{"id":"be0c8111-5e90-4f5d-93f9-e33c2e5fc6e8","name":"Smallest Substring Of A String Containing All Characters Of Another String ","description":"1. You are given two strings s1 and s2 containing lowercase english alphabets.\r\n2. You have to find the smallest substring of s1 that contains all the characters of s2.\r\n3. If no such substring exists, print blank string(\"\").","inputFormat":"Two strings s1 and s2","outputFormat":"A string","constraints":"1 &lt;= length of string s1 and s2 &lt;= 10000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nstring solution(string s1, string s2){\n // write your code here\n}\n\nint main() {\n\t\n\tstring s1, s2;\n\tcin >> s1;\n\tcin >> s2;\n\t\n\tcout << solution(s1, s2);\n}\t\t"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static String solution(String s1, String s2){\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(solution(s1,s2));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"timetopractice\r\ntoc","sampleOutput":"toprac\r\n","questionVideo":"https://www.youtube.com/embed/e1HlptlipB0?end=28","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"7ac3244d-f877-43bc-870d-543d7dc37a57","name":"Smallest Substring Of A String Containing All Characters Of Another String ","slug":"smallest-substring-of-a-string-containing-all-characters-of-another-string","type":1}],"next":{"id":"f0f579da-955a-48be-b519-4e5a8a130254","name":"Smallest Substring Of A String Containing All Characters Of Another String MCQ","type":0,"slug":"smallest-substring-of-a-string-containing-all-characters-of-another-string-mcq"},"prev":{"id":"61011504-f913-4a41-9dfe-568dec18d086","name":"Largest Subarray With Contiguous Elements:","type":3,"slug":"largest-subarray-with-contiguous-elements"}}}

Smallest Substring Of A String Containing All Characters Of Another String

1. You are given two strings s1 and s2 containing lowercase english alphabets. 2. You have to find the smallest substring of s1 that contains all the characters of s2. 3. If no such substring exists, print blank string("").

{"id":"be0c8111-5e90-4f5d-93f9-e33c2e5fc6e8","name":"Smallest Substring Of A String Containing All Characters Of Another String ","description":"1. You are given two strings s1 and s2 containing lowercase english alphabets.\r\n2. You have to find the smallest substring of s1 that contains all the characters of s2.\r\n3. If no such substring exists, print blank string(\"\").","inputFormat":"Two strings s1 and s2","outputFormat":"A string","constraints":"1 &lt;= length of string s1 and s2 &lt;= 10000","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nstring solution(string s1, string s2){\n // write your code here\n}\n\nint main() {\n\t\n\tstring s1, s2;\n\tcin >> s1;\n\tcin >> s2;\n\t\n\tcout << solution(s1, s2);\n}\t\t"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static String solution(String s1, String s2){\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn null;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(solution(s1,s2));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"timetopractice\r\ntoc","sampleOutput":"toprac\r\n","questionVideo":"https://www.youtube.com/embed/e1HlptlipB0?end=28","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"7ac3244d-f877-43bc-870d-543d7dc37a57","name":"Smallest Substring Of A String Containing All Characters Of Another String ","slug":"smallest-substring-of-a-string-containing-all-characters-of-another-string","type":1}],"next":{"id":"f0f579da-955a-48be-b519-4e5a8a130254","name":"Smallest Substring Of A String Containing All Characters Of Another String MCQ","type":0,"slug":"smallest-substring-of-a-string-containing-all-characters-of-another-string-mcq"},"prev":{"id":"61011504-f913-4a41-9dfe-568dec18d086","name":"Largest Subarray With Contiguous Elements:","type":3,"slug":"largest-subarray-with-contiguous-elements"}}}
plane

Editor


Loading...

Smallest Substring Of A String Containing All Characters Of Another String

hard

1. You are given two strings s1 and s2 containing lowercase english alphabets. 2. You have to find the smallest substring of s1 that contains all the characters of s2. 3. If no such substring exists, print blank string("").

Constraints

1 <= length of string s1 and s2 <= 10000

Format

Input

Two strings s1 and s2

Output

A string

Example

Sample Input

timetopractice toc

Sample Output

toprac

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode