## Recent Interview Questions

- 0of 0 votes
Completely blew it on this question today.

1.) Given an array, find the maximum difference between two array elements given the second element comes after the first.

For example.

array = [1,2,3,4,5,6,7]

We can take the difference between 2 and 1 (2-1), but not the different between 1 and 2 (1-2).

This question is super easy, I solved it within minutes of getting of the phone. I came up with an O(n^2) solution over the phone. My improved solution was O(n).

- 0of 0 votes
Warm-up question: Write a function that prints all ASCII characters. You are not allowed to use for/while loop.

- -1of 1 vote
Hello guys

I have an interview with quality assurance engineer in amazon for QAE position please help

- 1of 1 vote
1. qaz is a value for a number where this number is less than the other next values which have indexes larger than the index of this number.

for example: 33 , 25 , 26 , 58 , 41 , 59 -> qaz of (33) = 3 where 33 less than 3 numbers (58 , 41 , 59), qaz of (25) = 4 and not 5 because the index of 33 is less than the index of 25, qaz of (26) = 3 , qaz of (58) = 1 , qaz of (41) = 1 , qaz of (59) = 0.

the question is to find the max qaz.

it can be solved simply using 2 loops which takes time of O(n^2).

that's ok but how can we solve this problem in O(nlogn).

I have an approach and know the algorithm I got during the interview but it take a 40 of me to find it and write the code, but it was hard to think about it during the interview in that way.

I want to know if somebody can think and write the code in less than 20 minutes !!!

- 0of 0 votes
Write a function that receives a stream of pairs: id (some unique integer) + weight (positive real number).

The stream ends with the special pair {0,0}.

The function should return one the unique ids at random, with probability proportional to its weight (compared to the total weights sum when stream has ended).

Stream size and weights sum are unknown in advance, and you are allowed O(1) memory consumption.

Example: If this was the stream: {1,2},{2,2},{3,4},{4,10}, then id 2 would be returned with probability 1/9.

- 0of 0 votes
Write a class that receives in the constructor a vector of strings representing a browser history (URLs), and a method for "auto-complete":

The method that receives a string representing a partial URL typed by the user and returns a vector of all possible completions of this partial URL (prefix).

- 0of 0 votes
You are given a binary search tree and a positive integer K. Return the K-th element of the tree.

No pre-processing or modifying of the tree is allowed.

- 0of 0 votes
You are given an array of distinct numbers. You need to return an index to a "local minimum" element, which is defined as an element that is smaller than both its adjacent elements. In the case of the array edges, the condition is reduced to one adjacent element.

Reach a solution with better time complexity than the trivial solution of O(n).

If there are multiple "local minimums", returning any one of them is fine.

- 0of 0 votes
You are given a positive integer number N. Return the minimum number K, such that N can be represented as K integer squares.

Examples:

9 --> 1 (9 = 3^2)

8 --> 2 (8 = 4^2 + 4^2)

15 --> 4 (15 = 3^2 + 2^2 + 1^2 + 1^2)

First reach a solution without any assumptions, then you can improve it using this mathematical lemma: For any positive integer N, there is at least one representation of N as 4 or less squares.

- 0of 0 votes
You are given a double linked list and an array of pointers to elements in this list (no assumptions can be made on the array - number of pointers, order and duplicates allowed).

Return the number of sequences of elements (groups of consecutive elements), pointed by the array.

For example, if this is the array (number relates to index in the list, not the actual pointer value): 9,1,3,7,8,5,2.

Then output is 3, representing these sequences: [1,2,3], [5], [7,8,9]

- 0of 0 votes
Given a 2D array of size nXn with values from 1 to n^2 permuted in the 2D array i.e no duplicates.

Find the longest snake in the array such that snake can go upward, downward, right, left and each and every adjacent value in the snake should differ by 1.

Ex:

2 5 6

3 4 9

1 7 8

Answer is 5. [2,3,4,5,6].

- 0of 0 votes
You have a binary search tree and you have to return the two nodes such that there sum i equal to ‘K’. Pseudo code is to be given.

O(n)time & O(n) sppace is easy but challenge O(n) time & O(1) space.

- 0of 0 votes
How would you implement an algorithm for Decision Tree Algorithm - Machine Learning? How would you store records for a feature. Mention all the data structure you would use to make your work easy.

- 0of 0 votes
Count number of BST.

We are given N Nodes ,each having unique values in[1,N] how many different Binary search tree are possible using all of them.

- 0of 0 votes
what are real applications of avl tree?

- 1of 1 vote
2D matrix with 0s and 1s. Try to find out how many countries in this matrix?

For example:

[[1,1,1,0]

[1,1,0,0]

[0,0,0,1]]

return 3, because one for 1s, one for 0s, and one for the last one.

another example:

[[1,1,1,1]

[0,0,0,0]

[1,0,0,1]]

return 4

- 0of 2 votes
You are given a 2D Array that contains only 0s and 1s in sorted order. i.e. First Os and then 1s.

Array:

0 0 0 1

1 1 1 1

0 0 1 1

0 1 1 1

You have to figure out the row that contains maximum number of 1s.

e.g. in above case we have row 2 as the answer.

- 0of 0 votes
Write a function that does an in-order traversal of a tree and prints out the contents (Assume each node has 1 piece of content which is an integer).

Write this function without using recursion (you can assume a library that has stack/queue/list objects with some standard methods is available for use by you).

What is the maximum size your stack can grow to and what is the expected size that your data structure can grow to assuming that the tree has n nodes?

- 0of 0 votes
Find and fix the bugs in the following function that is supposed to remove the head element from a singly linked list.

`void RemoveHead (node * head) { free(head); head = head - > next; }`

- 0of 0 votes
Write a function that takes a string as an input and outputs an integer, e.g. turning "1234" into 1234.

- 0of 0 votes
Design your own String Pooling system. It should return a String with request of more length. String pool should have strings of different sizes available. When requested, it should just be returned to client and when client is done using string, it should be added back to string pool for other client to use.

- 0of 0 votes
Given a string, write a function to determine whether it is a valid IP address or not. Regex solutions are acceptable, but what other ways can it be done?

boolean isValidIP(String s) {

//code here

}

- 0of 0 votes
You are given an organization hierarchy tree (n-ary tree). Every employee (node) has some value (can be -ve or +ve). You have to host a party and have to invite employees such that the total value (summation of each node value) of all the employees is maximum.

there is a rule: no one likes to see their bosses in the party. So you cant invite an employee's immediate boss or subordinate.

You can skip more than 1 level if it gives you maximum value.

- 0of 0 votes
It started with simple behavioral questions like, why facebook, cultural fit questions etc. They asked simple question.

`You are at latest version of committed code. assume one branch of code. Code version is in sorted order. It is corrupted with bug. You have fun isBug(VerNumber) which returns True or False. Find the version in which bug was introduced?`

This can be solved with linearly checking each version or modified binary search. Person asked to write test cases? This is where i struggled. how do you write test case for this question? Do you guys use framework syntax or something else?

- 0of 0 votes
List of all the test cases for the following program

read p

read q

if p+q >100

pring large

end if

if p>50

print "p is larger"

end if

- 0of 0 votes
OSI layers

- 0of 0 votes
Diff between tcp and udp

- 0of 0 votes
Life cycle of bug, test severity and priority

- 0of 0 votes
shell script to rename all files in directory

- 0of 0 votes
find if linked list is palindrome

a -> b-> Null