Tips for Sorted Array or Matrix¶
In an interview, whenever you're given a question where the input array is sorted, here are some super useful things to consider:
- Binary Search
- Two (or three) pointers
- A sliding window
- Traversing from the right
For row-wise and column-wise sorted matrix:
Make sure to write down a couple examples and try experimenting with these approaches. Even understanding that these approaches may aid in finding an answer with a sorted array, you're showing your interviewer that you have a good understanding of the array data structure. Be mindful of negative values and duplicates as you're experimenting!