Match Each Constraint to a Tool

Five patterns in your toolbox, and two problems that each look a lot like something you’ve solved before. Sneaky! These exercises checked whether you’d spot the one changed detail that rules an approach in or out.

Here’s the constraint that decided each problem:

  • Shortest Exact Segment: Signed values mean shrinking a window isn’t safe. Prefix sums with the latest index of each total find the shortest segment ending at each position.
  • Readings Inside Bounds: Sorted input and a required O(log n) time point to two boundary searches, the first position at or above the low bound and the first above the high bound, followed by a subtraction.

Notice that Shortest Exact Segment kept the latest index, while Equal Binary Counts kept the earliest. The goal of the question decides which one you store.

If you started down a familiar path and had to turn back, that’s a useful detour. It shows you which constraint you read past the first time. Take a moment to pick the exercise that took you the most attempts. In two or three sentences, explain what first went wrong and what changed your mind.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.