## Recent Interview Questions

- 0of 0 votes
write boundary test cases for whether a linked list is circular linked list or not?

- 0of 0 votes
Write a java program logic to find whether list is circular

linked list or not?

- 0of 0 votes
Write a function that takes the following inputs and gives the following outputs.

Input: A list of points in 2-dimensional space, and an integer k

Output: The k input points closest to (5, 5), using Euclidean distance

Example:

Input: {(-2, -4), (0, 0), (10, 15), (5, 6), (7, 8), (-10, -30)}, k = 2

Output: {(5, 6), (7, 8)}

- 0of 0 votes
Implement strcmp function of stdlib.h library without using any standard library.

- 0of 0 votes
Implement a Singleton class in java? How will this help?

- 0of 0 votes
An efficient way to sort patient files in an array of just 3 types 'High-importance', 'Mid-importance', 'Low-importance' which are in an arbitrary order (unsorted).

The output preference should start with the highest.

1. High-importance

2. Mid-importance

3. Low-importance

[high,low,low,med,high,low]

ps I was told to take advantage of the fact that they are just only 3 types.

- 0of 0 votes
given a pre and post order kindof a traversal (2 arrays) create an n-ary treee out of it with struct of the form :

struct node {

int data;

struct node *child[MAX];

int child_num;

}

- 0of 0 votes
given matrix like :

a b e d

b c f e

a b d d

….

find the longest path of consecutive alphabets given a starting alphabet. You can move in all 8 directions. for eg. a->b(right)->c(down)->d(diagnal down)… len = 4 , find max such len

- 0of 0 votes
There is an integer INPUT array {1,2,3,4,5}. Create an OUTPUT array such that each element in output array consists Product of all elements in INPUT array divided by element at that point. But you have to do it without using divide operator (/).

e.g

intput={1,2,3,4,5}

output[0]=(1*2*3*4*5)/1

output[1]=(1*2*3*4*5)/2 and so on.

Don't use divide operator

- 0of 0 votes
If problem Statement "sun is rise in west " !

?

How to do tester test it ? What are all possible solution ?

- 0of 0 votes
Suppose you are a stock trader and you can do as many trades but if you stop you can't do another trade. You can start with any trade. Given an array of profits/loss of trades and find the maximum profit you can make.

Input:

Number of trades

Profit/loss in each trade

Output:

Max Profit

Ex:

Input:`7 1 2 3 4 -2 -3 1`

Output:

`10`

Explaination: Trade of [1,2,3,4]

Input:`5 -2 -3 -4 1 2`

Output:

`3`

P.S: Any solution than Brute-Force.

- 0of 0 votes
The latest reality show has hit the TV: “Cat vs. Dog”. In this show, a bunch of cats and dogs compete for the very prestigious Best Pet Ever title. In each episode, the cats and dogs get to show themselves off, after which the viewers vote on which pets should stay and which should be forced to leave the show.

Each viewer gets to cast a vote on two things: one pet which should be kept on the show, and one pet which should be thrown out. Also, based on the universal fact that everyone is either a cat lover (i.e. a dog hater) or a dog lover (i.e. a cat hater), it has been decided that each vote must name exactly one cat and exactly one dog.

Ingenious as they are, the producers have decided to use an advancement procedure which guarantees that as many viewers as possible will continue watching the show: the pets that get to stay will be chosen so as to maximize the number of viewers who get both their opinions satisfied. Write a program to calculate this maximum number of viewers.

Input

On the first line one positive number: the number of testcases, at most 100. After that per testcase:

One line with three integers c, d, v (1 ≤ c, d ≤ 100 and 0 ≤ v ≤ 500): the number of cats, dogs, and voters.

v lines with two pet identifiers each. The first is the pet that this voter wants to keep, the second is the pet that this voter wants to throw out. A pet identifier starts with one of the characters ‘C’ or ‘D’, indicating whether the pet is a cat or dog, respectively. The remaining part of the identifier is an integer giving the number of the pet (between 1 and c for cats, and between 1 and d for dogs). So for instance, “D42” indicates dog number 42.

Output

Per testcase:

One line with the maximum possible number of satisfied voters for the show.

Sample Input 1

2

1 1 2

C1 D1

D1 C1

1 2 4

C1 D1

C1 D1

C1 D2

D2 C1

Sample Output 1

1

3

- 0of 0 votes
given a vector of integers, v[i] represent the stock price on day i. Now you may do at most K transactions. you must sell your stock before you buy it again and that means you can NOT have two stocks at the same time. write a program to find max profit you can get.

- -1of 3 votes
20

/ \

8 22

/ \ / \

5 3 4 25

/ \

10 14

traverse this binary tree vertically and its output will be

5

8 10

20 3 4

22 14

25

- 2of 2 votes
Given a staircase that has 'n' step, and you climb the staircase by jumping over the steps. You can cover at max of 'k' steps in a single jump. List all the possible sequence of jumps you could take to climb the staircase.

input:

n=4, k=2

output:

1,1,1,1

1,1,2

1,2,1

2,1,1

2,2

- 1of 1 vote
A Matrix of 1s and 0s is given, all zeros are water and 1s are land, first find out the number of ponds in the array (Reverse of islands problem). If one change can convert 1s in to zero then find out minimum number of changes that we need to make so that there will be only one pond in matrix..

Any algo how to make 1 pond ?

- 0of 0 votes
There is a code with a runtime error. We add printf to display the value of a variable and we don't get the runtime error anymore. explain what the reason can be.

- 0of 0 votes
Describe what’s incorrect about the following function and how you would fix the problems.typedef map< int, char *> List;void foo(){ List l; FILE *f = fopen("data.txt", "r"); if (f) { char line[100]; for (int i = 0; fgets(line, sizeof(line), f); ++i) { l[i] = new char[strlen(line)]; strcpy(l[i], line); } } for (List::const_iterator it = l.begin(); it != l.end(); ++it) { printf("%d: %s", it->first, it->second); }}

- 0of 0 votes
The function bar crashes when invoked. What is wrong and how would you fix the problem without changing anything in function bar?struct A { char *name; A() : name(NULL) { } ~A() { if (name) delete[] name; }};void bar(){ A x; x.name = new char[10]; strcpy(x.name, "John"); A y = x;}

- 0of 0 votes
The structure Info stores information of a person. Using a STL map, implement a collection of Info. The fields first and last must be used a unique, composite key. The list should be sorted by last, first in ascending order.typedef struct { string first, last; int age; string addr1, addr2;} Info;Also Using the map of Info from the question, output the list in reverse order. You may not define a new map or redefine the map you defined in the last question.

- -1of 1 vote
There is a list of rectangles and a list of points in a 2d space. Note that the edge of each rectangle are aligned to XY axis. question is how to find rectangles with point or points inside

- 0of 0 votes
Given two integer arrays A and B.

B contains exactly same numbers as A except two additional numbers. Find the two elements with minimum time and space complexity.

for ex: A ={1, 4, 2, 6, 3}

B = {4, 0,7, 6, 3, 2, 1}

ans: 0 7

I came with this solution:`Arrays.sort(A); Arrays.sort(B); int i=0, j=0; while(j<=i+2 || i<A.length){ if(A[i]==B[j]){ ++i; ++j} else{ System.out.println(b[j]); j++; } } if(j==A.length+1){ System.out.println(B[j++]+" "B[j]); } if(j==B.length) System.out.println)(B[j]);`

- 0of 0 votes
How will you dictionary sort integers without converting them to strings.

For ex: 1 2 10 20 100 110

Ans: 1 10 100 110 2 20.

- 0of 0 votes
A credit card company allows merchants to use their Point-of-sale (POS) terminal to accept payments. It wishes to charge merchants for every transaction that happens through thier POS terminal. Here are some charging rules that it has come up with:

Transactions are charged 2.0% of transaction amount if amount is less than 5000.00

Transactions are charged 1.5% of transaction amount if amount is between 5000.00 and 9999.99 (both inclusive)

Transactions are charged 1.0% of transaction amount if amount is equal to or above 10000.00

If merchant has already done transactions worth 50000.00 in a month, then rest of transactions of that month are charged at 0.5%

Every Month - two transactions of amount less than or equal to Rs. 5000.00 are free

Charges are rounded to nearest higher Rupee (Eg: 9.23 is rounded to 10.00)

Please develop a program to compute the charges for given inputs.

Your input will be in the following format. First Line: number of records follows, say N Next N Lines - Transaction data in the order - Transaction Date, Merchant Name, Amount

15

2014-06-25,XYZ Retail,10000.00

2014-07-01,XYZ Retail,10000.00

2014-07-01,ABC Retail,1000.00

2014-07-02,ABC Retail,3999.00

2014-07-02,ABC Retail,2000.00

2014-07-03,ABC Retail,10000.00

2014-07-15,ABC Retail,6530.00

2014-07-15,XYZ Retail,500.00

2014-07-18,ABC Retail,9750.00

2014-07-18,XYZ Retail,35000.00

2014-07-18,XYZ Retail,500.00

2014-07-18,XYZ Retail,5000.00

2014-07-18,XYZ Retail,5000.00

2014-08-02,XYZ Retail,10000.00

2014-08-02,XYZ Retail,1000.00

Transactions must be read and processed in the order given, else output will not match. Do not try to sort the transactions.

Output (Charges for each transaction on separate line)

100.00

100.00

0.00

0.00

40.00

100.00

98.00

0.00

147.00

350.00

0.00

75.00

25.00

100.00

0.00

Sample Input (Plaintext Link)

15

2014-06-25,XYZ Retail,10000.00

2014-07-01,XYZ Retail,10000.00

2014-07-01,ABC Retail,1000.00

2014-07-02,ABC Retail,3999.00

2014-07-02,ABC Retail,2000.00

2014-07-03,ABC Retail,10000.00

2014-07-15,ABC Retail,6530.00

2014-07-15,XYZ Retail,500.00

2014-07-18,ABC Retail,9750.00

2014-07-18,XYZ Retail,35000.00

2014-07-18,XYZ Retail,500.00

2014-07-18,XYZ Retail,5000.00

2014-07-18,XYZ Retail,5000.00

2014-08-02,XYZ Retail,10000.00

2014-08-02,XYZ Retail,1000.00

Sample Output (Plaintext Link)

100.00

100.00

0.00

0.00

40.00

100.00

98.00

0.00

147.00

350.00

0.00

75.00

25.00

100.00

0.00

Explanation

100.00 // Rule 3 applied

100.00 // Rule 3 applied

0.00 // Rule 5 applied (ABC Retail) for the month of July

0.00 // Rule 5 applied (ABC Retail) for the month of July

40.00 //Rule 1 & 6 applied

100.00 // Rule 3 applied

98.00 // Rule 2 & 6 applied

0.00 // Rule 5 applied (XYZ Retail) for the month of July

147.00 // Rule 2 & 6 applied

350.00 //Rule 3 applied

0.00 // Rule 5 applied (XYZ Retail) for the month of July

75.00 // Rule 2 applied

25.00 // Rule 4 applied

100.00 // Rule 3 applied

0.00 // Rule 5 applied (XYZ retail) - for the month of Augus

- 0of 0 votes
Given a list of strings, return a list of lists of strings that groups all anagrams.

Ex. given {trees, bike, cars, steer, arcs}

return { {cars, arcs}, {bike}, {trees, steer} }

m = # of words

n = length of longest word

I solved this in O(m * n * log n) time.

- 0of 0 votes
//Given a method that takes in a positive non-zero number N, return from that method the total number of factors of N. //Start with O(n) solution and make it faster if we have time

- 0of 0 votes
You have a chess board of size NxN. You have a horse at a given starting position. You also have a function that gives you all the positions that the horse can reach from it's current position.

Given an ending position, find the path to it that uses the minimum number of moves.

- 0of 0 votes
Implement the divide of two integers without using the divide operator.

After implementing the O(n) algorithm to subtract the divisor from the divider, he asked me to implement a better algorithm.

I started working towards bit manipulation, but ran out of time.

He also hinted that I could have used binary search. Not sure how though.

- 0of 0 votes
Given a stack of magazines create an anonymous love note (pick words or alphabets from the magazine and create the note)...

He gave me the choice of handling words or alphabets

Assume you have a scanned copy of the magazine as a string.

Once I implemented both words and alphabets, he asked me to scale it to mass production and maximize the throughput of a fulfillment center handling this

- 0of 0 votes
Design a robot that will take your order and make sandwiches for you.

Once I was done with this, I was supposed to extend it to have multiple robots doing this job like an assembly line handling multiple sandwiches and other edible items

Once I handled that, he asked me to create a web service for this that will handle online ordering. He also wanted me to implement fulfillment centers