## Recent Interview Questions

- 0of 0 votes
given a stream of natural numbers ,

and a array J contains integers in increasing orders

operations performed J = [2,3,4]

1 2 3 4 5 6 7 8 9 10…………..27....100...1111

first operation

J[0] = 2 => remove every 2nd integer

now the stream is

1 3 5 7 … 27

J[1] = 3

remove every 3rd

stream is now

1 3 7 …

3rd

given a natural number n , find if it will survive given J, or at what index it will

die.

- 2of 2 votes
Return the length of longest possible chunked palindrome string.

Examples :

Input : VOLVO

Output : 3

Explanation :

(VO)L(VO)

Input : merchant

Output : 1

Explanation : No chunks possible.

Input :

ghiabcdefhelloadamhelloabcdefghi

Output : 7

Explanation :

(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi)

- 0of 0 votes
Given a list of manager and employee information represented in hashMap entries {AAA->BBB,CCC,EEE},{CCC->DDD}.

Print company structure tree with proper indentations. BBB, CCC and EEE directly reports to AAA, so they have one white space before "-", DDD reports to CCC, it has two whitespace before "-". The input is map<String,List<String>>`-AAA -BBB -CCC -DDD -EEE`

- 1of 1 vote
A producer continuously produces a stream of characters. There are multiple consumer threads which read the chars and match to one of known strings and increment the counter for that pattern. Write the consumer function. Show how you will synchronize and maintain parallelism.

Ex: Producer: abcdegabccaabbaacv ......

Known strings[] = {"ab", "aa", "fff" ... }

patternMatchCount[] = {3, 2, 0 ... }

- 0of 0 votes
Design OO food delivery app catering to use cases -

1) User can search different restaurant

2) User can select a restaurant

3) User sees a menu

4) Restaurant can change the menu any time

5) User adds an item from menu

6) User orders the food

7) User can track the order in real time

8) User can cancel the order

9) User pays for the order

- 0of 0 votes
Design food delivery app (OO design). Cater to use cases like search for different restaurants, selecting a restaurant, select an item from menu, menu can be updated in real time by restaurant, order the food, customer keeps track of the order in real time, payment for the order, cancel the order etc.

- 0of 0 votes
Design Uber low level OO design. Cater to use cases like search for a ride, different category of rides, select a ride, registration for a user and driver, paying for ride etc.

- 0of 0 votes
Find sum of n elements after kth smallest element in BST. Tree is very large, you are not allowed to traverse the tree.

- 0of 0 votes
For a given integer array, find a closet pair of elements in the array with a sum of N. For example, {1, 5, 3, 6, 4, 2} and 8, (5, 3) is the pair, but not (6, 2).

Note: the condition is an array of integers, which can be either positive or negative.

- 2of 2 votes
As an input, you have points on a 2D graph. You aim to find a straight line that can fit as my points as possible. Return, the maximum number of points you can fit.

- 0of 0 votes
Given a number, return the count of numbers having non-repeating digits till that number starting from 1?

- 0of 0 votes
There are Items[I1, I2, I3, I4] available in warehouses [W1, W2, W3, W4, W5] and serviceable by multiple partners with some shipping cost.

I1 available in W1

– serviceable by these partners S1[0.75 -shipping cost/selection cost], S2 [0.74], S3 [0.70]

available in W2

– serviceable by these partners S1[0.75], S2 [0.74], S3 [0.70]

available in W3

– serviceable by these partners S1[0.80], S2 [0.74], S3 [0.70]

I2 available in W4

– serviceable by these partners S2[0.85], S3 [0.94], S4[0.30]

available in W3

– serviceable by these partners S1[0.80], S2 [0.74], S3 [0.70]

I3 available in W1

– serviceable by these partners S1[0.85], S2 [0.55], S3 [0.70]

available in W2

– serviceable by these partners S1[0.80], S2 [0.54], S3 [0.70]

I4 available in W4

– serviceable by these partners S2 [0.74], S3 [0.70], S4[0.30]

available in W2

– serviceable by these partners S1[0.85], S2 [0.80], S3 [0.70]

available in W3

– serviceable by these partners S1[0.80], S2 [0.74], S3 [0.70]

You have to optimally select the items so that total cost will be minimum.

Ex: I can make a shipment from I1, I2, I4 fulfilled by W3 which will cost:

for partner S1: 2.40

for partner S2: 2.22

for partner S3: 2.10

Another Shipment I3 fulfilled by W2 which will cost: S2 [0.54]

Total cost: 2.10+0.54 = 2.64 with Shipment SH1 {I1,I2,I4} By S3 and SH2 {I3} by S2

Another possible way

I1, I3, I4 serviceable by W2 by Provider S2 : 2.08

I2 serviceable by W4 by S4: 0.30

Total cost: 2.38

So the shipments with minimum cost can be delivered/selected.

Write a program for the same to get optimum minimum cost for the number of shipments can be delivered from warehouses with shipping cost?

“If you ship multiple items in single packet, then the cost will be minimum. Assume Shipment Provider charges per packet and not on the weight and packing charges will be minimum. Idea is to consolidate/aggregate as many items as possible to one location so that packaging cost is minimum and on top of that you should consider warehouse selection cost.”

- 0of 0 votes
Assuming in a Facebook like social network application, find the shortest friend connection path for a given pair of two people.

Note: for scalability of this problem, she has discuss it in her book "Crashing The Coding Interview".

- 0of 0 votes
For a linked List p1 ->p2 ->p(n-1)->p(n) shuffle it to be p(1) -> p(n) ->p(2) ->p(n-1)....p(n/2)

- 0of 0 votes
Given the Java 8 Function interface:

interface Function<T,R> {

R apply<T t>;

}

Provide code that will apply the composition of the following implementations and would have the type

Function<String, Integer>:

class GetBytes<String, byte[]> {

byte[] apply<String value> {

return value.getBytes<>;

}

}

class ArrayLength<byte[], Integer> {

Integer apply<byte[] value> {

return value.length;

}

}

If the input is “hello world” what would the expected result of the function be?

- 0of 0 votes
Function to find if the characters of the sample string is in the same order in the text string. They need not be

consecutive.

Eg.. TextString: Redmond, Washington

Sample string :Rdd Waitn

- 0of 0 votes
https://www.hackerrank.com/challenges/array-and-simple-queries

Given two numbers N and M. N indicates the number of elements in the array A[](1- indexed) and M indicates number of queries. You need to perform two types of queries on the array A[] .

You are given M queries. Queries can be of two types, type 1 and type 2.

Type 1 queries are represented as 1 i j : Modify the given array by removing elements from to and adding them to the front.

Type 2 queries are represented as 2 i j : Modify the given array by removing elements from to and adding them to the back.

Your task is to simply print | A[1] - A[N] | of the resulting array after the execution of M queries followed by the resulting array.

Note While adding at back or front the order of elements is preserved.

- 0of 0 votes
Given a dictionary and an char array print all the valid words that are possible using char from the array.

Ex- char[] arr = {'e','o','b', 'a','m','g', 'l'}

Dict - {"go","bat","me","eat","goal", "boy", "run"}

Print - go, me, goal.

We can pre-compute as much we want but the query time must be optimal.

- 1of 1 vote
Given a pattern and a string - find if the string follows the same pattern Eg: Pattern : [a b b a], String : cat dog dog cat

- 0of 0 votes
public interface FirstCommonAncestor {

/**

* Given two nodes of a tree,

* method should return the deepest common ancestor of those nodes.

*

* A

* / \

* B C

* / \ \

* D E H

* / \

* G F

*

* commonAncestor(D, F) = B

* commonAncestor(C, G) = A

* commonAncestor(E, B) = B

*/

Node commonAncestor(Node one, Node two);

}`class Node { final Node parent; final Node left; final Node right; public Node(Node parent, Node left, Node right) { this.parent = parent; this.left = left; this.right = right; } boolean isRoot() { return parent == null; } }`

- 0of 0 votes
Q. Given an array of numbers. Print all the pairs (2) of numbers in the array if the sum of those numbers is also present in the array. Write in C

- 0of 0 votes
Find the first N prime numbers where N is a positive integer.

Note: This question is to find all first N prime numbers, but not determinate whether N is prime or not.

- 0of 0 votes
Given a matrix consisting of only 0's and 1's find the largest rectangular sub-array consisting of only 1's. Rows can be interchanged with each other and columns too can be interchanged with each other

- 1of 1 vote
Given N stacks, each stack contains Si elements, find the maximum sum of the M numbers in the N stacks. To get the number of the stack, only supporting get the top number. For example, S=[1,200,1,2,3], if you want to get the number 200, you need choose 3,2,1 first.

EX:

S1=[1,1,100,3]

S2=[2000,2,3,1]

S3=[10,1,4]

the maximum sum of the 3 numbers in the above stacks is 3+100+3=107.

Any better solution for this problem?

- 0of 0 votes
int bits(unsigned char v);

Which returns number of set bits in v.

A) Optimize for memory usage:

B) Optimize for speed:

- -1of 1 vote
Given two pre-order traversal arrays of two binary search tree respectively, find first pair of non-matching leaves.

Follow Up: If they are general binary trees instead of BSTs, could you solve it? give out your reason.

For the first question, I was thinking to construct two BSTs from pre-order traversal then do a leaf-level comparison. Any better solutions are welcome.

- 0of 0 votes
Find out the number of ways in which two queens can be placed in a 8*8 chessboard.

- 0of 0 votes
Find the possible (x,y) coordinates in a given 2-D chess board which are safe from the attack of a queen.

- 0of 0 votes
Design and implement traffic control system, also include pedestrian signal management as part of this solution.

- 1of 1 vote
Given a binary tree. I need to print the nodes in vertical line zigzag manner. For example: 1st vertical line from top to bottom, 2nd vertical line from bottom to top,3rd vertical line from top to bottom and so on

5

/ \

3 7

/ \ / \

1 4 6 8

/ \ \

2 9 10

Answer would be –

1

2 3

5 4 6

9 7

8

10