Category

Arrays

An array keeps values in index order, so a known index is a direct read. These articles start from that layout, then explain the scans the lessons build on it: two pointers moving inward, a window that grows and shrinks, a prefix sum, and rotating values without losing their order.

  1. How Arrays Support Fast Indexing

    An array gives each element an integer index, so reading a known position is O(1). Dense arrays scan efficiently, while insertions near the front are O(n) because later elements must move.

  2. How Do You Rotate an Array Left?

    A left rotation moves a prefix to the back without changing relative order. Reducing the step count modulo the length avoids repeated shifts and gives an O(n) solution.

  3. What Is the Two-Pointer Technique on a Sorted Array?

    Two pointers maintain two meaningful indexes and move them according to an invariant. For sorted squares, the largest remaining square must be at one of the two ends.

  4. What Is a Sliding Window?

    A sliding window represents one contiguous range with two boundaries. Reusing the previous range turns fixed-width sums into O(n), while variable windows require a condition that moves boundaries monotonically.

  5. How Prefix Sums Answer Range Queries

    A prefix-sum array precomputes totals from the start. After O(n) preprocessing, any half-open range sum can be answered in O(1) by subtracting two prefixes.

  6. How Do Inward Pointers Move? Ends, Palindromes, and Pair Sums

    Inward pointers start at the two ends of an array and move toward the middle. A rule decides which end moves, and each step drops one index.

  7. What Is a Variable Window? Growing and Shrinking a Subarray

    A variable window grows on the right and shrinks on the left. With zeros and positive numbers, the left edge only moves forward, so the scan stays linear.

  8. Why Does an Array Middle Edit Shift Elements?

    A contiguous array keeps indexes adjacent, so insertion or deletion in the middle must copy the tail while direct indexed access remains constant-time.