Pattern Recognition in Python
Chapter 61: Pattern Recognition
4 short lessons, with 3D animations, quizzes and coding tasks.
The lessons
Reading the limits: input size → the speed you need
Python does roughly 10,000,000 simple steps a second, so put the biggest n into each Big-O and keep only the ones that stay under that budget: the limit tells you how fast your solution must be before you choose a technique.
The pattern map: which signals point to which technique
Read the problem for clues (sorted input, "pair", "stretch of items", "fewest moves", "count the ways", the size of n), let each clue vote for the techniques it fits, and try first the one that most clues agree on.
From brute force to the best answer, worked through
Start with a brute force you can trust, find the work it repeats, keep one piece of information that removes the repeat, and check the fast version against the brute force on many small inputs.
Testing your own solution: edge cases and small examples
List the edge cases the limits allow and check each by hand, then compare your solution with a simple brute force on many random small inputs, and when they differ, look at the smallest input that shows it.