## SDE1 Interview Questions

- 1of 1 vote
A list of words is given and a bigger string given how can we find whether the string is a permutation of the smaller strings.

eg- s= badactorgoodacting dict[]={'actor','bad','act','good'] FALSE

eg- s= badactorgoodacting dict[]={'actor','bad','acting','good'] TRUE

The smaller words themselves don't need to be permuted. The question is whether we can find a ordering of the smaller strings such that if concatenated in that order it gives the larger string

One more constraint - some words from dict[] may also be left over unused

- 0of 0 votes
Given the following inputs, return a list of rooms that are available and large enough:

# of people

Start Time

End Time

You should return

total list of rooms

capacity of each rooms

availability

- 0of 0 votes
The stepping number:

A number is called as a stepping number if the adjacent digits are having a difference of 1. For eg. 123,121,9878 are all stepping numbers. While 890, 098,012 are not i.e. a number should not start with 0.

Also all 1-digit numbers are stepping numbers.

Find out how many stepping numbers exist with number of digits =N (input given)

- 2of 2 votes
10000 cameras, 100 hours of video each. 30 fps. Police need to input a plate number and find the path of a suspicious vehicle. (Estimate the size of the video, e.g., blueray disc is 2 hours and 20 GB. No need to scan all of the videos. Estimate the time that a vehicle can be seen between 2 traffic cameras, e.g., 0.3 miles and 30 miles per hour, then select 1 out of 100). Web client, load balancer, servers, db.

- 0of 0 votes
How do I solve this simple geometrical programming problem?

https://s32.postimg.org/sm75dimol/hurdle1.jpg

- 1of 1 vote
How do I find the longest possible route in a matrix?

There are some hurdles in the path.

Details in image : https://s31.postimg.org/7nwp4gmzv/hurdle1.jpg

- 0of 0 votes
Problem : Christmas Tree

Chirag is a boy. And his one and only dream is to meet Santa Claus. He decided to decorate a Christmas tree for Santa on coming Christmas. Chirag made an interesting Christmas tree that grows day by day.

The Christmas tree is comprised of the following

Parts

Stand

Each Part is further comprised of Branches. Branches are comprised of Leaves.

How the tree appears as a function of days should be understood. Basis that print the tree as it appears on the given day. Below are the rules that govern how the tree appears on a given day. Write a program to generate such a Christmas tree whose input is number of days.

Rules:

If tree is one day old you cannot grow. Print a message "You cannot generate christmas tree"

Tree will die after 20 days; it should give a message "Tree is no more"

Tree will have one part less than the number of days.

E.g.

On 2nd day tree will have 1 part and one stand.

On 3rd day tree will have 2 parts and one stand

On 4th day tree will have 3 parts and one stand and so on.

Top-most part will be the widest and bottom-most part will be the narrowest.

Difference in number of branches between top-most and second from top will be 2

Difference in number of branches between second from top and bottom-most part will be 1

Below is an illustration of how the tree looks like on 4th day

https://s31.postimg.org/5s1txk4zf/christmas_tree.jpg

https://s32.postimg.org/i2c6i850l/christmas_tree_2.jpg

- 0of 0 votes
Given some resources in the form of linked list you have to canceled out all the resources whose sum up to 0(Zero) and return the remaining list.

E.g-->> 6 -6 8 4 -12 9 8 -8

the above example lists which gets canceled :

6 -6

8 4 -12

8 -8

o/p : 9

case 3 : 4 6 -10 8 9 10 -19 10 -18 20 25

O/P : 20 25

- 0of 0 votes
In an incoming stream of +ve integers, return true if 2 numbers with sum equal to 10 has occurred till now.

How to handle stream of numbers

- 0of 0 votes
Given an array,find all valid ip-address form this array.

- 0of 0 votes
Find the number of column-swaps required to find the largest rectangle of all ones in a matrix.

The question is similar to the one in this link-

http://www.geeksforgeeks.org/find-the-largest-rectangle-of-1s-with-swapping-of-columns-allowed/

But we need to find the number of minimum swaps required

- 0of 0 votes
Write a function that takes a string of javascript code as parameter and returns a new string with these literals standardized on double quotes.

For example if the input is

/* This method says 'hello'*/

function sayHello()

{alert('hello')}

The out put should be

/* This method says 'hello'*/

function sayHello()

{alert("hello")}

The quoted text in the code section of the function should be changed to double quotes. The quotes used in the comments section should be left alone.

static string standardizeJavaScript(string inputJavaScript)

{

string temp = string.Empty;

if (string.IsNullOrEmpty(inputJavaScript))

return inputJavaScript;

bool updateQuote = false;

string output = string.Empty;

string[] split = inputJavaScript.Split('\n');

for (int i = 0; i < split.Length; i++)

{

if (split[i].Contains("{"))

updateQuote = true;

//if (split[i].Contains("{"))

// updateQuote = false;

if (updateQuote)

{

split[i] = split[i].Replace("'", "\"");

output = output +"\n" + (split[i]);

}

}

return output;

}

- 0of 0 votes
Write a function that will give the number of intersections between 2 strings. The function should take two string parameters which represents 2 words that may or may not intersect.The method should return the count of intersections which are found. For example, if the input is word 1 - Sales, word 2 - isles. The out put should be 4.

The word sales and isle intersects in 4 places.

1. The 2nd letter of isle intersects with the 1st letter of sales.

2. The 2nd letter of isle intersects with the 5th letter of sales.

3. The 3rd letter of isle intersects with the 3rd letter of sales.

4. The 4th letter of isle intersects with the 4th letter of sales.`static int numberOfIntersections(string word1, string word2) { if (string.IsNullOrEmpty(word1) || string.IsNullOrEmpty(word2)) return 0; string shorterWord = string.Empty; string longerWord = string.Empty; //Identify the shorter word and the longer word if (word1.Length < word2.Length) { shorterWord = word1.Trim(); longerWord = word2.Trim(); } else { shorterWord = word2.Trim(); longerWord = word1.Trim(); } //Create a dictionary with the characters of the shorter word Dictionary<char, int> lookup = new Dictionary<char, int>(); Dictionary<char, int> duplicates = new Dictionary<char, int>(); foreach (char c in shorterWord) { if (!lookup.ContainsKey(c)) lookup.Add(c, 0); else { if (!duplicates.ContainsKey(c)) duplicates.Add(c, 1); else duplicates[c] += 1; } } //update the count of characters if the character is present in the longer word foreach (char c in longerWord) { if (lookup.ContainsKey(c)) { lookup[c] += 1; } } //get the count of letters that has value greater than 0 var totalCount = lookup.Sum(l => l.Value); int dupCount =0; //get the letters that are common and have duplicates foreach(KeyValuePair<char,int> d in duplicates) { if(lookup[d.Key] > 0) { dupCount += (lookup[d.Key] * duplicates[d.Key]); } } return totalCount + dupCount; }`

- 2of 2 votes
You want to design a Cab system which will show you nearest 5 taxis.

Each taxi will continuously emit (x,y) coordinates.

You need to print the nearest taxi from (p,q).

- 2of 2 votes
You want to design a Cab system which will show you nearest 5 taxis.

Each taxi will continuously emit (x,y) coordinates.

You need to print the nearest 5 taxis from (p,q).

- 1of 1 vote
Alternate sorting: Given an array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum.

Eg.) Input : {1, 2, 3, 4, 5, 6, 7}

Output : {7, 1, 6, 2, 5, 3, 4}

- 0of 0 votes
Given a two dimensional array of string like

<”luke”, “shaw”>

<”wayne”, “rooney”>

<”rooney”, “ronaldo”>

<”shaw”, “rooney”>

Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2.

- 0of 0 votes
Rotate the matrix elements

For 3*3 matrix

Input

1 2 3

4 5 6

7 8 9

Output:

4 1 2

7 5 3

8 9 6

For 4*4 matrix

Input:

1 2 3 4

5 6 7 8

9 10 11 12

13 14 15 16

Output:

5 1 2 3

9 10 6 4

13 11 7 8

14 15 16 12

- 0of 0 votes
Given a set of numbers like <10, 36, 54,89,12> we want to find sum of weights based on the following conditions

1. 5 if a perfect square

2. 4 if multiple of 4 and divisible by 6

3. 3 if even number

And sort the numbers based on the weight and print it as follows

<10,its_weight>,<36,its weight><89,its weight>

Should display the numbers based on increasing order.

- 0of 0 votes
Given a list of numbers ex:(2,15,8) as a string with out any delimiters like space or ',' as str = "2158"; is there a way to parse the string an identify which one is double digit or single digit number ?? like 2,8 are single digit number and 15 is a double digit number

- 1of 1 vote
There are n number of conference rooms available in a company for the meeting. You need to book a meeting for a particular time slot. Write an algorithm to determine the number of conference rooms available for the meeting with given start time and end time.

Hint: any conference room with non- overlapping meeting will be selected.

- 1of 1 vote
Write a program to find all duplicate files within a folder.

- 0of 0 votes
What happens after you write “a.out” and press enter. He wanted to know the functionality performed by the OS after executable file is created of your code.

- 0of 0 votes
Finding Peak element in an array

- 1of 1 vote
This is a question I received in an online challenge.

A list of numbers are given. We need to find the total number of groups in which the digits of each number have same frequency.

For example if numbers are:

1

10

3

33

There are 4 groups:

G1={1}has one 1.

G2={3} has one 3.

G3={10}has one 1 and one 0.

G4={33}as two 3s.

- 0of 0 votes
Design an Algorithm for Amazon Advertisement Page

- 0of 2 votes
Given N ropes of lengths L1, L2, L3, L4, …, LN. I had to join every rope to get a final rope of length L1 + L2 + … + LN.

However, I can join only two ropes at a time and the cost of joining the two ropes is L1 + L2. I was supposed to join ropes in such a way that the cost is minimum.

- 3of 3 votes
Given an array and an integer k, find the maximum for each and every contiguous subarray of size k.(Using DP)

- 0of 0 votes
You have 10^9 user, 10^3 websites that users are subscribed to and 2000 servers. Some users will unsubscribe from certain websites. How would you architect this system to be scalable and performant?

- 1of 1 vote
This is was asked in Amazon SDE online test from Hacker rank.

Initech is a company which has CEO Bill and a hierarchy of employees. Employees can have a list of other employees reporting to them, which can themselves have reports, and so on. An employee with at least one report is called a manager.

Please implement the closestCommonManager method to find the closest manager (i.e. farthest from the CEO) to two employees. You may assume that all employees eventually report up to the CEO.

Tree structure:

Bill -> Dom, Samir, Michael

Dom -> Bob, Peter, Porter

Peter -> Milton, Nina

Sample Data:

CEO Bill has 3 employees reporting to him: {Dom, Samir, Michael}

Dom has three reports { Peter, Bob, Porter}

Samir has no reports {}

Michael has no reports {}

Peter has 2 reports {Milton, Nina}

Bob has no reports {}

Porter has no reports {}

Milton has no reports {}

Nina has no reports {}

Sample calls:

closestCommonManager(Milton, Nina) = Peter

closestCommonManager(Nina, Porter) = Dom

closestCommonManager(Nina, Samir) = Bill

closestCommonManager(Peter, Nina) = Peter