Skip to content
Streak:0Loading your progress…Sign in

Module 3 · Lesson 1 of 2

Hash maps & two pointers

Trade memory for time; walk inward from both ends. ~30 min

Lesson notes

The interview loop: (1) restate the problem and ask about edge cases, (2) give the brute force and its Big-O, (3) improve it, (4) code it, (5) test with examples out loud. Most of the score is steps 1, 2 and 5.

Hash map pattern: when you need "have I seen X?" or "where did I see X?", store it in a dict as you go. Turns O(n²) nested loops into O(n).

Two pointers: on sorted data or when comparing ends (palindromes), use left = 0, right = len(xs) - 1 and move them toward each other.

Practice

  1. 1. Two Sum

    easy10 XP

    Given nums and target, return indices [i, j] (i < j) of the two numbers that add up to target. Exactly one answer exists. Aim for O(n).

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor

  2. 2. Valid palindrome

    easy10 XP

    Write is_palindrome(s) — True if s reads the same forwards and backwards considering only alphanumeric characters, case-insensitive. Use two pointers (O(1) extra space).

    Ctrl/⌘ + Enter runs the tests · Esc then Tab leaves the editor