TechPrep

Track 1

Coding patterns

Sixteen core patterns in order, each with Python and C# solutions that are tested, and a lab that steps through the real code.

Most coding questions are one of a small set of patterns wearing a costume. Learn to spot the signals, state the invariant, and code the template cleanly in Python, with C# alongside.

The order matters: each pattern reuses an idea from the one before (hash maps feed prefix sums, BFS feeds topological sort and greedy). Do them in order the first time, then revisit by weakness.

Every Python solution here is executed by the test suite against its listed cases, and every C# solution is compiled and run against the same expected values. If a lesson shows it, it runs.

Arrays and strings

How a coding round is scored, then the four patterns behind most array and string questions: hashing, two pointers, sliding window and prefix sums.

  1. 01How a coding round is scoredThe six moves that turn a correct idea into a hire signal: clarify, example, brute force, improve, code, test.
  2. 02Hash maps and countingTrade memory for time: remember what you have seen so the inner loop becomes a lookup.
  3. 03Two pointersTwo indices that move toward each other (or together) so each step safely discards part of the search.
  4. 04Sliding windowGrow the right edge, shrink the left edge only when the window breaks its rule, and track the best window seen.
  5. 05Prefix sumsPrecompute running totals so any range sum is one subtraction, and pair them with a hash map to count ranges.

Searching and ordering

Binary search (including on the answer), monotonic stacks, interval sweeps and heaps.

  1. 01Binary search, including on the answerHalve a search space whose predicate flips once from false to true, whether the space is an array or a range of possible answers.
  2. 02Monotonic stackKeep a stack whose values only decrease (or increase) so each element finds its next greater or smaller neighbour in one pass.
  3. 03Intervals: sort, then sweepSort by start (or end) so overlaps become adjacent, then sweep once while comparing only with the last interval kept.
  4. 04Heaps and top-KA size-K min-heap keeps the K largest items seen so far; its top is the answer and everything smaller is discarded.

Linked structures, trees and graphs

Fast and slow pointers, tree recursion that returns one fact upward, breadth-first search and union-find.

  1. 01Fast and slow pointersTwo runners at different speeds detect cycles and find midpoints without extra memory.
  2. 02Tree DFS: pass state down, return answers upRecursion on trees where each call returns one fact to its parent and updates one global best on the way.
  3. 03Breadth-first searchExplore in rings of equal distance with a queue; the first time you reach a node is by a shortest path.
  4. 04Union-find (disjoint sets)Track which items are connected under repeated merges, in nearly constant time per operation.

Search spaces and optimisation

Topological sort, backtracking with pruning, dynamic programming and greedy algorithms you can defend.

  1. 01Topological sortOrder the nodes of a dependency graph so every edge points forward, and detect cycles for free.
  2. 02BacktrackingBuild candidates one choice at a time, undo each choice on the way back, and prune branches that cannot succeed.
  3. 03Dynamic programmingDefine the state, write the recurrence, fix the base case and fill the table in an order where every dependency is ready.
  4. 04Greedy, and how to defend itMake the locally best choice when you can prove an exchange argument shows it never hurts.

Sources