Union find in PythonAre a and b already connected? If you're adding undirected edges one at a time, union find answers that by comparing two roots. 1. Follow the parents Each node starts in its own group with parent[x] =2 min read·basecase-utkarsh.hashnode.devNov 22
Building a tree from preorder + inorderPreorder tells you which node is the root. Inorder tells you which nodes go to its left and which go to its right. Take one root at a time, split the arrays, and recurse. With a hashmap and a pointer6 min read·basecase-utkarsh.hashnode.devNov 22
Sliding window without the guessworkSliding window turns "check every subarray" (O(n²)) into one pass (O(n)). Grow the window on the right, shrink it on the left, and keep state you can update in O(1). 1. Spot it Use a sliding window wh3 min read·basecase-utkarsh.hashnode.devOct 18
Binary search without the off-by-one guessworkBinary search is easy to explain and easy to get wrong. left <= right or left < right? mid or mid + 1? Return left or right? Here's my first attempt at LeetCode 981: Time Based Key-Value Store, which3 min read·basecase-utkarsh.hashnode.devOct 11