Questions that ask you to inspect, validate, count or summarize an entire array.
- every element matters
- one pass is possible
- the answer can be updated while scanning
After index i, the stored state correctly describes the processed prefix from 0 through i.
Usually O(n) time. Typical auxiliary space: Usually O(1).
JAVA STARTING POINT
A template to adapt, not memorize.
for (int index = 0; index < values.length; index++) {
int value = values[index];
// Update the answer using value.
}Common mistakes
- Starting from an unsafe default value
- Skipping the first or last index
- Forgetting empty-input behavior
PUBLISHED / 06
Learn in this order.
Available articles always appear before the publishing plan.
Arrays Learning Path
Learn array traversal, two pointers, in place updates, hashing, and prefix techniques through Java examples.
Read article →Array Fundamentals in Java
Build a clear mental model for array indexing, traversal, updates, and common problem solving patterns.
Read article →Find the Largest Element in an Array
Learn to keep a running maximum, reason about each comparison, and trace a one-pass Java solution.
Read article →Find the Second Largest Element in an Array
Track the two largest distinct values in one pass without sorting the array.
Read article →Check Whether an Array Is Sorted
Verify nondecreasing order by checking each adjacent pair once.
Read article →Find the Missing Number
Find the missing value from 1 through n using XOR without overflow.
Read article →PLANNED PRACTICE
What comes after the published lessons.
- Count elements matching a conditionPlanned, not yet published
- Maximum consecutive onesPlanned, not yet published
