# Uber hiring 2021 coding questions and answers!

### List of questions which were asked during the online test

#### 1. Edward and Alphonse are alchemists

Problem Statement
Edward and Alphonse are alchemists. They want to perform human transmutation to revive their mother and need philosopher stones for it. Father Inc has a factory which produces philosopher stones. The factory will run for n days. On day i the factory will produce A[i] stones. These stones also have a expiry date! The stones produced on day i can only be used for D[i] days. So if D[i] = 1 those stones can only be used on the day they are produced and so on.

Edward and Alphonse want to maximise their chances to succeed at the transmutation. For this tell them the maximum number of stones they can use for the transmutation.

• [execution time limit] 4 seconds (py3)
[input] array.integer stones
This is an array of the number of stones produces on day i. 0 <= stones[i] <= 10000000. No of array
elements <= 100000

• [input] array. integer days
This is an array of the number of days stones produces on day i can be used for. 0 <= days[i] <- 1000000. No of array elements <= 100000

• [output] integer
Output is an integer which is the maximum number of that can be used for transmutation. As the answer can be large give the result modulo 1000000007

Example

Input:
stones: [15, 82, 43, 44, 50]
days: [1, 3, 3, 4, 4]
Expected Output: 169

Solution

``# We will Update here ASAP!``

#### 2. Kth Character of infidelity String

Problem Statement

You are given two strings S and T. An infinitely long string is formed in the following manner:
• Take an empty string
• Append S one time.
• Append T two times.
• Append S three times.
• Append T four times.
and so on, appending the strings alternately and increasing the number of repetitions by 1 each time.
You will also be given an integer K. you need to tell the Kth Character of this infidelity long string.

Sample Input:
S=”a”,T=”bc”,K=4
Sample Output: b
Sample Explanation:
The string formed will be “abcbcaaabcbcbcbcaaaaa…”. So the 4th character is “b”.
• [execution time limit] 4 seconds (py3)
• [input] string s: The first string. 1 <= len(S)<=100
• [input] string t: The second string. 1<=len(t)<=100
• [input] integer64 k: The integer k is. 1<=k<=10^6
• [output] character : The kth character of the infinitely long string.

### Solution:

``````def kthElement(S,T,K):
temp = ''
i=1
while(len(temp)<K):
temp+=S*1
temp+=T*(i+1)
i+=2
return temp[K-1]

print(kthElement('a','bc',4))``````

#### 3. XOR Sum

You are given 4 integers A,B,C and D. You need to find the following sum:

``````sum = 0
for(i=A;i<=B;i++){
for(j=C;j<=D;j++){
sum = sum + (i^j)
}}``````

Here ^ stands for the bitwise XOR operation. Since the final sum can be huge, you should return the output modulo 1000000007. (10^9 + 7)

Sample Input:
A = 1, = 2, C=3, D = 4
Sample Output:
14

Explanation:
The required sum would be (1^3) + (1^4) + (2^3) + (2^4) = 2 + 5 + 1 + 6 = 14.
• [execution time limit] 4 seconds (py3)

• [input] integer a
1 <= A <= 10^9
• [input] integer b
A <= B <= 10=9
• [input] integer c
1 <= C <= 10^9
• [input] integer d
C <= D <=10^9

[output] integer:
The required sum. modulo 1000000007

### Solution:

``````def sums(A,B,C,D):
sum=0
for i in range(A,B+1):
for j in range(C,D+1):
sum=(sum+(i^j))%1000000007
return sum
print(sums(1,2,3,4))``````

#### Note

If You have optimized Solution. Please write in your solution in Comment.

Accenture Software Development Engineer Hiring Coding Question & Answer!