How do you find whether a sorted array has a pair that sums to a target?
Simple meaning
Place pointers at both ends
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready DSA interview set questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
Place pointers at both ends
Open the full page for Why, Steps, Example and Key takeaway.
A slow pointer marks the end of the unique prefix
Open the full page for Why, Steps, Example and Key takeaway.
Walk both arrays with two indices and always append the smaller head into a result.
Open the full page for Why, Steps, Example and Key takeaway.
Two pointers skip non-letters/digits, compare lowercased characters, and stop on mismatch.
Open the full page for Why, Steps, Example and Key takeaway.
Dutch National Flag uses low, mid, and high pointers: swap 0s to the left, 2s to the right, and advance on 1s.
Open the full page for Why, Steps, Example and Key takeaway.
Sum the first k elements, then slide: add the incoming element and subtract the leaving one, tracking the max.
Open the full page for Why, Steps, Example and Key takeaway.
Maintain a running window sum as you slide by one, then divide by k for each position.
Open the full page for Why, Steps, Example and Key takeaway.
Keep a deque of indices of negatives inside the current window, dropping those that slide out of range.
Open the full page for Why, Steps, Example and Key takeaway.
Push opening brackets and pop when you see a matching closer
Open the full page for Why, Steps, Example and Key takeaway.
Store items in a list and treat the end as the top: append to push, pop from the end to pop, and peek the last index.
Open the full page for Why, Steps, Example and Key takeaway.
Scan tokens: push numbers, and for an operator pop two operands, apply it, and push the result.
Open the full page for Why, Steps, Example and Key takeaway.
Push every character, then pop them all into a new buffer.
Open the full page for Why, Steps, Example and Key takeaway.
A stack is LIFO and fits undo, DFS, matching brackets, and nested evaluation.
Open the full page for Why, Steps, Example and Key takeaway.
Push into an in-stack.
Open the full page for Why, Steps, Example and Key takeaway.
Start with "1" in a queue.
Open the full page for Why, Steps, Example and Key takeaway.
Walk with prev, curr, and next: save curr.next, point curr.next to prev, then advance prev and curr.
Open the full page for Why, Steps, Example and Key takeaway.
Slow pointer moves one step, fast moves two
Open the full page for Why, Steps, Example and Key takeaway.
Floyd's tortoise and hare: slow walks one, fast walks two
Open the full page for Why, Steps, Example and Key takeaway.
Advance a fast pointer n steps, then move fast and slow together until fast falls off
Open the full page for Why, Steps, Example and Key takeaway.
Copy the next node's value into the current node and bypass next by pointing current.next to next.next.
Open the full page for Why, Steps, Example and Key takeaway.