THN Interview Prep

Problem Mind-Map Template

Use this as the target shape for new problem pages and major rewrites. Some legacy pages still use the older compact mind-map shape; the current repo check validates frontmatter and internal links, while section-shape enforcement is tracked as a future quality improvement.

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.

## Core Basics

- **Opening move:** classify the object (interval, multiset, bitmask, trie node…) and whether the answer lives in enumeration, greedy structure, DP, graph walk, etc.
- **Contracts:** what a valid **partial solution** preserves at each step.
- **Complexity anchors:** brute upper bound + single structural shortcut that defeats it.

## Understanding

- **Why brute hurts:** name repeated work/state explosion succinctly.
- **Why optimal is safe:** invariant, exchange proof, optimal sub-structure—what you’d tell another senior.

## Memory Hooks

- **One chant / rule:** mnemonic, acronym, or operator mantra you reuse under clock pressure.

## Recognition Cues
Bullet list of phrases or signals that route you to this pattern before coding:
- "find pair / triplet that sums to ..."
- "longest / shortest substring with property X"
- "kth largest / smallest"
- ...

## Study Pattern (SDE3+)

- **0–3 min:** verbalize constraints + **two** candidate approaches + **explicit time/space** before typing.
- **Implementation pass:** one-line invariant atop the tight loop + progress metric per iteration.
- **5 min extension:** mutate **one** real-world constraint (stream, immutable input, bounded memory, concurrent readers); describe what fractures.

## Diagram
Early visual sweep before digging into implementations. Minimum one **Mermaid** chart (flow/state/DS sketch). Use **camelCase** node IDs; no spaces inside IDs.

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

## Approaches
- **Brute force**`O(?)` time / `O(?)` space — one-line idea.
- **Better**`O(?)` time / `O(?)` space — one-line idea.
- **Optimal**`O(?)` time / `O(?)` space — one-line idea. **<- defend this in-room.**

## Optimal Solution

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

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

## Walkthrough
Trace the optimal on a small input. Surface invariants/table rows so you can replay without the code.

Input: example here

## Edge Cases
- Empty input
- Single element
- Duplicates
- All same value
- Negative numbers / overflow
- Already sorted / reverse sorted

## Pitfalls
- Off-by-one traps you almost hit cold
- API mismatches (`i != j`, values vs indices, stable ordering requirements)

## Similar Problems (same pattern)
Three links anchoring spaced repetition lanes.

## Variants
Interview twists worth one whiteboard sketch each.

## Mind-Map Tags
`#hashmap #arrays #pair-sum`

Why this shape

  • Validator-ready: fixed headings and Mermaid fences make a future section-shape check straightforward.
  • Cross-linkable: “Similar Problems” feeds graph utilities.
  • Recall-friendly: you always scan Problem → Basics → Recall hooks → cues → rehearsal block → Diagram → code story.

Mark this page when you finish learning it.

Last updated on

Spotted something unclear or wrong on this page?

On this page