LESSON 04 / 04

A Method for Any Problem (UMPIRE)

A calm, repeatable six-step method — Understand, Match, Plan, Implement, Review, Evaluate — that works on problems you have never seen.

🎓Easylevel
⏱️35 minto finish
✏️2activities

📂 Big O & Problem Solving🏷️ Interview skills

🎯 By the end of this lesson you can…

  • Apply the six UMPIRE steps
  • Ask clarifying questions and list edge cases
  • Move from brute force to an optimised solution

UMPIRE

  1. 1Understandrestate the problem, ask questions, write 2–3 examples including edge cases
  2. 2Matchwhich pattern does it look like? (hashing, two pointers, BFS…)
  3. 3Plandescribe the steps in plain words or pseudocode
  4. 4Implementwrite clean code with good names
  5. 5Reviewtrace your code with an example, line by line
  6. 6Evaluatestate time and space complexity; can it be better?

Walkthrough: “Find the first letter that doesn’t repeat”

Understand. Input: a string like "swiss". Output: the first character that appears once ("w"), or "" if none. Questions: uppercase? empty string? → assume lowercase, return "".

Match. Counting how often things appear → hash map.

Plan. Pass 1: count every letter. Pass 2: return the first letter whose count is 1.

first-unique.pseudo
1BEGIN2    SET TEXT = "swiss"3    SET COUNTS = {}4    FOR EACH C IN TEXT5        IF CONTAINS(COUNTS, C) THEN6            SET COUNTS[C] = COUNTS[C] + 17        ELSE8            SET COUNTS[C] = 19        END IF10    END FOR11    SET ANSWER = ""12    FOR EACH C IN TEXT13        IF COUNTS[C] = 1 AND ANSWER = "" THEN14            SET ANSWER = C15        END IF16    END FOR17    DISPLAY ANSWER18END

Implement.

First unique character

1function firstUnique(s) {2  const counts = new Map();3  for (const c of s) counts.set(c, (counts.get(c) || 0) + 1);4  for (const c of s) if (counts.get(c) === 1) return c;5  return "";6}7console.log(firstUnique("swiss"));

✨ The logic didn’t change. Only the syntax changed.

Review. “swiss”: counts s:3, w:1, i:1 → first with count 1 is “w” ✔. Edge case "aa" → "" ✔.

Evaluate. Two passes → O(n) time. The map holds at most 26 letters → O(1) extra space for lowercase letters.

💡 Concept check
What should you do FIRST when you hear a new interview problem?
🛠️ First unique character

Implement it yourself: return the first character that appears exactly once, or an empty string.

📌 Key takeaways

  • Never start coding before you understand the problem and have examples.
  • Say the brute force first, then improve it.
  • Always test with an edge case before saying "done".

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.