## Recent Interview Questions

- 1of 1 vote
Generate all possible sorted arrays from alternate elements of two given sorted arrays.

Given two sorted arrays A and B, generate all possible arrays such that once first element is taken from A then from B then from A and so on in increasing order till the arrays exhausted. Then first element is taken from B then From A, and do same as above.

- 0of 0 votes
Given a tree and a number N, construct another tree such that each node of the tree has either 0 or N elements,except for one node which has between 0 to N elements.Only other constraint is that ancestry is preserved in the new tree.

- 0of 0 votes
There are five classes having inheritance a,b,c,d,e. We have to solve an equation with all the possible methods defined in the above classes.We have multiply(), add(),subtract() and divide() methods in the above classes.

- 0of 0 votes
There are n persons and k different type of dishes. Each person has some preference for each dish. Either he likes it or not. We need to feed all people. Every person should get atleast one dish of his chioce. What is the minimum number of different type of dishes we can order?

Input is n x k matrix boolean matrix.For each person a row represent his likes or not likes each row.

n = 6 k = 7

1 0 0 0 1 0 0

1 0 0 0 0 1 0

1 0 0 0 0 0 1

0 1 0 0 1 0 0

0 0 1 0 0 1 0

0 0 0 1 0 0 1

Output

3

Explanation

Take dish number 5,6,7.

- 0of 0 votes
Model a restaurant reservation system, where staff can a reservation, pull up, cancel reservations. The reservation system is very simple local to just one terminal at the restaurant not connected to network.

- 0of 0 votes
Find an algorithm to find a word ladder between 2 words by changing just one letter at a time. All the words formed should be valid dictionary words.

Eg.

FOOL ->POOL->POLL->POLE->PALE->SALE->SAGE

COLD → CORD → CARD → WARD → WARM

- 0of 0 votes
Maga gives a hard problem to Alex. And Alex couldn't solve yet. Could you help him?

The grid is n by m. Each cell contains a unique number on it. Maga is at the left-top and wants to go to right-bottom. But there is a condition. Maga can go through only two way - right and down. And the path of your move is called the nodes you have passed through over them. The path is called the most beautiful if the following condition is satisfied: The sorted of the path has to be lexicographic smallest as possible as. Output the most beautiful path for given grid.

Input:

In the first line you are given two numbers: the dimensions of grid - n and m. The next n lines contains m numbers. Each number is unique.

Output:

Output the most beautiful path.

Contraints:

1 <= n,m <= 1000

1 <= A[i][j] <= n*m, All of the numbers in the grid are unique.

Sample Input

2 2

4 2

3 1

Sample Output

1 2 4

Explanation

There are 2 ways to reach at (2,2) cell. The pathes are 4, 3, 1 or 4, 2, 1 respectively. So The most beautiful of them is 4, 2, 1 because if looking the sorted of them it looks like these : 1, 3, 4 and 1, 2, 4 respectively. So 1, 2, 4 is lexicographic smaller than the other. So the ans is 1 2 4.

- 0of 0 votes
Little Chandan is a friend everyone feels lucky to have. He is a happy-go-lucky-fellow and makes sure that everyone around him is happy. But recently, he came to know that his friend little Arjit is in serious trouble, and needs help. Like the great friend little Chandan is, he took the challenge upon himself without any serious thought, to make sure that little Arjit feels fine.

Now, little Arjit explains the story of his problems (His life, in general!) to let little Chandan figure out his troubles. After all, everyone needs help. All little Arjit needs is to get an internship somewhere, and complete his dual degree course, somehow, anyhow.

Little Chandan being the great genius man with psychic power decides to enter the brain of his friend to help him out.

Here are the contents of little Arjit's brain:

- His goals. (Internship, dual degree, remember?) - what Chandan needs to free. - Predictable empty spaces in his brain - plain empty spaces. - Ex-girlfriends and their memories - which CANNOT be penetrated, while traversing. - Windows which lead to the goal - which need to be open for little Chandan to pass.

Little Chandan knows the location of the two goals in his brain, the problem is while traveling through the path of his brain he'll have to break down the windows - once he has opened a window to cross that path, it remains open forever. So, he wants to minimize the number of windows he opens inside his friend's mind.

Help him plan his path accordingly, so he ends up breaking the minimum number of windows!

Input Format:

- First line contains a number t, denoting the number of test cases.

- Every test case will have the following:

- One line with two integers hm, wm - determining the width of the brain and the height of the brain.

The following characters define the state:

- X is the space which cannot be penetrated filled by the memories of ex-girlfriends. - W is the windows which little Chandan need to cross to reach the goal. - . is an empty space in the brain. - G are the two goals to be rescued.

Output Format:

1. Minimum number of windows Chandan needs to open to get to both the goals in Arjit's mind.

Constraints:

1 <= t <= 100

2 <= hm, wm <= 100

There are EXACTLY two goals in his mind.

For each goal, a path from the outside to that goal is surely going to exist.

Chandan can move around freely outside the mind.

Sample Input

1

5 9

XXXXWXXXX

X..W.W..X

XXXX.XXXX

XGW.W.WGX

XXXXXXXXX

Sample Output

4

- 0of 0 votes
Write an algorithm to create tables of a given set of players (i.e divide the players into groups) for a game in the following manner. Each table will have 6 players. Total number of players will be a multiple of 6. There are some conditions that must be fulfilled to decide which player takes which table. These conditions are defined later and requires some definitions that we will look into first.

'Distance' between the players:

Since these players have been playing with each other in the past, we have history (available in a data set) about who played with whom in the past. Using this player game history we can plot a graph of players where each player is a node in the graph. A player is connected to another player if they have played on the same table in the past. In such a case distance between them is 1.

For example: If Pi and Pj have played on the same table in the past then they are connected with each other and 'Distance' between Pi and Pj is 1. Distance between any 2 players is defined as length of the shortest path between 2 players. If 2 players are not connected then distance between them is same as maximum of distance between any 2 players + 1

Degree of separation of a table

Degree of separation of a table is defined as sum of (Distances of all players taken 2 at a time)

Example: For a table of 6 players: Degree of separation = Sum of all 15 distances (6 choose 2)

The condition on table formation is:

We have to create tables (i.e divide the players into groups) such that Sum of (degree of separation of all the tables) is minimum.

The constraints on data size:

Number of history records is upto 100M records

Number of unique players in history upto 200K

Number of tables possible in the solution is upto 1K

- 0of 0 votes
write a program how many squares in chessboard ?

- 1of 1 vote
Write program to print the value of the second last node in a single linked list and write the test cases (code to test) for the same .

- 0of 0 votes
Write test data to check the e-mail id field

e.g:- abc@xmail.com

- 0of 0 votes
Enumerate test cases for testing an online payment using credit card for a purchase done through mobile app.Test cases should have description and expected result

- 0of 0 votes
How would you debug the following case

Your phone gets switched off every time you click on the alarm icon

- 1of 1 vote
Write program for the following case

Reverse string (string is stored in an array)

Input:- "This is an example"

Output:-sihT si na elpmaxe

- 1of 1 vote
Write program for the following scenario

Input Array :- {1,2,3,4,5,5,5,6,7,7}

Output:- 5 is repeated 3 times

7 is repeated 2 times

- 0of 0 votes
Write code for square root function? Basic Math Square Root. (Discuss your solution first with the interviewer then code while interviewer was watching over online)

- 0of 0 votes
Samu's Birthday is near so she had started planning a party for all of her friends. Being a kind and caring girl she calls each of her friend and asks for his/her favorite dish.Now each friend has own liking/disliking for different dishes.

A friend can only like or dislike a dish it means if we are having three dishes 1,2,3 then if a friend says that he likes Dishes 1 and 2 then its obvious that he dislikes Dish 3. So for each friend we are given a string of 1 and 0 where 1 shows that this person like this particular dish.

Now we are given that Samu has N friends and total of K dishes available to make her menu. Now Samu doesn't want to make any of her friend unhappy , After all its her birthday.

So she got confused on what dishes to count in menu and calls you for help. You need to find count of minimum dishes to order so that all of her N friends are happy which means everyone has at least one dish to eat in party.

Note : Its for sure that everyone has at least liking for one dish.

Input : Input will contain T test cases and each of the test case has following description :

First line of test case has N denoting the total number of friends and K denoting the total number of dishes available.Both separated by a space (Dishes are numbered from 1 to K) .

Then it is followed by N lines each of length K . Each of the N lines contains a string of 0 and 1 where if jth (1<=j<=K) value in ith line (1<=i<=N) is set 1 then it shows that dish

- 0of 0 votes
how would you design a microwave for the blind?

- 0of 0 votes
How would you increase Youtube revenue?

- 0of 0 votes
How much is Youtube Revenue

- 0of 0 votes
2. There is a maze of size n*n. Tom is sitting at (0,0). Jerry is sitting in another cell (the position of Jerry is input). Then there are k pieces of cheese placed in k different cells (k <= 10). Some cells are blocked while some are not. Tom can move to 4 cells at any point of time (left, right, up, down one position). Tom has to collect all the pieces of cheese and then reach to Jerry’s cell. You need to print the minimum no. of steps required to do so.

I know it is possible throgh dp but please provide me solution with approoch i am unable to solve it please

- 0of 0 votes
Write a program in that determines the members and parents of nested groups without using recursion.

These are the requirements.

1. A group can have 0 or more members.

2. A group can be member of one or more groups

3. A group can be member of itself.

4. If there is a path from a group either directly or through multiple hops, then that user is considered as member of the group.

5. A group can have users or groups as members

EX: Input looks like this`var groupMembers = new Dictionary<string, HashSet<string>> { { "G4", new HashSet<string> { "U1","G1"} }, { "G1", new HashSet<string> { "G2","G3","G6"} }, { "G3", new HashSet<string> { "G3","G5"} }, { "G2", new HashSet<string> { "G4","U2"} }, { "G5", new HashSet<string> { "U2","G6"} }, { "G6", new HashSet<string> { "U3"} }, };`

Signature of function is:

`private List<MyGroup> FindMembers(Dictionary<string, HashSet<string>> groupMembers)`

You need to make sure that you take care of cycles in the graph and not go into infinite recursion.

Output should look like a list of groups where a group is as follows.`private class MyGroup { public string Identity { get; set; } public Dictionary<string, MyGroup> MemberOf { get; set; } public Dictionary<string, MyGroup> Members { get; set; } public HashSet<string> Users { get; set; } public MyGroup(string name) { this.Identity = name; this.MemberOf = new Dictionary<string, MyGroup>(); this.Members = new Dictionary<string, MyGroup>(); this.Users = new HashSet<string>(); } }`

Each group object should contain all the groups it's a memberOf (directly or indirectly), all the groups that are it's members (directly or indirectly) and all users that are it's members.

- 0of 0 votes
You have a farm of 400m * 600m where coordinates of the field are from (0, 0) to (399, 599). Some part of the farm is barren. All the barren land is in form of rectangles. Due to these rectangles of barren land, the remaining area of fertile land is present in form of holes in the farm. Each hole is a maximal area of land that is not covered by any of the rectangles of barren land.

Input

You are given a set of rectangles that contain the barren land. Each String in rectangles consist of four integers separated by single spaces, with no additional spaces in the string. The first two integers are the coordinates of the bottom left corner in the given rectangle, and the last two integers are the coordinates of its top right corner.

Output

Output all the holes’s area in square meters, sorted from smallest area to greatest, separate by space.

Sample Input/ Output

Sample Input Sample Output

{“0 292 399 307”} 116800 116800

{“48 192 351 207”, “48 392 351 407”, “120 52 135 547”, “260 52 275 547”}

22816 192608

Deliverables – the code below or similar structure

import java.io.*;

public class Solution { public static void main(String args[] ) throws Exception { /* Enter your code here. ead input from STDIN. Print output to STDOUT */ }}

- -2of 2 votes
Design a game like angry birds

- -1of 1 vote
Check if the given cordinates on a map correspond to the correct address (where address or cordinates are provided in a tab separated file)

- 0of 0 votes
Reverse string except spaces. A string has mix of alphabets and spaces. Your task is to reverse the string, but preserve the positions of spaces. For example, reverse of " a if" is " f ia".

- 0of 0 votes
You have a farm of 400m * 600m where coordinates of the field are from (0, 0) to (399, 599). Some part of the farm is barren. All the barren land is in form of rectangles. Due to these rectangles of barren land, the remaining area of fertile land is present in form of holes in the farm. Each hole is a maximal area of land that is not covered by any of the rectangles of barren land.

Input

You are given a set of rectangles that contain the barren land. Each String in rectangles consist of four integers separated by single spaces, with no additional spaces in the string. The first two integers are the coordinates of the bottom left corner in the given rectangle, and the last two integers are the coordinates of its top right corner.

Output

Output all the holes’s area in square meters, sorted from smallest area to greatest, separate by space.

Sample Input/ Output

Sample Input Sample Output

{“0 292 399 307”} 116800 116800

{“48 192 351 207”, “48 392 351 407”, “120 52 135 547”, “260 52 275 547”}

22816 192608

Deliverables – the code below or similar structure

import java.io.*;

public class Solution {

public static void main(String args[] ) throws Exception {

/* Enter your code here. Read input from STDIN. Print output to STDOUT */

}

}

- 0of 0 votes
Implement hashtable put function in C++ without using STL stuff.

- -8of 8 votes
LOOKING FOR IAS TOPPERS PERSONAL INTERVIEW QUESTION AND ANSWERS