PIXELBANKv9.1.0
Menu

Smallest Window Containing All Features

Problem Statement

In computer vision, feature matching often requires finding the smallest region in an image that contains all required feature types.

Given a string features representing detected features in a scan line, and a string required containing all feature types that must be present, find the length of the smallest contiguous substring of features that contains all characters in required.

If no such window exists, return 0.

Applications

  • Finding minimal bounding regions containing specific objects
  • Video keyframe selection
  • Region-of-interest detection

Constraints

  • 1≤len(features)≤1051 \leq len(features) \leq 10^5
  • 1≤len(required)≤1001 \leq len(required) \leq 100
  • Strings contain uppercase and lowercase English letters

Example:

Input:
features = "ADOBECODEBANC", required = "ABC"
Output:
4
Reasoning:

The minimum window is "BANC" which has length 4 and contains A, B, and C.

🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Smallest Window Containing All Features - Hard | PixelBank