Skip to content
    Algoria

    INTERVIEW PRACTICE · 10 MIN

    Cracking Coding Interviews

    A repeatable method beats memorising answers.

    BYTE explains

    • 1. Restate the problem and ask about edge cases (empty input, duplicates, negatives).
    • 2. Say the brute force and its Big-O, then improve with a pattern: hashing, two pointers, sliding window, BFS/DFS, DP.
    • 3. Code cleanly, then dry-run a small example and state the final time and space complexity.

    Real world: Placement drives and online assessments at product companies.

    Code

    def longest_unique(s):
        seen, left, best = {}, 0, 0
        for i, ch in enumerate(s):
            if seen.get(ch, -1) >= left:
                left = seen[ch] + 1
            seen[ch] = i
            best = max(best, i - left + 1)
        return best
    print(longest_unique("abcabcbb"), longest_unique(""))
    Output ›
    3 0
    Try it in the online compiler →

    Checkpoint quiz

    What should you do first in an interview problem?