1. Two Sum
easy10 XPGiven 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
Module 3 · Lesson 1 of 2
Trade memory for time; walk inward from both ends. ~30 min
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.
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
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