## Software Engineer / Developer Interview Questions

- 0of 0 votes
Suppose you are given a puzzle that is represented as a matrix with 0s and 1s, where a 0 indicates you’re allowed to move into that position and 1 means you’re not allowed to move in that position. Write a function that given a start position and an end position, returns a boolean value indicating if there exists a path from start to end. you are only allowed to move up, left, right and down. Diagonal movement is not allowed.

Example #1

Input

0 0 1 0 1

0 0 0 0 0

0 1 1 1 1

0 1 1 0 0

start: 4,1

end 0,3

Output - true

Example #2

Input

0 0 1 1 1

0 1 0 0 0

1 1 1 1 1

0 0 0 0 1

start: 0,0

end: 1,2

Output - false

- 0of 0 votes
Implement a function that returns the i-th most popular item sold

at xyz company. You cannot rely on any libraries.

Class Item {

String itemId;

int quantitySold;

}

/**

find the i-th most popular item in the list

**/

String find(List<Item> items, int i) {

// your code goes here

}

- 0of 0 votes
Search in a sorted rotated array.

- 0of 0 votes
Merge K sorted singly linked list

- 0of 0 votes
paint a list of N houses and M colors, each combination has cost, minimize the total cost without color in row.

- 0of 0 votes
How do you traverse a binary tree and output the nodes in-order? Do it in O(1) space.

Hint: You can modify the tree.

- 1of 1 vote
Given an unsorted array, find Kth smallest element in it.

A = 12, 3, 17, 0, 9, 6, 100

K = 3 -> 6

- 0of 0 votes
write a function that takes two integers, k and n, with 0 ≤ k ≤ n, and prints out all subsets of size k of the integers 1, ..., n, one subset per line. The order of the subsets and the order of elements within the line doesn't matter.

example 1: print_subsets(k=1, n=2);

1

2

example: print_subsets(k=2, n=3);

3 1

2 3

1 2

- 0of 0 votes
Given two binary trees ( not BST) , return true if both of them have same inorder else return false.

Eg.`B / \ A C`

`A \ B \ C`

Both of the trees have same inorder ( A-B-C) hence function will return true

P.S.

Please note, we can write inorder method call it once for first tree and then second tree, and finally compare both inorder.

We want to parallely do inorder on both tree, if there is mismatch between inorder nodes of both trees, we can stop the traversal and return false

- 0of 0 votes
Bring up as many approaches: Your goal is to make faster web browser for phones. You can change the phones, the data center etc. There's a limited network bandwidth and the browsers from the companies can't be altered.

- 0of 0 votes
We've got Quad-trees making up a screen. Every box of the Quad-tree has either color white or black. How would you design the data structure of this Quad-tree?

And how would you count the number of pixels in a screen of a given color, given a Quad-tree?`int numberOfPixelsGivenColor(QuadTree* t, bool col)`

i used bool to specify white/black.

- 3of 3 votes
write a function:

`int median(int a, int b, int c)`

and then write another function:

`int median(int a, int b, int c, int min, int max)`

- 0of 0 votes
Then the more difficult question was how I'd reverse this.

Implement function:`GetStringsfromNumeronym(numeronym){...}`

h3e -> {house, halle, hocke....}

- 0of 0 votes
Started out with simple question - to get warmed up:

Implement a function:`makeNumeronym(string s){...}`

Ex: house -> h3e, marcus -> m3s

- 0of 0 votes
Given a singly linked list, swap the list items in pairs (reconnect the pointers, not simply swap the values). For example:

Before: A->B->C->D

After: B->A->D->C

- -1of 1 vote
Hardest bug you faced

- 2of 2 votes
Let's assume that there's an array that has nonzero natural numbers where all the numbers repeat an even number of times, except for one value that repeats an odd number of times. Can you write me a function that takes this array, and returns the value that occurs the odd number of times?

Ex : - [ 4, 7, 2, 2, 5, 3, 5, 7, 7, 3, 4, 5 ]

- 1of 1 vote
During appraisal due to bell curve funda a manager is restricted to give promotion to only one of his team members. Three of his team members are equally competant. He wanted to select one by giving a puzzle. He called his three talented team members and blidfolded them. He placed a hat on each of their heads. Manager took off their blindfolds and gave following clues and conditions

1) Each hat is either white or blue

2) There is atleast one blue hat

3) Contest is fair for all the three team members

4) Each team member can see the hat of other team members but not his.

5) The team members should not communicate to each other.

The manager declared that who ever comes up first with right answer shall be given promotion.

The most talented of his team members came up with right answer and explanation.What is the answer and the logic behind that?

- 0of 0 votes
Design a hotel reservation system. To make it simple, we assume that the hotel has only one building and the building has only one floor. Design your objects so that they work better with a non-sql database, say a document-oriented database.

- 1of 1 vote
Assume we only take the least significant digit of each value in fibonacci sequence, and form the sequence of digits into pairs. In those pairs, the first value of one pair is the same as second value of its predecessor.

As we know the fibonacci sequence is 1, 1, 2, 3, 5, 8, 13, 21...

so the pair sequence is:

[1, 1], [1, 2], [2, 3], [3, 5], [5, 8], [8, 3], [3, 1] ...

Write a function to output the first n pairs of this sequence.

void Outputpairs(int n)

- 3of 3 votes
Given an array Of integers build a new array of integers such that every 2nd element of the array is greater than its left and right element.

eg:

[1,4,5,2,3]

o/p:

[1,4,2,5,3]

Soln proposed:

Step 1:Sort The array -> O(nlogn)

Step 2:Use 2 indices: one starting at leftmost index and other at rightmost index.

and populate the new array alterntely using the left pointer(index) first and then the right pointer and then increment the pointer used. till both the pointers meet/cross each other. -> O(n).

- 0of 0 votes
given an expression like 3*4 + 8-9 (only +, - , * operators) as a string evaluate it strictly from left to right

- 0of 0 votes
snake sequence. same as in other interviews

- 0of 0 votes
given a horizontal array of strings convert it to vertical. like english characters are read left to right. convert them to a chinese format which is read vertically.

eg.

epic is a healthcare company.

interviewing for software developer.

print this vertically sentence by sentence.

- 4of 4 votes
Given an m x n matrix where each row element is sorted, but the columns do not appear in sorted order, write a function to print each matrix element in sorted order.

Example matrix:

matrix = [

[20, 40, 80],

[5, 60, 90],

[45, 50, 55]

]

Your function should print 5, 20, 40, 45, 50, 55, 60, 80, 90.

Add on: Assume that we are space-constrained such that we can only hold one row in memory at a time. Optimize your function to work under such constraints as efficiently as possible.

- 0of 0 votes
You are given an N*N matrix. The matrix contains characters. Write a program to find a word in the matrix.The word can be found in either the rows or columns or the diagonals. The program should return true if the word is found and false if the word is not found.

- 0of 0 votes
This was asked in an Online written test that was timed (60 mins). And this question was one among the three.

"Write a method to merge three sorted integer arrays into just one array"

Nothing more or less was given. Since it was a written test I assumed that the 1st array had space towards to end which can fit the other two arrays. I can code this but given the timer limitations (of 20 mins per question) I thought it was a bit too much for me to handle unless there is a more obvious way to do this. I did it using two arrays and using the resultant array, I merged it with the 3rd array. That was the best i could think of at that time.

- 0of 0 votes
Amazon wants to implement a new backup system, in which files are stored into data tapes. This new system must follow the following 2 rules:

1. Never place more than two files on the same tape.

2. Files cannot be split across multiple tapes.

It's guaranteed that all tapes have the same size and that they will always be able to store the largest file.

Every time this process is executed, we already know the size of each file, and the capacity of the tapes. Having that in mind, we want to design a system that is able to count how many tapes will be required to store the backup in the most efficient way.

The parameter of your function will be a structure that will contain the file sizes and the capacity of the tapes. You must return the minimum amount of tapes required to store the files.

Example:

Input: Tape Size = 100; Files: 70, 10, 20

Output: 2

- 0of 0 votes
Reverse left node of BT.

1 (ROOT)

/ \

2 3

/ \

4 5

/ \

6 7

to

1

/

2 - 3

/

4 - 5

/

6 - 7

(6 is root)

- 1of 1 vote
Find a given element in sorted array.

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

follow up: If the sorted array is shifted left by unknown number, modify existing binary search to find a element in modified array

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