## Recent Interview Questions

- 0of 0 votes
You are given a stream of numbers which represent the stock prices of a company with timestamp. You need to perform some set of operations on the stream of data efficiently as below: 1. findStockPriceAtGivenTimeStamp(Timestamp) 2. deleteAndGetMinimumStockPriceForToday() Timstamp: 1 2 3 . 4 . 5 Prices: 12 34 4 . 1 . 18

- 0of 0 votes
convert prefix to postfix expression

public String convert2postfix(String prefix){

}

- 0of 0 votes
Given a list of rectangles, pick a random point within one of the rectangles, where the likelihood of a point is based on the area of the rectangle.

There we no sample inputs and outputs that were provided.

- 0of 0 votes
Inserting dashes between two odd numbers and star between two even numbers

- 2of 2 votes
Print Common Suffix In Strings

Ex: cornfiled , Exfiled --- field

- 0of 0 votes
Write a function to generate Random Number without using any library functions.

Extension: Write an overloaded method for the above function which accepts a Range.

- 0of 0 votes
Design online multiplayer generic board game (like chess). How will you store sessions.(RDBMS or REDIS) How will the

competitor be chosen and notified(HTTP or what?).

What are the appropriate classes?

- 0of 0 votes
Design Recommendation system. How will you generate generate recommendations for millions of users. DB Schema, How will you improve latency? if the user is searching a item, when will you show next recommendations. How will you update, latency basically and consistency.

- 0of 0 votes
You are provided with 2D char array. You have to provide the 2D char array as response which contains the multiplication od the input array. For eg: input=> {{a,b},{c,d}}, output => {{a,c},{a,d},{b,c},{b,d}}

- 0of 0 votes
You are provided with different Excel files and the data format those files contain. You are also provided with low level parser. You have to design a system which takes the excel file and its data type as the input and returns the list of Data objects in the file.

- 1of 1 vote
Design JProfiler. How will you design datastructure and why, function stacktrace. HLD+LLD

- 0of 0 votes
Design a Fresh Grocery System. Means Daily usable Items, you cannot store them in inventory like bread, milk etc.

HLD+ DB Schema + Concurrency issues + Scalable architecture. How will you scale to multiple countries

- 0of 0 votes
Write algorithm for java grep command for word matching in the following context.Given a file containing n words.Given a word w and a number k.Find k words in the file occuring before occurence of w.Assume that the average word size is m in the file

eg.

aaa

bbb

ccc

booking

alpha

beta

gamma

for k=3 and w = booking

the output should be [aaa,bbb,ccc,booking]

similarly for k =2 and w = beta

output should be [booking,alpha,beta]

Assume that the file size can grow very large

and try to get solution with space complexity lesser than O(n)

I suggessted solution for iterating through file until the word w is found and maintaiining a queue of size K

The time complexity of my solution was O(nm)

and space complexity was O(k) .Any answers to improve the time and space complexity

Apparently they were looking for a better implementation of grep

- 1of 1 vote
Given an array of integers where each element points to the index of the next element how would you detect if there is a cycle in this array

can you do it without extra space

- 0of 0 votes
Given an unsorted array. for example [2, 3, 1, 4, 5].

Sort the array, we have new array [1, 2, 3, 4, 5],

if we draw the line between the 2 arrays for the same number, for example:

[3, 2, 1,4,5]

\ | /

\|/

/|\

[1, 2, 3,4,5]

then we have 3 line-cross:

line (1 to 1) cross line (2 to 2)

line (1 to 1) cross line (3 to 3)

line (2 to 2) cross line (3 to 3)

Note: the line between two 4s and the line between two 5s don't cross any other lines;

Implement the algorithm to calculate the how many line crosses for an unsorted array.

- 0of 0 votes
You are given an alphanumeric string. Complete the function sortSegments that will segment the string into substrings of consecutive letters or numbers and then sort the substrings.

For example, the string "AZQF013452BAB" will result in "AFQZ012345ABB". The input letters will be uppercase and numbers will be between 0 and 9 inclusive.

- 0of 0 votes
You are given an integer array n. Complete the function sortIntegers which takes as an argument, an integer array n of up to 1 million integers such that 1 <= n_i <= 10.

for every element n_i in the array, and returns the sorted array. The sort does not need to occur in-place.

Please do not call a standard sorting function like quicksort, you can do better. A sample input is {3, 1, 4, 1, 5, 9, 2, 6, 5} and the corresponding output is {1, 1, 2, 3, 4, 5, 5, 6, 9}. Constraints: i <= 10^9; 1 <= n_i <= 10

- 1of 1 vote
How to develop a web based multiplayer chess game. There will be 2 player in each session. There will be multiple sessions.

My answer(I was not selected)

Each player will have a database with columns

user id(primary key), passwd,no of games played, won,drawn,last active time,sq1,sq2,...sq64,move made flag,pawn num, sqstart,sqend

where sq1-denotes square 1 and its value represents the pawn num in sq1

question- what all fields in database will be encrypted

answer-passwd

question- why not others

answer-may be system admin needs to access them

question – how will u start a session between players?

Answer-When a player logs in, his last active time is updated. Each player is shown a list of last active players to chose from.Or system can arbitrarily select one.When a player is selected, he gets a request. Each player receives a list of requests from other players. He choses from one. That player gets an acknowledgement others get negative acknowledgement. If acknowledgement does not come in time then that player is dropped and another player is selected.

Question- http connection, can not send request from server. How the 2 players will send request to each other and how session will be initiated?

Question-how the game will be stored?

The 64 squares sq1,sq2,..sq64 will each store the pawn number in them. From random number calculatio, it will be decided which one is white and which one is black 1st time. When a player makes move,has made move flag will be true. The last move is stored as sqstart,sqend,pawn number. Each time a move is made check for valid move.The other player continuously polls for has made move flag to know if it is his turn

remarks- ur design is not scalable.

- 0of 0 votes
If you have 2 hotel rooms and 10 upcoming bookings. Such as

Booking 1. checkin Sept 1st to Sept 4

Booking 2. checkin Sept 9st to Sept 1

Booking 3. checkin Sept 1st to Sept 10

Booking 4. checkin Sept 11st to Sept 20

...

What should be the algorithm to optimize the room allocation?

When a new booking arrives in the future, how should the rooms to be re-allocated.

- 0of 0 votes
You are given a Log that contains UserId, ProcessId, Start Time, End Time and Resource Consumption during that time, you need to find out the user who has utilized the most resources.

Example:`UID PID StartTime EndTime Consumption`

`1 1 200 300 100`

`2 2 230 340 80`

`1 3 245 315 50`

`1 4 305 330 20`

Time 200 signifies: 02:00.

Output: UID# 1

UserID 1 because he has consumed the most number of resources between 200 to 315 (Resource Consumption: 150).

- 0of 0 votes
This was a 3 hours coding round in which we had to code 1 problem having 50 test cases. Only those students were selected for the next round who passed all the test cases. Here is the question:

You’ll be given a grid as below:

0 1 0 2 0

0 2 2 2 1

0 2 1 1 1

1 0 1 0 0

0 0 1 2 2

1 1 0 0 1

x x S x x

In the grid above,

1: This cell has a coin.

2: This cell has an enemy.

0: It contains nothing.

The highlighted(yellow) zone is the control zone. S is a spaceship that we need to control so that we can get maximum coins.

Now, S’s initial position will be at the center and we can only move it right or left by one cell or do not move.

At each time, the non-highlighted part of the grid will move down by one unit.

We can also use a bomb but only once. If we use that, all the enemies in the 5×5 region above the control zone will be killed.

If we use a bomb at the very beginning, the grid will look like this:

0 1 0 2 0

0 0 0 0 1

0 0 1 1 1

1 0 1 0 0

0 0 1 0 0

1 1 0 0 1

x x S x x

As soon as, the spaceship encounters an enemy or the entire grid has come down, the game ends.

For example,

At the very first instance, if we want to collect a coin we should move left( coins=1). This is because when the grid comes down by 1 unit we have a coin on the second position and by moving left we can collect that coin. Next, we should move right to collect another coin( coins=2).

After this, remain at the same position( coins=4).

This is the current situation after collecting 4 coins.

0 1 0 2 0 0 1 0 0 0

0 2 2 2 1 -->after using 0 0 0 0 1

x x S x x -->bomb x x S x x

Now, we can use the bomb to get out of this situation. After this, we can collect at most 1 coin. So maximum coins=5.

- 1of 1 vote
I get a chance to talk to Facebook software engineer during my android engineer interview. He asked me couple of question about native android like diff between views and fragment, mutable and immutable string, diff between string builder and string and a programming question convert int into words.

- 2of 2 votes
There is a maze of size m*n. You are sitting at (0,0). Another person is sitting in another cell. There are some cheeses placed in different cells with a cell value of 2. Some cells are blocked with a value of 1, thus you cannot pass it, while some cells are filled with 0, thus you can pass it.

You can move to left, right, up, down at each step. You have to collect all the pieces of cheese and then reach to Another Person cell. You need to return the minimum no. of steps required to do so.

Public int getShortest(int[][] maze, int[] anotherPersonCell){

}

- 1of 3 votes
Design an order tracking system using the below constraints.

Once an order is received, it will be assigned to a delivery boy and sends notification at every stage of the order such as order received with expected time of delivery, delivery boy assigned, order picked up, order delivered.

State how your design will help scale and what will be the performance SLAs that will you will set for your design. The system should be able to horizontally scalable from hundreds of orders to million orders and should perform at almost the same level irrespective of the number of orders received.

- 1of 3 votes
(Q2)what is output and explain why?

struct abc

{

double d;

char c;

int b;

}st;

int main()

{

int i=sizeof(st);

printf("%d",i);

}

- -2of 2 votes
please help me ...i am confused

(Q1)what is output and explain why?

struct abc

{

char c;

double d;

int b;

}st;

int main()

{

int i=sizeof(st);

printf("%d",i);

}

......................................................................................................................................................................................................

- 1of 1 vote
We start with a list of Integers. We can remove a group of integers from the list if the all but one equals the remaining number. This removal operation can be performed in the remaining number of list until no more operations can be performed.

Write a function which can accept an array of integers, and return the minimal number of remaining integers from performing this operation.

Example [1, 3, 5, 6] -> remove 1, 5, 6 , because 1 + 5 = 6, thus only [3] left, so return 1

[48, 20, 1, 3, 4, 6, 9, 24] -> remove 3, 6, 9 , because 3 + 6 = 9, and remove 4, 20, 24, 48, because 4 + 20 + 24 + 48, thus only [1] left, so return 1

int left(int[] nums){

}

- 1of 1 vote
Tweet Recommendation

Twitter Interview Online Test

On Twitter, millions of tweets are posted on a daily basis. Help Twitter write a simple ranking algorithm to find the best of all tweets. It works as follows: A good tweet receives many “likes” from people on Twitter, either from people you follow, or people you do now follow. A tweet is more relevant to you if people you follow also liked the tweet. If enough people you follow have liked that tweet, we recommend that tweet to you.

Your task is to complete the function

getRecommendedTweets(followGraph_edges, likeGraph_edges, targetUser, minLikeThreshold), which returns a list of tweet IDs in sorted order that should be recommended for a certain user. It takes 4 parameters:

followGroup_edges stores follow relationships as an array of tuple of integers.

For example, followGraph_edges = Array{(A, B), (A, C), (B, C)} represents 3 follow relationships:

A follows B

A follows C

B follows C

likeGraph_edges stores like relationships, also in an array of tuple of integers.

For example, likeGraph_edges = Array{(A, T1), (B, T2), (A, T2)} means:

A liked tweet T1

B liked tweet T2

A liked tweet T2

targetUser is the user ID for which we generate recommended tweets

minLikeThreshold is the minimum number of likes a tweet mush receive from people you follow to be recommended

For example, if minLikeThreshold = 4, only tweets that received at least 4 likes from people you follow should be recommended

Note: If you cannot find a single tweet that meets our requirement, simply return an empty list. You may also use any functions provided by the standard library.

- 0of 0 votes
Consider an N*N game board, with a black and white pieces that can be placed on it. You are given a board with placed pieces around it in a random spots.

You need to implement a function that determines if a piece (black or white) is captured on a given coordination (x, y).

A piece is defined as captured by the following rules:

1. If all sides (up, down, left & right) contains an opposite piece that surrounds/blocking it.

2. If some of the sides are blocked (for example, right and down) and the other ones are out of bound (OOB defined for coords: x: <= 0, y: <= 0) it's considered as blocked.

3. If one of the sides is empty, it's free.

4. If one of the sides contains the same piece type, and that piece is not captured (by the rules above), it's free.

5. Note that pieces may be captured in a clustered way (related to #4).

For example, consider the following coordinates:

coord(1,1) = B

coord(1,2) = W

coord(2,1) = W`X | 1 | 2 1 | B | W 2 | W |`

For the given coordination 1,1 the result would be `captured` (true).

Another example, consider the following coordinates:

coord(2,2) = W

coord(2,3) = W

coord(3,1) = W

coord(3,2) = B

coord(3,3) = B

coord(3,4) = W

coord(4,2) = W

coords(4,3) = W`X | 1 | 2 | 3 | 4 | 5 | 2 | E | W | W | W | E 3 | W | B | B | B | W 4 | E | W | W | W | E`

For the given coordination 3,2 (or 3,3) the result would be `true` (captured).

If we would either remove one of the W coords (thus making it empty), or change it to be a B piece, the result would be `false` (not captured).

As basic primitive, you are provided with a function that translates coordination into its state:`getState (x, y) == Black, White, Out Of Bound, Empty`

- -1of 3 votes
123+123+123