## Coding Interview Questions

- 0of 0 votes
Given two numbers L and R, find the highest occurring digit in the prime numbers present between L and R (both inclusive). If multiple digits have the same highest frequency print the largest of them. If there are no prime no.s between L and R, print -1.

- 0of 0 votes
Round 6

Question 3 : You are given a word document, you have to print the words with frequencies. Now print the kth rank word in terms of frequency. Print top k words as well by frequencies

- 0of 0 votes
Round 2

Question 3 : You have to implement an external iterator which iterate the binary tree InOrder. You have to figure out what kind of iterator one should use, and implement each of those function. required complexity is O(N) time + O(log(N)) space

- 0of 0 votes
You are given a large array of 10,000,000 bits. Each bit is initially 0. You perform several operations of the type "Flip all the bits between start_index and end_index, inclusive". Given a sequence of several such operations, perform all the operations on the array. Finally, split the array into sets of 4 bits - first four, next four, then next four and so on. Each set can represent a hexadecimal integer. There will be exactly 2,500,000 hexadecimal integers. Calculate the frequency of each of the hexadecimal integers from '0' to 'f' among the 2,500,000 integers, and print it. See Input / Output and explanation of Sample Input / Output for clarity.

Input

The first line of input contains an integer T (1 ≤ T ≤ 10), the number of test cases. Then follows the description of T test cases. You should assume that the array has exactly 10,000,000 bits and that the bits are all unset at the start of each test case. The first line of each test case contains an integer N (1 ≤ N ≤ 10,000), the number of operations performed. The next N lines contain two integers separated by a space, the start_index and end_index for the respective operation. Note that the flip operation is performed from start_index to end_index, inclusive. Also, the array is 1-indexed - meaning, the smallest index is 1 and the largest index is 10,000,000.

Output

For each test case, output 16 integers on a single line, separated by single space characters. The first integer should represent the number of times 0 occurs among the 2,500,000 hexadecimal integers created according to the problem statement. The second integer should represent the number of times 1 occurs among the 2,500,000 hexadecimal integers created according to the problem statement, and so on.

Constraints

1 ≤ start_index ≤ end_index

start_index ≤ end_index ≤ 10,000,000

Sample Input

2

2

1 4

9999997 10000000

2

3 6

5 8

Sample Output

2499998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2

2499998 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0

Explanation

In the first test case, after we perform the two operations and split the array into 2,500,000 groups of 4 bits, the first and the last group will have all 4 bits set - representing 'f' hexadecimal digit. All the other groups will have all 4 bits unset - representing '0' hexadecimal digit.

In the second test case, after we perform the two operations and split the array into 2,500,000 groups of 4 bits, the first two groups will have the state 0011. This represents the hexadecimal digit '3'. All the other groups will have all the 4 bits unset - representing '0' hexadecimal digit.

- 0of 0 votes
Describe the different ways to determine if an integer is a power of 2.

He was looking for a solution other than dividing by 2.

I suggested initially log2X. They said it has some rounding issues in certain environments. I continued to doing bitwise arithmetic.

- 0of 0 votes
Round 3

Question 1, you are given a puzzle, You can check the image here`https://drive.google.com/file/d/0B6-TjTC-KfTqQThBamxPa0NwNGM/view?usp=sharing`

You have to write a program to provide a solution for this.

- 0of 0 votes
Round 2

Question 1: Design a traffic signalling system for a city.

1.a : think as you were asked this question in a high level meeting with leadership teams, what would you do at that time ?

1.b : what are the check-list/to-do you will do before start of your project.

1.c : how will you go over each and every check-list/to-do

1.d : Once you have done all this, what are the design principle you will follow.

1.e : what kind of system you would choose(I gave distributed/centralized)

1.f : Tell me the pros and cons of these type which you have listed

1.g : how do you go over your goal.

1.h : how will you make the cons go away from one system which out changing it to another type(like possible modification).

1.i : How will to achieve your goal which was given to you by LT team.

1.f : Now lets write the code for a road intersection, make it generic enough both in terms of colors, and ordering, so what it can be used anywhere.

Note that : a road intersection may have many traffic lights one for each side of the roads

- 1of 1 vote
Design a cache module for an image server. The server accepts image requests from users and sends them back the images. The cache should always hold in-memory the 10 most recently requested images. The cache should also support multiple requests simultaneously

- 0of 0 votes
Tech Screening round

Q.1 : a non decreasing sorted array is rotated by some random amount, write a routine to figure out this random amount.you can consider the clockwise rotation.

Write the test cases for it.

Interviewer wanted to see prod ready code.

- 0of 0 votes
What's the use of concurrency list in java? What are various locking mechanism in java?

- 0of 0 votes
what's use of equals and hashcode function?

- 0of 0 votes
hashmap implementation?

- 0of 0 votes
vector vs arraylist

- 0of 0 votes
hashtable vs hashmap

- 0of 0 votes
How Garbage collector know if something is not used and needs to be removed?

- 0of 0 votes
What's difference between Javascript and JAVA in terms of OOP principles. Provide examples.

- 0of 0 votes
Design Bing search.

- 0of 0 votes
/*

Tree:

1

/ \

3 5

/ \ \

2 4 7

/ \ \

9 6 8

==========

Expected Output:

1

35

247

968

*/

class TreePrinter {

static class Node {

int value;

Node left;

Node right;

public Node(int value, Node left, Node right) {

this.value = value;

this.left = left;

this.right = right;

}

}

public void printTree(Node root) {

// implementation here

}

- 0of 0 votes
/*Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die. Given a flowerbed (represented as an array containing booleans), return if a given number of new flowers can be planted in it without violating the no-adjacent-flowers rule

Sample inputs

Input: 1,0,0,0,0,0,1,0,0

3 => true

4 => false

Input: 1,0,0,1,0,0,1,0,0

1 => true

2 => false

input: 0

1 => true

2 => false */

public boolean canPlaceFlowers(List<Boolean> flowerbed, int numberToPlace) {

// Implementation here

}

- 1of 1 vote
design a class (give different methods and variables that will be used) that will provide information about the allergy of a patient.

e.g. who reported the allergy(patient/doctor/relative), different symptoms of the allergy that are detected, severity, method that returns when was that

allergy detected in that patient. Along with info about disease if it is not allergy, and can be updated easily, how would you record the time of the disease report using java

- 0of 0 votes
{1, 1, 0, 0, 0},

{1, 1, 0, 0, 0},

{1, 0, 0, 1, 1},

{0, 0, 0, 0, 0},

{1, 0, 1, 0, 1}

write a function to return the size of max cluster and coordinate of it, max cluster size to the above example is 5.

- 0of 0 votes
given a string, characters can be shuffled to make a paliandrome.

What is the minimum possible number of insertions to original string needed so that it will be a palindrome (after shuffling, if required).Input

T -> number of test cases

T number of Strings in different lines`import java.util.Arrays; import java.io.InputStreamReader; import java.io.BufferedReader; public class Xsquare{ public static void main (String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int limit = Integer.parseInt(br.readLine()); int [] alphabets = new int[26]; while(limit-- >0){ String input = br.readLine(); Arrays.fill(alphabets,0); char [] inpChar = input.toCharArray(); int sum = 0; for (int i=0;i<input.length();i++){ int pos = (int)inpChar[i] - (int)'a'; alphabets[pos]+=1; } for(int i=0;i<26;i++){ if(alphabets[i]%2==0) sum+=0; else sum+=1; } if(sum<=0) sum=0; else sum-=1; System.out.println(sum); } } }`

This is the code I submitted online. But it was not accepted as solution. What is the correct approach to this question?

- 0of 0 votes
Given this set of interfaces:

public interface Processor<T,U> {

U process(T arg);

}

public interface Splitter<T,V> {

V[] split(T arg);

}

public interface Worker<V,W> {

W processPart(V part);

}

public interface Aggregator<U,W> {

U aggregate(W[] args);

}

and this scenario:

Please provide

1. An implementation of Processor interface

2. Test cases for testing the implementation

http://webcache.googleusercontent.com/search?q=cache:QW8rjNE9dDwJ:stackoverflow.com/questions/29716343/how-to-implement-processort-u-using-java-generics+&cd=1&hl=en&ct=clnk&gl=in

- 1of 1 vote
write custom pattern match function to match following logic

.’ Matches any single character.

‘*’ Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

The function prototype should be:`bool isMatch(const char *s, const char *p) Some examples: isMatch(“aa”,”a”) → false isMatch(“aa”,”aa”) → true isMatch(“aaa”,”aa”) → false isMatch(“aa”, “a*”) → true isMatch(“aa”, “.*”) → true isMatch(“ab”, “.*”) → true isMatch(“aab”, “c*a*b”) → true isMatch(“ccca”, “c*a”) → true`

- 0of 2 votes
Write a program to test whether a string and all strings that can be made using the characters of that string are palindrome or not.

Eg:

Input Output

mmo True

yakak True

travel False

Note : Please do not use any inbuilt functions.

- 4of 4 votes
Sparse number is an integer if there are no adjacent 1 in it's binary representation.

Like: 5 -> 101 (no adjacent 1)

9 -> 1001 (no adjacent 1)

while 6-> 110 is not sparse number.

Now you are given an integer find the NEXT BIGGER sparse number.Please mind 'it is next bigger'.

- 0of 0 votes
Write a program to modify the string in following pattern,

Change odd words to uppercase and Reverse the even words. Make sure that the spaces (multiple) between the words remains as it is.

E.g.:

Input : "This is a test String!!"

Output: "THIS si A tset STRING!!"

- 0of 0 votes
hi i have one question, for example : convert A2B2A to A3B2, that is simple but but string can also have parentheses like AB3((CB)2(CB)2)3 which to converted to AB15C12

- 0of 0 votes
You are given heights of n candles .

First day you lit one candle

second day you need to lit two candles

Third day you need to lit three candles

..........

........

till possible.

After lighting candles the height of candles deduced by 1 each day.You can also extinguish any candle you want but only at the end of day.

So you need to tell the maximum number number of days , you can carry on lighting the candles.

Example : there are three candles of heights {2 , 2 ,2 }

Answer : 3

1.You light first candle on day one. heights -> {1,2,2}

2.You light second and third and extinguish first one . heights ->{1, 1,1}

3.You light all the candles. heights -{0,0,0}

- 0of 0 votes
Input any string, count the maximum depth of parenthesis nesting, i.e. "abc(123(xyz))m(((n)))o" -> 3.

if input is null or contains a mismatch "a)b(c" or "a(b"

Also some other samples:

(((()))) -> 4

()()()() -> 1