Loading...
Loading...
Loading...
Given a text s and a text t, find the shortest piece of s that contains every letter of t, including repeated letters. If several pieces have the same shortest length, print the leftmost. Print NONE if no piece works.
Example
Input
ADOBECODEBANC ABC
Output
BANC
The piece "BANC" holds A, B and C and is the shortest.
Try the problem first. Open one hint at a time.
Count what t needs and track how many needed letters are still missing.
When nothing is missing, record the piece, then drop letters from the left while it still holds everything.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor