## SDE1 Interview Questions

- 0of 0 votes
Write code for scheduling algorithms for such a cab services provided you have a list of future bookings, and list of cabs in your fleet.

- 0of 0 votes
In an auctioning system, the bidder with the highest bid wins but charged at kth highest price. Develop a system for it. Solved it using a hashmap. Was asked to write a code for the same.

- 0of 0 votes
Design a system which would make a schedule for a user to complete a book in given number of days. A pre condition is that the schedule for every day should end at the end of some chapter.

Ex – 3 chapter with 10 pages each and user has to complete this book in 2 days, then the schedule should be either be 2 chapters on first day and 1 chapter on second or 1 chapter on first day and 2 chapters on second. (code)

- 1of 1 vote
Implement DFS

After I implemented this, I was told to implement it without recursion. He told me to write pseudo code. I wrote it using stacks.

- 1of 1 vote
Given a matrix (0,0 is to the botto9m left like co-ordinate system)of 0s and 1s and two co-ordinates find if there is a path between them, Also you can only travel via 1s and you can only go up or right.

Answer: Backtracking algorithm

- 0of 0 votes
given K sorted arrays merge them

Answer: Told him how to do using merge of merge sort. He wanted me to do another approach I googled later you can use min heap for it.

- 2of 2 votes
Given an array of integers find the element for which the sum of left = sum of right. example -1 100 1 98 1 should return index of 1 i.e 2

Answer: First told him about Brute Force approach and then told him if we can iterate once and get the total sum`int findIndex(A){ int sum =0; for(int i =0;i<A.lenght;i++) { sum+= A[i]; } int lSum=0; for(int i=0;i<A.length;i++) { int rsum = sum - lsum-A[i]; if(lsum==rsum) return i; lsum += A[i]; } return -1; }`

- 0of 0 votes
Given a string having a number:

"625626628"

Here the substrings are in consecutive order except for 1 substring which is missing. Find the missing substring.

Test cases:

"1235678" -> 4 is missing

"9979981000" -> 999 is missing

"624625627" -> 626 is missing

- 3of 3 votes
How can you design a data structure that can do the following operations in O(1) time:

Insert, Delete, Search, Max which returns the maximum number

I know delete, search and insert can be done O(1) time in a hashmap with a proper hash function. But not sure Max is even possible in O(1) with the presence of delete operation?

- 0of 2 votes
You have given a mathematical expression in string format.

Example: "3+12*3-4/7"

You need to write function which will return final result of the given expression. Don't use Expression Tree and start scanning from left to write.

It should be bug free.

- 0of 0 votes
A 2D matrix is given to you. Now user will give 2 positions (x1,y1) and (x2,y2),

which is basically the upper left and lower right coordinate of a rectangle formed within the matrix.

You have to print sum of all the elements within the area of rectangle in O(1) running time.

Now you can do any pre computation with the matrix.

But when it is done you should answer all your queries in constant time.

Example : consider this 2D matrix

1 3 5 1 8

8 3 5 3 7

6 3 9 6 0

Now consider 2 points given by user (0, 2) and (2, 4).

Your solution should print: 44.

i.e., the enclosed area is

5 1 8

5 3 7

9 6 0

- 1of 1 vote
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.

- 5of 5 votes
Given an integer array, adjust each integers so that the difference of every adjcent integers are not greater than a given number target.

If the array before adjustment is A, the array after adjustment is B, you should minimize the sum of |A[i]-B[i]|

You can assume each number in the array is a positive integer and not greater than 100

Given [1,4,2,3] and target=1, one of the solutions is [2,3,2,3], the adjustment cost is 2 and it's minimal. Return 2.

- 0of 0 votes
Array of size (n-m) with numbers from 1..n with m of them missing. Find one all of the missing numbers in O(log). Array is sorted.

Example:

n = 8

arr = [1,2,4,5,6,8]

m=2

Result has to be a set {3, 7}.

- 1of 1 vote
Give you a list of Modules of Dependencies,

A --> B,C

B --> D,E,F

D --> F

And please return back a correct build order of Module (input)

- -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

- 1of 1 vote
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.

- 1of 1 vote
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.