↳
The two answers above suck. Don't say them if you get an interview.
↳
This looks so good: bit.ly/faang100
↳
i believe in work not in words
↳
Keep dividing while storing stream e.g - 10101-1 will be like 1 -> 1 0 -> 10 1 -> 101(5) divided and remain 10 0 -> 100 (4) divided and remain 1 1 -> 11(3) divided and remain 0 Less
↳
I have answered the second question saying that we can keep storing the 1's and 0's in a vector and the moment we hit -1, we will reverse iterate the vector and can get the integer number out of the bit stream and can see whether %3 is zero or not. he told me to optimize the program in terms of space and time complexity. I told we can compress the bit stream in such a way so that when we have continuous 1's and 0's can be replaced by only single 1's and 0's. He was not satisfied with the answer. Less
↳
Question 2 is damn easy and can be done in o(1) space complexity:- This is basically a conversion of base-2 to decimal base-10 . int finalNum = 0; keep reading the val of (1's and 0's till we hit -1), for each received input, follow the below logic. finalNum = 2 * finalNum + Less
↳
By i++ and j++, I think you mean —
↳
This is an interesting read: bit.ly/faang100
↳
int j = numbers1.length-1; for(int i=0;i!=j;i++){ while(numbers1[j] == 0) { j--; } if(i==j)break; if(numbers1[i] == 0){ numbers1[i] = numbers1[j]; numbers1[j] = 0; j--; } } return numbers1; Less
↳
Use Trie data structure or any graph based representation.
↳
take a map with string and vector in cpp, and store positions of a particular element in vector, the best part vector will be sorted. Less
↳
take a map with string and vector in cpp, and store positions of a particular element in vector, the best part vector will be sorted. Less
↳
I discussed the approach and wrote code for it. There was one mistake in the code which I corrected and provided proper code and he was satisfied with it. The low level design question - which was not explained well (or may be I could not understand) - and I gave a reflection based answer (which seemed to be the only way to solve what I understood). Later on after some clarifications, I came up with 2 more approaches, but probably he was not satisfied with it and insisted on making it better, without explaining problems in design I proposed. I think he had something in mind, and he wanted me to read his mind and come up with the same solution, which I could not. After the interview I googled for it and I feel my solution was quite close (like 80% close) to a highly rated stackoverflow answer. After this round I was told to leave :). Less
↳
Can you please share what was the low level design question that he asked you ?
↳
There is no correct answer and the interviewer is just trying to assert his mental superiority. Less
↳
The correct answer is a negative number.
↳
Appreciated