Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
String Manipulation Problem
00:00
5 left

String Manipulation Problem

MediumPython

Problem

Lyra Care may need to locate the smallest portion of a member message that contains every character from a required search pattern. Given a text string and a pattern string, return the shortest contiguous substring of text that contains all characters in pattern, including duplicate occurrences.

Character matching is case-sensitive, spaces and punctuation are valid characters, and the returned substring must preserve the original text exactly. If multiple shortest substrings exist, return the one with the smallest starting index. Return an empty string when no valid substring exists.

Formal Specification

Implement min_covering_window(text, pattern).

  • Input: two strings, text and pattern.
  • Output: the shortest contiguous substring of text containing every character in pattern with at least the required frequency.
  • The input strings contain printable ASCII characters.

Constraints

  • 1 <= len(text) <= 100,000
  • 1 <= len(pattern) <= 100,000
  • Both strings contain printable ASCII characters
  • Matching is case-sensitive

Function Signature

def min_covering_window(text, pattern):
Interviewer

Your question is String Manipulation Problem. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.