Pattern

Circular arrays

Handle an array whose last element wraps back around to the first, turning a linear technique into two or three linear cases.

What it is

A circular array treats index n-1 as adjacent to index 0, so any pattern that normally reasons about "the next element" or "the ends of the array" has to account for wraparound. Interviewers under this label aren't testing a new algorithm — they're testing whether you can take a technique you already know (DP over a line, a monotonic stack, a running max) and correctly adapt it to a circle, usually by splitting the circular case into a small number of linear subcases (break the circle at one point, or solve it with and without wraparound and compare) rather than inventing a fundamentally new approach.

When it applies

Tells in the problem

The classic mistake

Patching the original linear algorithm in place to "handle wraparound" with extra conditionals instead of recognizing that most circular problems decompose cleanly into two or three independent linear subproblems whose results you just compare or combine — for example, running the same linear DP once excluding the first element and once excluding the last, and taking the max of the two, rather than trying to make one pass that is aware of the circle the whole time. Tangled in-place patches are where subtle bugs at the exact wraparound boundary hide. Catch it by first asking "can I turn this circle into two or three straight lines and reuse my linear solution unchanged on each," before reaching for anything more clever.

Questions to start with

All 3 circular arrays questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.