Contents
T wo Pointers...... ..................................................................................................................4
Shift Zeros to the End....................... .......................................................................................................................... 4
Ne xt Le xicogr aphical Sequence.............................................................................................................................. 9
Hash Maps and Sets........................................................................................................16
Longest Chain of Consecutiv e Numbers.......................................................................................................... 16
Geometric Sequence T riplets................................................................................................................................ 20
Link ed Lists...................................................................................................... .................. 27
P alindromic Link ed List............................................................................................................................................27
Flatten a Multi-Le vel Link ed List.......................................................................................... ................................31
Fast and Slow Pointers .................................................................................................. 36
Happy Number Time Comple xity Analysis...................................................................................................... 36
Binary Search................................................................................................................... 39
Find the Median F rom T wo Sorted Arra ys....................................................................................................... 39
Matrix Search.................................................................................................................................. ............................ 46
Local Maxima in Arra y..............................................................................................................................................52
Weighted Random Selection................................................................................................................................. 58
Stacks.................................................................................................................................. 65
Repeated Removal of Adjacent Duplicates..................................................................................................... 65
Implement a Queue Using Stacks........................................................................................................................ 68
Maximums of Sliding Window.............................................................................................................................. 74
Heaps.................................................................................................................................. 81
Sort a K -Sorted Arra y............................................................................................................................................... 81
T rees.................................................................................................................................... 88
Binary T ree Symmetry............................................................................................................................................. 88
Binary T ree Columns................................................................................................................................................ 92
K th Smallest Number in a Binary Search T ree................................................................................................ 97
Serialize and Deserialize a Binary T ree.......................................................................................................... 102