COMP 5481 Programming and problem solving Lab5 Lab 5 (Solution)

$ 24.99
Category:

Description

Problem Description:
Write a program that receive two strings namely “str” and “letters” and finds the minimum window in “str” which will contain all the characters in “letters”. Input string “str” can take alphabets, numbers, spaces, commas and periods. It cannot exceed column 70 (max length of “str”<=70). The second line of the input “letters” will not be greater than the size of string “str”. The search is case-sensitive.

Input:
First line of the input is string “str” which needs to be searched in. Second line of the input takes the string “letters” which need to be searched for.
Output:
The minimum window in “str” which will contain all the characters in “letters”.

Hint:
Naïve approach will be to generate all possible substrings of “str” and then print the smallest substring that contains all the characters from “letters”.
Efficient approach will involve storing occurrences of each character in “letters” present in “str”. Loop through string “str” and increment a counter every time a character from “letters” is found. Once all characters are found, slide the window to find the substring with smallest length.

SR Input Output
1 qploresinazxrhqknhoilerthf
lion nhoil
2 MKWPLNHNNKLASOPQLRHLI
HILL LRHLI
3 1qnkyp098fSkkmnQryS9pkYn0Qd7mksy0fRW0a7Sxzc
Sky07 yS9pkYn0Qd7

Reviews

There are no reviews yet.

Be the first to review “COMP 5481 Programming and problem solving Lab5 Lab 5 (Solution)”

Your email address will not be published. Required fields are marked *