You are on page 1of 2

Q1 - Return 1st non repeated no from a stream on integer numbers.

Input - 6, 8, 4, 6, 7, 4, 8, 7, 8, 13, 11, 13


Output - 6, 6, 6, 8, 8, 8, 7, N, N, 13, 13, 11

Initially she give an solution using Hash map but it was not keeping
the order of integers.
She than suggest using a ordered Hash but time complexity is still
O(N2)
After getting hints she was able to using doubly linked list.
She took many hints to use Hash properly to store list reference as key
- value for fast search within list.
Finally she suggested the solution with overall O(N) time complexity
using hash and doubly linked list.

Q2 - Print all valid on permutations of N left and N right parentheses


Input - N = 3
Output - ()()(), (()()), ((( )))

She find it difficult to crack. I gave her many hints but she find it
challenging to code.
She suggested an recursive approach using input two array filled with
N Left and Right parentheses
But she was not able to code it.
Even her code was nowhere near a solution.
Her final code was.

public void print(String[] left, String[] right, int n){

while(n>0){
for(int i=0; i<n; i++){
System.out.println(left[n]);
System.out.println(right[n]);
}
for(int i=0; i<n; i++){
System.out.println(left[n]);
System.out.println(right[n]);
}
n=n-1;
print(left, right, n);
}

You might also like