## SDE1 Interview Questions

- -4of 4 votes
Shorten a List of Strings.

- 0of 2 votes
Design a Black-Jack poker game

- 4of 4 votes
Give an 2d-characters Grid, char[][] A, and a dictionary, List<String> dict. Search all possible words in the 2d-Grid.

- 0of 0 votes
finds a domino pattern for a "double-N" domino set that forms a loop / a ring using all available tiles.

for example,In a double-two domino set, with six tiles, (0 , 0) (0 , 1) (1 , 1) (1 , 2) (2 , 2) (2 , 0). So if parameter is 2, the function should return true. if no loop found, should return false.

Dominoes are small rectangular game tiles divided into two squares and embossed with dots on the top surface of the tile. You can think of dots as integers. A double-N domino set consists of (N+1)(N+2)/2 tiles, e.g. a standard double-six domino set has 28 tiles (T): one for each possible pair of values from (0.0) to (6.6) - no pair of numbers occurs more than once.

- 0of 0 votes
We have a class as follows:

`public class People{ String name; String position; String sex; ... ... public String getAttribute(String attrName){ /** * This is a generic getter method that will give you * any attribute value based on the passed attribute * Name; * for eg: getAttribute("name") => will return the * attriute(Name) value of the current object. */ } }`

I now give you two List:

list1<People> friends;

list2<String> attributes;

Using the generic getter method, we have to group "friends" on "attributes". Think of this as an implementation of GROUP BY function to be implemented on objects in list1 and to be grouped on entries in list2.

eg: list2 = {sex, occupation}

So objects in list1 will be grouped such that all Male-doctors together, Female-cops together, male-cops together, etc.

- 1of 1 vote
Given a array of positive integers, find all possible triangle triplets that can be formed from this array.

eg: 9 8 10 7

ans: 9 8 10, 9 8 7, 9 10 7, 7 8 10

Note : array not sorted, there is no limit on the array length

- 2of 2 votes
Given a large array of unsigned ints, quickly find two who's sum is 10

Then the interviewer asked me to write test cases.

Followed by how to implement this on a distributed system, where multiple systems can read/write simultaneously on a shared cache (HINT: It is ok if you do not return the first instance)

- 1of 1 vote
Minesweeper question: Given an n x m grid holding individual mine co-ordinates, identify all of the mine clusters. A mine cluster is the largest collection of neighboring mines.

Example input:

0 1 2 3

---------

0|0|1|0|1

1|0|0|1|1

2|0|0|0|0

3|1|1|0|0

Expected output:

[cluster 1] (0,1),(1,2),(1,3),(0,3)

[cluster 2] (3,0),(3,1)

- 1of 1 vote
given a range of number 1 through N, where N >=3. you have to take an array of length 2N and place each number ( from the range 1 to N) twice. such a that the distance between two indexes of a number is equal to the number. example

N=3

( 3, 1, 2, 1, 3, 2 )

I know we can Use Backtracking but is there any other solution.

- 0of 0 votes
Write an algorithm to convert the given input string to the expected output string. The input string shall be the length of few million characters. So the output has to be updated in the same string...

Input String = "ABBCDEFGGGGGGGGHHXX..<20 more X>..XYY..."

Expected output = "A1B2C1D1E1F1G8H2X23Y2..."

Note: The count of each character has to be appended with the same character in the output string

- 0of 0 votes
Given a stream of characters (stream is increasing char by char), check if newly

formed 10character word is present in already parsed/scanned stream. Print such

repeating streams lexicographically at the end.

- 0of 0 votes
reverse nodes in k interval in single linked list

eg. k = 3

i/p 1 2 3 4 5 6 7 8 9

o/p 3 2 1 6 5 4 9 8 7

- 0of 0 votes
find if two people are connected in social network.

- 0of 0 votes
you wrote a c++ program and your processor change (eg. from intel to ARM or anything ) then what are thing needs to be change in compiler to get the same behavior of program in different (eg. ARM ) architecture machine.

- 0of 0 votes
There is a rectangle with left bottom as (0, 0) and right up as (x, y). There are n circles such that their centers are inside the rectangle. Radius of each circle is r. Now we need to find out if it is possible that we can move from (0, 0) to (x, y) without touching the circle. We can move freely anywhere.

- 0of 0 votes
calculate the summary statistics for a fleet of hosts. Each host has a fixed number of slots in which virtual instances can run. Each host can only run instances of a particular type, e.g. M1, M2, or M3. You are provided with the file “FleetState.txt” that contains the state of the fleet. Each line in the file represents a single host in the following comma-separated format:

<HostID>,<InstanceType>,<N>,<Slot1State>,<Slot2State>,…,<SlotNState>

where

<HostID> is an integer

<InstanceType> can be M1, M2, or M3

<N> is the total number of slots on the machine

<SlotjState> is 0 if slot j is empty and 1 if it is occupied by an instance

Write a program that loads the state of the fleet from the input file “FleetState.txt” and then computes and writes out the following summary statistics to the output file “Statistics.txt”:

For each instance type, the count of empty hosts (all slots empty)

For each instance type, the count of full hosts (all slots filled)

For each instance type, the count of the most filled hosts (having the smallest number of empty slots > 0). Both the host count and number of empty slots must be written out in that order.

The output file must have the following format:

EMPTY: M1=<count>; M2=<count>; M3=<count>;

FULL: M1=<count>; M2=<count>; M3=<count>;

MOST FILLED: M1=<count>,<empty slots>; M2=<count>,<empty slots>; M3=<count>,<empty slots>;

What is the best way to solve this problem?

- 0of 0 votes
calculate the summary statistics for a fleet of hosts. Each host has a fixed number of slots in which virtual instances can run. Each host can only run instances of a particular type, e.g. M1, M2, or M3. You are provided with the file “FleetState.txt” that contains the state of the fleet. Each line in the file represents a single host in the following comma-separated format:

<HostID>,<InstanceType>,<N>,<Slot1State>,<Slot2State>,…,<SlotNState>

where

<HostID> is an integer

<InstanceType> can be M1, M2, or M3

<N> is the total number of slots on the machine

<SlotjState> is 0 if slot j is empty and 1 if it is occupied by an instance

Write a program that loads the state of the fleet from the input file “FleetState.txt” and then computes and writes out the following summary statistics to the output file “Statistics.txt”:

For each instance type, the count of empty hosts (all slots empty)

For each instance type, the count of full hosts (all slots filled)

For each instance type, the count of the most filled hosts (having the smallest number of empty slots > 0). Both the host count and number of empty slots must be written out in that order.

The output file must have the following format:

EMPTY: M1=<count>; M2=<count>; M3=<count>;

FULL: M1=<count>; M2=<count>; M3=<count>;

MOST FILLED: M1=<count>,<empty slots>; M2=<count>,<empty slots>; M3=<count>,<empty slots>;

what is the best way to solve it?

- 0of 0 votes
Given a set of equalities and inequalities like A=B,B=C,F=J and A!=C, etc in two separate arrays (equalities[] and inequalities[]) and a method, separate that returns the two objects, e.g. separate(A=B) will return A and B, write an algorithm to find whether the entire set is consistent in constant time.

- 0of 0 votes
Given a string and a regular expression pattern, give the number of times the pattern occurs in the string. RegEx example means as follows:

. – 2 occurrences of the previous character

+ – 4 occurrences of the previous character

* – more than 5 occurrences of the previous character

Sample Input:

5

aaaaaannndnnnnnnfffhfhhgjjjwkkkllclc

a.

n+

a*

an.

a.d.

Sample Output:

5

3

2

1

0

- 1of 1 vote
Find the 90th percentile of a stream of numbers between 1 and 10^6.

Followup: What if there is not enough memory to store all numbers and no upper bound.

- 1of 1 vote
`Given a String s and a hashmap containing certain decodings for all the characters of alphabet. Find all possible passwords that can be generated by replacing decodings in the string s. Note that decodings of a charachter can only be single charachters Eg: String s="abcde" decodings given a-{1,2,p,o,q} b-{2,y} c-{p} d-{4,a,m,n} e-{9,z,x} h-{1} ' ' ' x-{0} y-{4,k,l} z-{r,5} So possible set passwords will be abcde,1bcde,2bcde,pbcde,obcde,qbcde, //replace a with all possible decodings a2cde,12cde,22cde,p2cde,o2cde,q2cde,aycde,1ycde,2ycde,pycde,oycde,qycde //replace b will all possible decodings a2pde,12pde,22pde,p2pde,o2pde,q2pde,aypde,1ypde,2ypde,pypde,oypde,qypde.....//replace c will all possible decodings`

- 0of 0 votes
non recursive method to calculate height of the binary tree.

- 0of 0 votes
you have a dictionary which will return true if the word is present in it otherwise false. You have a string "ABC", check if anagram of "ABC" is present or not. the condition was not to generate the all the anagram of ABC. (Assumption: you can store the dictionary in trie or hashmap (any data structure) and no need to implement the dictionary)

- 0of 0 votes
Merge two sorted linked list

- 0of 0 votes
Design a stack using queue(s)

- 1of 1 vote
Design a valet parking system. Requirements of the valet parking system should be:

1. Customer are given a ticket that they can use to redeem to get their vehicle back

2. Parking spots come in three sizes, small, med, large

3. Thee types of vehicles, small, med, large

-a small vehicle can park in a small, medium, and large spot

-a medium vehicle can park in a medium and large spot

-a large vehicle can park in a large spot

- 0of 0 votes
Suppose you want improve the performance of search queries, using a cache. Each search queries is in form of a string and returns a list of ad id's in the form of longs.

Design a class with the appropriate data structure(s) that can manage a cache of search queries.

- 0of 0 votes
Say you have a string:

"Thisisasentence"

How would you separate the string into separate words, return either the sentence with spaces or as a list/array where each entry is a word

- 0of 0 votes
Write a program to find the smallest number that can be formed by 0 and 9 which is divisible by a given number.

For example, if given number is 3 output should be 9,

if given number is 2 output is 90,

if given number is 10 output is 90,

- -2of 2 votes
Write a program to find the smallest number that can be formed by 0 and 9 which is divisible by a given number.

For example, if given number is 3 output should be 9,

if given number is 2 output is 90,

if given number is 10 output is 90,

if given number is 7 output is 10^23.