How do you find all start indices of anagrams of p inside s?
Simple meaning
Maintain a window of length p with character counts
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.
Maintain a window of length p with character counts
Open the full page for Why, Steps, Example and Key takeaway.
Sliding window: the window is valid while window_size minus the count of the most frequent character is at most k.
Open the full page for Why, Steps, Example and Key takeaway.
This is a window where the number of zeros is at most k
Open the full page for Why, Steps, Example and Key takeaway.
Scan left to right and keep a stack of indices with decreasing temperatures
Open the full page for Why, Steps, Example and Key takeaway.
Store values on one stack and running minima on a second stack (or pairs of value and min).
Open the full page for Why, Steps, Example and Key takeaway.
Iterate asteroids and use a stack of survivors.
Open the full page for Why, Steps, Example and Key takeaway.
Use a stack of (previous_string, multiplier) pairs: on '[', push the current buffer and k, on ']', pop and repeat the inner buffer.
Open the full page for Why, Steps, Example and Key takeaway.
Keep a buffer, head index, count (or head and tail), and capacity.
Open the full page for Why, Steps, Example and Key takeaway.
Maintain a frequency map and a queue of candidate characters (or indices).
Open the full page for Why, Steps, Example and Key takeaway.
Multi-source BFS: enqueue every rotten orange at time 0, then spread to adjacent fresh oranges level by level.
Open the full page for Why, Steps, Example and Key takeaway.
Use a dummy head and append the smaller current node from either list, then attach any leftover tail.
Open the full page for Why, Steps, Example and Key takeaway.
Walk both lists with a carry, creating a new node for (sum % 10) and carrying sum // 10.
Open the full page for Why, Steps, Example and Key takeaway.
Find the middle with slow/fast, reverse the second half, compare pairwise, then optionally restore.
Open the full page for Why, Steps, Example and Key takeaway.
Two pointers walk both lists and switch to the other head on null
Open the full page for Why, Steps, Example and Key takeaway.
Split at the middle, reverse the second half, then weave nodes from the two halves.
Open the full page for Why, Steps, Example and Key takeaway.
The diameter is the max of left_height + right_height over every node (in edges).
Open the full page for Why, Steps, Example and Key takeaway.
Recurse: if the current node is p or q, return it
Open the full page for Why, Steps, Example and Key takeaway.
DFS subtracting the node value, succeeding when you hit a leaf and remaining target is zero.
Open the full page for Why, Steps, Example and Key takeaway.
A bottom-up DFS returns height or a sentinel if any subtree differs by more than one.
Open the full page for Why, Steps, Example and Key takeaway.
Level-order BFS and take the last node of each level, or DFS root-right-left and record the first node seen at each depth.
Open the full page for Why, Steps, Example and Key takeaway.