2017-12-28 05:04:00 UTC
This is a simple 10 step process to follow to solve any programming interview problem in a pressure cooker situation. Train your mind to remember this for any question and then it will do it automatically, especially when its game time!
Questions to ask at this stage:
1. Ask constraints (Is there any constraints on space, time, input format etc)
2. if its an array, ask if it's sorted (if it is, binary search can be a possibility)
3. Think and ask for edge cases
Step 2: Write 5 or more test cases (For few problems, writing more tests helps)
Write tests for empty input, large input, two normal size input, and other edge cases inputs and give 5 minutes on test analysis.
Step 3: Use one of the two normal size input and write it in the middle of whiteboard
Step 4:Find Pattern:
After writing one of the test cases in front of you, go through this questionnaire to know what sort of problem is it:
1. Is the question of inputs where input Is sorted? -> Think of using binary search
2. Is the question about some pattern among indexes of array/string? -> Its a math problem, try finding an equation between elements.
> Like palindrome is where ith element and (n-1-i)th elements are equal,
> sum of difference of diagonals is where you have to find difference of input_array[i][j] and input_array[n-1-i][j],,
If you can find a pattern or equation, its is a math problem
3. Is the question of a repetitive pattern /overlapping elements /common elements? -> Think Hashing and then Dynamic Programming
> Find two repetitive numbers in array
> Longest common continuous sub-string between two strings
4. Is it a searching/sorting problem? -> Binary search, sorting algorithms, object sorting
> Sort list of candidates with respect to the number of votes they got
> Search in a sorted array
5. Is it asking to find greatest/least of the numbers? -> Think Heap (Takes O(n) time for getting the max)
> Max k elements
> Winner of an election
> Min k elements
> Most frequent n-words.
6. is it a recursion problem?
> Palindrome of a string
7. is there any basic data structure involved?
hash -> Repeat, Search, Exists kind of problems
heap -> finding max, min
stack -> performing LIFO
queue -> FIFO
LinkList problems? > Find if cycle in LL, Doubly LL etc
tree problem ? > Lowest common ancestor etc
9. Is this a word related problem? - > Trie
> prefix based search
> word problem
> dictionary problem
> validations of words from dictionary
> Lexicographic ordering of words
> Find valid words from scrabble game
> Valid words from twitter tweets
10. Is this a graph traversal problem? -> Think BFS and then DFS
> Island 1/0 problem
> shorted path problems
Owned & Maintained by Saurav Prakash
If you like what you see, you can help me cover server costs or buy me a cup of coffee though donation :)