Smallest Window Containing All

Talk it through with a coach who asks guiding questions and gives hints until you reach the answer. Pass to mark the challenge as completed.

The problem

  • hard
  • Pro

Given a long text and a short pattern, find the shortest stretch of the text that contains every character of the pattern, including repeats. For example, if the pattern has two a's, the stretch needs at least two a's. Explain your approach and its cost.

Talk this problem through with an AI coach

This is a Pro challenge. Sign in with Google, then upgrade to start a voice session.

Start free →