THN Interview Prep

Problem Mind-Map Template

Every file in topics/<topic>/problems/ MUST follow this exact 12-section shape (including ## Diagram for quick visual scan). The validation pass enforces section presence by heading. Each ## Diagram must contain at least one ```mermaid block (replace the placeholder with a problem-specific flowchart as you refine the note).

Copy the block below verbatim, then fill it in.


# NNN. Problem Title

## At a Glance
- **Topic**: <arrays-hashing | trees | graphs | ...>
- **Pattern**: <Two Pointers | Sliding Window | ...> (link to the matching pattern guide under [Patterns](/dsa/patterns/README))
- **Difficulty**: Easy | Medium | Hard
- **Companies**: Amazon, Google, Meta, ... (top 5)
- **Frequency**: Very High | High | Medium | Low
- **LeetCode**: [NNN](https://leetcode.com/problems/<slug>/)

## Problem (one-liner)
Restate the problem in your own words in <=2 sentences. Include input/output shape.

## Recognition Cues
Bullet list of phrases or signals in the problem statement that scream "use this pattern":
- "find pair / triplet that sums to ..."
- "longest / shortest substring with property X"
- "kth largest / smallest"
- ...

## Diagram
**Place this section early** (right after recognition cues) so the eye catches the pattern before code.

At minimum, one **Mermaid** diagram: algorithm flow, state machine, or data structure. Use **camelCase** node IDs, no spaces in IDs.

```mermaid
flowchart TD
  inputData[Input] --> patternStep[Apply pattern]
  patternStep --> resultOut[Output]

Approaches

  • Brute forceO(?) time / O(?) space — one-line idea.
  • BetterO(?) time / O(?) space — one-line idea.
  • OptimalO(?) time / O(?) space — one-line idea. <- pick this in interview.

Optimal Solution

Go

// idiomatic Go: explicit types, no single-letter vars
func solve(nums []int, target int) []int {
    // ...
}

JavaScript

// idiomatic ES2022+: const/let, no var, descriptive names
function solve(nums, target) {
    // ...
}

Walkthrough

Trace the optimal on a small input. Show state at each step (table or annotated list). Make the invariant explicit.

Input: nums = [2,7,11,15], target = 9

stepindexnumseenaction
102{}store 2 -> 0
217{2:0}9-7=2 in seen -> [0,1]

Edge Cases

  • Empty input
  • Single element
  • Duplicates
  • All same value
  • Negative numbers / overflow
  • Already sorted / reverse sorted

Pitfalls

  • Off-by-one
  • Forgetting i != j
  • Returning values instead of indices
  • Mutating input when not allowed

Similar Problems (same pattern)

Variants

  • "Sum closest to target" -> sort + two pointers, track min diff.
  • "Count pairs" -> hashmap with counter.
  • "Streaming input" -> hashmap on running window.

Mind-Map Tags

#hashmap #arrays #pair-sum #lookup-trick


---

## Why this rigid shape

- **Codex-validatable**: a script checks the 12 H2 headings exist on every file, and warns if a ` ```mermaid ` block is missing.
- **Cross-linkable**: similar-problems map can be auto-generated from the "Similar Problems" section.
- **Recall-friendly**: identical layout means you scan in the same place every time.

Last updated on

Spotted something unclear or wrong on this page?

On this page