InterviewLegend

Two Pointers & Sliding Window

Alex Chen32 min readUpdated 835 real interview reports

A lot of array and string problems ship with an obvious answer that reads every pair: two loops, one nested inside the other, quadratic time. Two pointers and sliding window are the two habits that fold that double loop into a single walk across the data. Both keep a couple of indices moving forward and lean on one promise: whatever ground a pointer has already passed, it never has to revisit. That promise is what buys you the drop from O(n squared) to O(n). In a Walmart loop, that drop is the bar.

The two techniques split by how the indices move. Two pointers can converge from opposite ends toward the middle, or run in the same direction at different speeds. A sliding window is a specialized same-direction pair where the gap between the pointers is what you care about. It is a contiguous stretch you widen and narrow to hunt for the best or smallest run that obeys some rule. Name which movement the problem wants, and the skeleton writes itself. The wrinkle the problem wraps around that skeleton is where your interview minutes should go.

The Walmart angle
Walmart's coding bar sits reliably in the medium band, and this cluster is where a nested-loop solution quietly costs you. The editor runs your code against hidden tests, so a brute-force pass that is correct still finishes second to a linear one that reads the same. What the interviewer wants to hear first is the O(n squared) baseline, then the reason two pointers or a window beats it, then the time and space, all before you type. The string-window problems come back often on both the US and India tracks. They arrive in retail terms: the longest run of a feed with no repeated event, the smallest slice of an order log that covers a required set of items. Say the plan out loud, then let the pointers do the work. The narration is half the grade.
What's inside
  • 4 problems, worked step by step
  • about 32 min

Premium lessonWalmart interview guide

These took digging.

What candidates walked out with, from 20,000+ reports, forum threads behind logins and write-ups in Chinese. Then solved step by step.

100 companies. Checked every month.

Unlock all 100 companies

$49 a year · less than $1 a week · Cancel anytime

Had your Walmart interview?Tell us what they asked. Reviewed before it goes in, never with your name.
Walmart interview guide

Know what Walmart asks before you walk in.

24 coding · 4 system design · 20 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.