Module 11 · Bits, Range Tools and Final Review · Lesson 39 of 40

The pattern map: which tool when?

Turn problem wording into the right data structure or pattern. A cheat sheet, a matching drill and flashcards.

In this lesson · about 20 minutes

  • Match common problem clues to the right pattern
  • Recall the cost of the main operations
  • Follow a simple plan when you meet a new problem

A plan for any new problem

  1. Understand: say the problem in your own words. Try a tiny example by hand.
  2. Brute force first: what's the simplest correct idea, even if slow? What is its Big-O?
  3. Look for clues (table below) to find a faster pattern.
  4. Code it, then test small cases: empty input, one item, all the same, already sorted.
  5. State the cost: time and space.

Clue → pattern

If the problem says…Think of…
"Have I seen it?", count things, pair that adds to a targetDict / set (hashing)
Sorted list, find a pair, palindrome, in placeTwo pointers
Subarray / substring, longest / shortest, "k in a row"Sliding window
Many range-sum questionsPrefix sums
Sorted data, or "smallest x that works"Binary search
Brackets, undo, "next greater"Stack / monotonic stack
Process in arrival order, levels, fewest stepsQueue / BFS
Hierarchy, parent and childrenTree + recursion (DFS)
"k largest", "k smallest", always the best next itemHeap
Network, map, connections, dependenciesGraph: BFS, DFS, Dijkstra, topological sort
Groups that mergeUnion-find
Prefixes of words, autocompleteTrie
All combinations / arrangementsBacktracking
Number of ways, min cost, max value with overlapping choicesDynamic programming
Intervals, schedules, "always take the best now" (proven)Greedy (often after sorting)
Pairs cancel out, powers of two, small setsBit manipulation

Sorting drill

Pick the pattern

Each problem below has a clue. Put it under the pattern that fits best.

  • Find the first word that appears twice in a book
  • Longest stretch of a string with no repeated letter
  • Check if every ( has a matching )
  • Fewest moves for a knight to reach a square
  • Number of ways to make 50 cents from coins
  • Two numbers in a sorted list that add up to 100
  • Group words that are anagrams of each other
  • Can I get from city A to city B at all?
  • Serve customers in the order they arrived
  • Most money from houses, no two neighbours

0 of 10 sorted

Flashcards

Costs to remember

0 of 14 known

Say the Big-O out loud before flipping.

14 left in the deck

Check your understanding0 of 2 correct

Question 1

1.'Find the k most frequent words.' Which pair of tools fits best?

Question 2

2.What should you do before trying to find a clever solution?

Quiz score: 0 of 2

Tip: answer every quiz question correctly first.

Noviq Academy is free and for learning. This course follows the topics of a set of DSA study notes, rewritten in Noviq's own words with Python examples. Python runs in your own browser with Pyodide; nothing you type is sent to Noviq.