• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
December 28, 2023 |240 Views
SDE Sheet - Smallest window in a string containing all the characters of another string
  Share   Like
Description
Discussion

This video is part of Strings section under GFG SDE Sheet.

In this video, we are given, two strings S and P. Find the smallest window in the string S consisting of all the characters(including duplicates) of the string P.  Return "-1" in case there is no such window present. In case there are multiple such windows of same length, return the one with the least starting index.

Note : All characters are in Lowercase alphabets.

Example :

Input:
S = "timetopractice"
P = "toc"
Output: 
toprac

Explanation: "toprac" is the smallest substring in which "toc" can be found.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/find-the-smallest-window-in-a-string-containing-all-characters-of-another-string/
Problem: https://practice.geeksforgeeks.org/problems/smallest-window-in-a-string-containing-all-the-characters-of-another-string-1587115621/1

Read More