Sunday 7 February 2016

Some technical interview questions

Here are some technical interview questions asked now day's.

1.  Which is faster, heap or stack?
Solution : The stack is faster because the access pattern makes it trivial to allocate and deallocate memory from it (a pointer/integer is simply incremented or decremented), while the heap has much more complex bookkeeping involved in an allocation or free. Also, each byte in the stack tends to be reused very frequently which means it tends to be mapped to the processor's cache, making it very fast. Another performance hit for the heap is that the heap, being mostly a global resource, typically has to be multi-threading safe, i.e. each allocation and deallocation needs to be - typically - synchronized with "all" other heap accesses in the program.


2. Which data structure is used in recursion calls? And why?
Solution : Well if you think about it, then you might be wondering that there should be some place where those function calls are stored. And there is some order in which they are called, right...
Yes, the answer is stack data structure. Now think why not queue.




3. Find all possible combination of given string?


4. Which data structure you will use for maintaining companies stock market values?
Solution : We can use hash/dictionary for storing company names/id and Queue data structure for storing stock market values.


5. Given a running stream of integers, you need to find median at any given instance? You need to solve it in O(1)?


6. There is a matrix of 10 X 10 size ( or say 2d array), you need to find numbers which are common in all rows?


7. Find the longest palindrome of any given string?


8. Let say you are storing files on some folder, how can you track/check if same file is already stored while the user is uploading the file?


9. Given an array of size million, it only contains 0's and 1's . How can you sort this array in O(n)?