Basic Framework
Implementleetcoderesearch-card

LeetCode Card 259 — Tree DFS / Implement

Tree DFS — BASIC step map

Pattern signal

This pattern usually appears when the prompt involves recursive subtree questions about depth, identity, path sums, construction, or transformation. Invert Binary Tree, Maximum Depth, Same Tree, Subtree of Another Tree, and Binary Tree Maximum Path Sum belong here.

Patterns are shortcuts, not substitutes for reasoning.

What Implement means here

In BASIC, the Implement step is where you write the code in the same order as the chosen skeleton so the logic stays stable. For Tree DFS, that matters because the pattern only becomes useful once the candidate is explicit about what is being tracked, reduced, or preserved.

Interview move

A strong move is to transcribe the plan instead of improvising. In this pattern family, say out loud what representation makes the problem easier: the map entry, the pointer invariant, the recursion contract, the queue contents, or the DP state. That keeps the implementation attached to a reason.

Common miss

The miss is failing to define the recursion contract: what each call returns and what side effects it performs. BASIC reduces that risk because the stage sequence forces you to earn the implementation instead of jumping straight into it.

BASIC prompt

“Given that this looks like Tree DFS, what is the simplest way to write the code in the same order as the chosen skeleton so the logic stays stable?”

Execution discipline
The best implementations are boring. They follow the structure step by step, without clever detours. If you find yourself innovating during implementation, that's usually a sign the Structure step was incomplete. Go back and fill the gap rather than improvising forward.

References

S10 S12 S13

Related in LeetCode

January 14, 2023

BASIC for LeetCode: the most reliable way to think through coding interviews

LeetCode is often treated like a memory contest.

April 27, 2024

LeetCode Card 206 — Arrays and Hashing / Breakdown

This pattern usually appears when the prompt involves lookup, duplicate detection, counting, grouping, or direct indexbased traversal. Problems like Two Sum, Contains Duplicate,…

April 29, 2024

LeetCode Card 207 — Arrays and Hashing / Assess

This pattern usually appears when the prompt involves lookup, duplicate detection, counting, grouping, or direct indexbased traversal. Problems like Two Sum, Contains Duplicate,…