State checklist
Before writing the loop, ask what has been seen, what the next step needs, and whether the answer depends on a prior value or index. Store only that information.
Arrays and Hashing
Choose the smallest useful state while scanning an array from left to right.
Practice
0/2 solved
Notes
Array problems are often state-tracking problems. At each position, decide what the scan has already learned and what the next position will need.
Use a set for seen values, a frequency map for counts, or a map for last positions.
Maintain running values such as a prefix sum, minimum, maximum, count, or best answer.
Preserve order for subarrays and prefix-based logic; a subarray must remain contiguous.
Before writing the loop, ask what has been seen, what the next step needs, and whether the answer depends on a prior value or index. Store only that information.
Sorting can simplify a minimum or maximum problem when original order is irrelevant. For subsequences, subarrays, and prefix sums, keep the order or store enough information to reconstruct it.