## Recent Interview Questions

- 0of 0 votes
You are currently in practice mode. This is a demo only.

A zero-indexed array A consisting of N integers is given. An equilibrium index of this array is any integer P such that 0 ≤ P < N and the sum of elements of lower indices is equal to the sum of elements of higher indices, i.e.

A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].

Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.

For example, consider the following array A consisting of N = 8 elements:

A[0] = -1

A[1] = 3

A[2] = -4

A[3] = 5

A[4] = 1

A[5] = -6

A[6] = 2

A[7] = 1

P = 1 is an equilibrium index of this array, because:

A[0] = −1 = A[2] + A[3] + A[4] + A[5] + A[6] + A[7]

P = 3 is an equilibrium index of this array, because:

A[0] + A[1] + A[2] = −2 = A[4] + A[5] + A[6] + A[7]

P = 7 is also an equilibrium index, because:

A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] = 0

and there are no elements with indices greater than 7.

P = 8 is not an equilibrium index, because it does not fulfill the condition 0 ≤ P < N.

Write a function:

int solution(int A[], int N);

that, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices. The function should return −1 if no equilibrium index exists.

For example, given array A shown above, the function may return 1, 3 or 7, as explained above.

Assume that:

N is an integer within the range [0..100,000];

each element of array A is an integer within the range [−2,147,483,648..2,147,483,647].

Complexity:

expected worst-case time complexity is O(N);

expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).

Elements of input arrays can be modified.

- 0of 0 votes
Given a number n.find (l X b) dimension such that it is maximally close .

E.g:--

12---o/p->4X3 not 6X2

13---o/p->5X3 // as it is close

- 0of 0 votes
given a LinkedList like 1->2->3->4->5->6

Modify it as:

1->6->2->5->3->4

- 0of 0 votes
How do I solve this simple geometrical programming problem?

https://s32.postimg.org/sm75dimol/hurdle1.jpg

- 0of 0 votes
How do I find the longest possible route in a matrix?

There are some hurdles in the path.

Details in image : https://s31.postimg.org/7nwp4gmzv/hurdle1.jpg

- 0of 0 votes
The question is in the image.

https://s32.postimg.org/xv0x002p1/mcq_1.jpg

- 0of 0 votes
Problem : Christmas Tree

Chirag is a boy. And his one and only dream is to meet Santa Claus. He decided to decorate a Christmas tree for Santa on coming Christmas. Chirag made an interesting Christmas tree that grows day by day.

The Christmas tree is comprised of the following

Parts

Stand

Each Part is further comprised of Branches. Branches are comprised of Leaves.

How the tree appears as a function of days should be understood. Basis that print the tree as it appears on the given day. Below are the rules that govern how the tree appears on a given day. Write a program to generate such a Christmas tree whose input is number of days.

Rules:

If tree is one day old you cannot grow. Print a message "You cannot generate christmas tree"

Tree will die after 20 days; it should give a message "Tree is no more"

Tree will have one part less than the number of days.

E.g.

On 2nd day tree will have 1 part and one stand.

On 3rd day tree will have 2 parts and one stand

On 4th day tree will have 3 parts and one stand and so on.

Top-most part will be the widest and bottom-most part will be the narrowest.

Difference in number of branches between top-most and second from top will be 2

Difference in number of branches between second from top and bottom-most part will be 1

Below is an illustration of how the tree looks like on 4th day

https://s31.postimg.org/5s1txk4zf/christmas_tree.jpg

https://s32.postimg.org/i2c6i850l/christmas_tree_2.jpg

- 0of 0 votes
Given two object arrays of "id,weight" (sorted by weight), merge them together and create a one single array. If the "id"s are same values should be merged. Final resulting array should be sorted by weight. Result should be O(nlogn) in time complexity.

- 0of 0 votes
Mario wants to reach to his princess who is waiting for him in a castle. But the way to the castle is full of dragons. Each dragon is an enemy of the dragon who is located just before him on that path. The dragons in this world are quite peculiar. They have some number of diamonds each. Although they are dragons, they won't burn, instead they will give Mario their diamonds, but if and only if, Mario didn't take any diamonds from the dragon standing directly before the current one. If Mario does, then that dragon will burn him. Mario is in your control. You have to make Mario collect maximum number of diamonds for his princess and reach castle safely.

Input- Each test case starts with a number N, the number of dragons, 0 <= N <= 10^4. The next line will have N numbers, number of diamonds each dragon has, 0 <= The number of diamonds with each dragon <= 10^9. Dragons described in the order they are encountered on the way to the castle.

Output- Print the maximum number of diamonds you can collect (and reach to castle safely).

Sample Input

5 1 2 3 4 5

Sample Output

9

Explanation

Input - 5 ==> Represents number of Dragons 1 2 3 4 5 ==> Represents the diamonds each of the Dragon has consecutively. The first dragon has 1 , the second has 2 and so on....

Output- 9

Explanation- If Mario collects diamonds from 1st, 3rd and 5th dragon (1+3+5). He will get 9 diamonds which is the maximum number of diamonds he can collect. Two of the other possible ways in which he can collect diamonds is, from 2nd and 4th dragon, (2+4),i.e.(6) or from 2nd and 5th dragon (2+5) i.e.,7 . He can’t obtain more than 9 diamonds in any case.

Therefore the output would be 9, the maximum he can collect.

- 0of 0 votes
Jacob and Peter have their favorite number X and Y. We have given an array with positive interger number and we need to find the longest prefix index which contain equal number of X and Y. return -1 if there is no prefix with equal number of X and Y.

Suppose we have an array A = [7,42,5,6,42,8,7,5,3,6,7]

X = 7

Y =42

Output should be 9 as prefix will be index from 0 to 9 with equal number of X and Y.

I wrote below code but this has some bug which I could not find.`public int findIndex(int A[],int N,int X,int Y) { int nx =0; int ny=0; int result = -1; for( int i=0;i<N;i++) { if(A[i] == X) nx+=1; else if(A[i] == Y) ny+=1; if(nx== ny&& nx!=0&&ny!=0) result = i; } return result; }`

- 0of 0 votes
Given a dictionary and a string, find all the substrings that are valid words in dictionary.

I was thinking of a Trie solution but I'm not sure a Trie will work easily to match sub words that begin in the middle of the string.

- 0of 0 votes
Given a String input and a tree, write a code to return the same node for same input string. Also each node will should be given equal amount of weight between nodes at the same level while choosing a path.

- 0of 0 votes
Given an array: 1,2,3 ,5,8,7,6,9,5,7,3,0,5

subarry:5,7

Find the subarray in the large array and return the minimum length and index where you can find the subarray. Note: that the subarray may be present in the large array non-contiguous.

In the above case : the answer is length = 2 and

index = 8

- 0of 0 votes
Swap the elements in Kth position from the start and end of a link list.

ex:

input: list: 1,2,4,5,7,8 & K=2

output: 1,7,4,5,2,8

- 0of 0 votes
Write a program to check if the given string is repeated substring or not.

ex 1: abcabcabc - yes - abc is repeated.

2: abcdabababababab - no.

- 0of 0 votes
The following is the design question I was asked.

Design a dash board.

Should be very realistic.

Should be scalabe .

Should have very less latency .

Can expect millions of updates per second.

Dash board should show :

for each day :

1. city name ,

2.total trips in that city for that day ,

3.total fare it could collect in that city on that day,

4. fare collected from old clients

5. fare collected from new clients (new client is the client who is having his first ride in Uber after registration)

Input : we get two strings s1 , s2.

the format of s1 : trip_id , client_id , city , datetime

the format of s2 : trip_id , fare.

Could you please suggest how to proceed for this kind of question?

- 0of 0 votes
you have millions of records in DB. How could you display those records efficiently as a paginated view. Which UI technology would you use and why? how will you design the back end?

- 0of 0 votes
You have a big .csv file (say the size is 3GB). How efficiently you can process it and put the records in database?

- 0of 0 votes
http://www.indianapolisinseo.com

- 0of 0 votes
The SEO solutions talked about listed here are all next major corner gemstones from the SEO world.

- 0of 0 votes
Utilizing various search engine optimization services is as essential as selecting a business to delegate these too.

- 0of 0 votes
Given two strings, print all the inter-leavings of the Strings in which characters from two strings should be in same order as they were in original strings.

e.g.

for "abc", "de", print all of these:

adebc, abdec, adbce, deabc, dabce, etc, etc

- 0of 0 votes
Given a matrix of positive integers, you have to reach from the top left corner to the bottom right in minimum cost. You can only go one square right, down or diagonally right-down. Cost is the sum of squares you've covered. Return the minimum cost.

e.g.

4 5 6

1 2 3

0 1 2

Answer: 8 (4+1+0+1+2)

- 0of 0 votes
Find the length of maximum number of consecutive numbers jumbled up in an array.

e.g.: 1, 94, 93, 1000, 2, 92, 1001 should return 3 for 92, 93, 94

- 0of 0 votes
Given an array of numbers, find the maximum and minimum sum of sub sequences at a distance > m

Example –

arr = {3, 4, -2, 1, -2, 4, 6, -3, 5} & m = 2

Solution – max = 13 {4 + 4 + 5}, min = -5 {-2-3}

- 0of 0 votes
Given some resources in the form of linked list you have to canceled out all the resources whose sum up to 0(Zero) and return the remaining list.

E.g-->> 6 -6 8 4 -12 9 8 -8

the above example lists which gets canceled :

6 -6

8 4 -12

8 -8

o/p : 9

case 3 : 4 6 -10 8 9 10 -19 10 -18 20 25

O/P : 20 25

- 0of 0 votes
In an incoming stream of +ve integers, return true if 2 numbers with sum equal to 10 has occurred till now.

How to handle stream of numbers

- 0of 0 votes
Given an array,find all valid ip-address form this array.

- 0of 0 votes
An unsorted array is given . Find the no of greater elements on right side on current element in array. Find this for every element of array Expected time complexity is lesser then O(n^2)

- 0of 0 votes
A monotonically increasing function F(X) exists. For a given no N , find the value of X when F(X) = N.