Skip to content

Classical Variable names

Abstract

Classical variable names used in solutions to the 48 problems of LeetCode Top Easy, with references to the types of problems or algorithms they are used for, and the reason for the name when it's not obvious.

These names are purposely limited to these problems.

Why these names matter:

  • Interviewers expect them.
  • They compress explanation.
  • They make standard patterns recognizable fast.

Generated with love by AI.

Array / two pointers

  • i, j: generic indices
  • left, right: opposite ends, two-pointer scans, palindrome, reverse, partition-ish work
  • read, write: in-place compaction problems (rationale: one pointer reads input, one writes kept values)
  • lo, hi: inclusive bounds in binary search / divide and conquer (rationale: short for low and high)
  • mid: middle index in binary search or recursive split
  • n,m, k: lengths or problem parameters (rationale: conventional short math-style names)

Hash map / set

  • seen: values already encountered
  • counts: frequency table
  • need: complement needed to complete a target, especially Two Sum

Linked list

  • head: first node of the list
  • dummy: fake node before head to simplify edge cases
  • cur: current node while traversing
  • prev: previous node or reversed prefix
  • nxt: saved next node before pointer rewrite
  • slow, fast: tortoise-hare or middle-finding pointers
  • tail: end of an output or merged list

Tree

  • root: top node
  • node: current node in DFS/BFS
  • left, right: child references
  • stack: iterative DFS
  • queue: BFS
  • depth: current tree depth

Dynamic programming / greedy

  • dp: dynamic programming table
  • cur, best: current local answer and global best
  • prev1, prev2: previous states in rolling DP
  • profit, min_price: stock problems
  • acc: accumulator, especially XOR accumulation

Bit manipulation

  • ans: result being built
  • digit: extracted decimal digit
  • count: bit count or loop count

Others

  • rows, cols, boxes: Sudoku constraint buckets