Learnings
- Always handle edge cases
- Look at the data structures, queues, stack, map
Singly Linked List
- To return parent keep a dummy/root copy and return dummy.next
- Dummy parent means it has a value of null and its next is the first value. That is the root
- Fast and slow runner if you it becomes equal and fast has not become null means it is circular
- Removing list, just copy the next val
Rotating Images:
- If you want to rotate image and you know the order of the arrays end point, you can assign it to just linked list and poll.
String problems
- Character.isDigit and Character.isLetter
- Prefix contains - you can check the first word and slowly trim word and check if .contains each other words
Array Problems
- Valid sudoku - https://leetcode.com/submissions/detail/323519342/
- Check horizontal/vertical then 3x3
- Mid traversals:
int mid = s.length / 2;
for(int first = 0, last =s.length -1; first < mid || last >mid; first++, last--)
2D ARRAY
- BFS for grid traversals, do not be afraid to create a new linked list in the recursion for the new set of data (Amazon exam is the rotting orange challenge, https://leetcode.com/problems/rotting-oranges/submissions/)
- To avoid revisiting you can either destroy matrix clone matrix or do a visited boolean matrix
Tree level
- Add null on each level, if two nulls then that’s the actual null else increment level
Search
- Binary tree: start + (end- start) /2
Math.max
- Recursive algo for trees
- Permutations using sets and arrays 2^n solution on possible permutations
Data structure
- Treemap for ordered key set
- Master compute for maps
- Arrays.stream
Arrays
- Arrays.copyOfRange(arr, start, end); - sub array