Solutions Engineer Interview Questions
- 5of 5 votes
AnswersGiven K sorted (ascending) arrays with N elements in each array, implement an iterator for iterating over the elements of the arrays in ascending order.
The constructor receives all of the input as array of arrays.
You need to implement the MyIterator class with a constructor and the following methods:class MyIterator<T> { T next(); boolean hasNext(); }
You are allowed to use only O(K) extra space with this class.
example:
input:[[1,5,7], [2,3,10],[4,6,9]]
The iterator should return:
- torchs January 13, 2020 in Israel1,2,3,4,5,6,7,9,10
| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Algorithm - 0of 0 votes
AnswersWrite a method that merges a fixed number of streams containing an infinite sequence of monotonically increasing integers into an output stream of monotonically increasing integers. It is important to note that the input stream are infinite, so any solution based on the length of the streams would be considered incorrect.
Note that the question was given in the context of Java with the below code given as the base contract for the method.public void merge(List<Stream> inputStreams, Stream outputStream) { // Implement me }
This was also provided as the definition of "Stream" in this case, and not what is defined in java.util.stream.Stream.
- gr1ml0ck October 05, 2019 in United Statesinterface Stream { // Retrieves but does not remove the next item from the stream int peek(); // Retrieves and removes the next item from the stream. int poll(); // Puts an item into the stream void put(int i); }
| Report Duplicate | Flag | PURGE
Amazon Solutions Engineer Algorithm - 7of 7 votes
AnswersGive an array A of n integers where 1 <= a[i] <= K.
- aonecoding July 12, 2018 in United States
Find out the length of the shortest sequence that can be constructed out of numbers 1, 2, .. k that is NOT a subsequence of A.
eg. A = [4, 2, 1, 2, 3, 3, 2, 4, 1], K = 4
All single digits appears. Each of the 16 double digit sequences, (1,1), (1, 2), (1, 3), (1, 4), (2, 1), (2, 2) ... appears. Because (1, 1, 2) doesn't appear, return 3.| Report Duplicate | Flag | PURGE
Google Solutions Engineer - 4of 4 votes
AnswerWish Interview
- aonecoding November 03, 2017 in United States
-Phone: Two sum, Three sum, N sum(recursion)
Onsite:
-Implement merge sort (recursion&iteration)
-Merge two sorted arrays: one of length m+n, the other n; store the result in the longer array
-Given a number print diamond:
Given 1
Pirnt 1
Given 3
Print
1
121
1
Given 5
Print
1
121
12321
121
1
- Rank N people in a game. There may be a tie among participants. How many possible ways of ranking there is.
- Design: Define a bot as an IP that hits the web app over M times in the past T seconds (not necessarily hits on the same page. Also take into account different API calls.) How to design a bot detector layer and where to place it in the system.| Report Duplicate | Flag | PURGE
Wish Solutions Engineer Algorithm - 0of 0 votes
Answer/*Find minimum size of text window which contain all keywords of a search query from document.
- npkatre104 June 16, 2017 in United States
Order of keywords don't matter.
Input:
Document: "MS(1) x y Is MS(5) x y MS(8) x Is Awesome x y z Awesome"
doc index dictionary:
{
Keyword: Index Position for keyword in doc
"MS": [1,5,8],
"Is": [4,10]
"Awesome": [ 11, 15] (n)
}
Search Input 1 : "MS is" ( k)
Result: "Is MS Ms" --> [Ms: 5 ; "Is" : 4] --> 2
Search Input 2: "Ms is Awesome",
Result : "MS x is Awesome" --> [Ms:8, Is: 10, Awesome: 11] ---> 4
for -> n
n^k
[1 4 5 8 10 11 15]
*/| Report Duplicate | Flag | PURGE
Microsoft Solutions Engineer - 2of 2 votes
AnswersIterate over a singly linked list backwards. Call print on each node.
Example: The list A->B->C should print as
"C B A"class Node { public Node next; public String value; }
There are 4 solutions
- Nerd March 16, 2017 in Europe
1) recursive
2) iterative with O(n) memory
3) iterative with O(1) memory and O(n²) runtime
4) iterative with O(1) memory and O(n) runtime (for this solution the initial list may be modified)
Explain all 4 solutions and write the code for solutions 3 and 4| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding - 1of 1 vote
AnswersYou are given an array of integers.
- Nerd March 16, 2017 in Europe
Write an algorithm that brings all nonzero elements to the left of the array, and returns the number of nonzero elements.
The algorithm should operate in place, i.e. shouldn't create a new array.
The order of the nonzero elements does not matter. The numbers that remain in the right portion of the array can be anything.
Example:
given the array [ 1, 0, 2, 0, 0, 3, 4 ],
a possible answer is [ 4, 1, 3, 2, ?, ?, ? ], 4 non-zero elements, where "?" can be any number.
Code should have good complexity and minimize the number of writes to the array.| Report Duplicate | Flag | PURGE
Facebook Solutions Engineer Coding