`{"id":"2e9044e5-a93b-4f28-bdca-2d1dadd6147b","name":"Smallest Substring Of A String Containing All Unique Characters Of Itself","description":"1. You are given a string str.\r\n2. You have to find the smallest window length that contains all the unique characters of the given string.","inputFormat":"A string","outputFormat":"A number representing smallest window length that contains all unique characters of the given string.","constraints":"1 &lt;= length of string &lt;= 10^6","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(string str){\n // write your code here\n}\n\nint main(){\n\tstring str;\n\tcin>>str;\n\tcout <<solution(str);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str){\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"aabcbcdbca","sampleOutput":"4\r\n","questionVideo":"https://www.youtube.com/embed/pbUNTDdxomI?end=20","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":"100573ee-2316-45ac-87c2-b5e7b375050d","name":"Smallest Substring Of A String Containing All Unique Characters Of Itself","slug":"smallest-substring-of-a-string-containing-all-unique-characters-of-itself","type":1}],"next":{"id":"04ea8d63-efc9-4d3b-b0e2-96d3ec8d9adf","name":"Smallest Substring Of A String Containing All Unique Characters Of Itself MCQ","type":0,"slug":"smallest-substring-of-a-string-containing-all-unique-characters-of-itself-mcq"},"prev":{"id":"5145b7b0-3872-49d9-9078-58f656b80165","name":"Smallest Substring Of A String Containing All Characters Of Another String","type":3,"slug":"smallest-substring-of-a-string-containing-all-characters-of-another-string"}}}`

# Smallest Substring Of A String Containing All Unique Characters Of Itself

1. You are given a string str. 2. You have to find the smallest window length that contains all the unique characters of the given string.

`{"id":"2e9044e5-a93b-4f28-bdca-2d1dadd6147b","name":"Smallest Substring Of A String Containing All Unique Characters Of Itself","description":"1. You are given a string str.\r\n2. You have to find the smallest window length that contains all the unique characters of the given string.","inputFormat":"A string","outputFormat":"A number representing smallest window length that contains all unique characters of the given string.","constraints":"1 &lt;= length of string &lt;= 10^6","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nint solution(string str){\n // write your code here\n}\n\nint main(){\n\tstring str;\n\tcin>>str;\n\tcout <<solution(str);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str){\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"aabcbcdbca","sampleOutput":"4\r\n","questionVideo":"https://www.youtube.com/embed/pbUNTDdxomI?end=20","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":"100573ee-2316-45ac-87c2-b5e7b375050d","name":"Smallest Substring Of A String Containing All Unique Characters Of Itself","slug":"smallest-substring-of-a-string-containing-all-unique-characters-of-itself","type":1}],"next":{"id":"04ea8d63-efc9-4d3b-b0e2-96d3ec8d9adf","name":"Smallest Substring Of A String Containing All Unique Characters Of Itself MCQ","type":0,"slug":"smallest-substring-of-a-string-containing-all-unique-characters-of-itself-mcq"},"prev":{"id":"5145b7b0-3872-49d9-9078-58f656b80165","name":"Smallest Substring Of A String Containing All Characters Of Another String","type":3,"slug":"smallest-substring-of-a-string-containing-all-characters-of-another-string"}}}`

Editor

# Smallest Substring Of A String Containing All Unique Characters Of Itself

medium

1. You are given a string str. 2. You have to find the smallest window length that contains all the unique characters of the given string.

## Constraints

1 <= length of string <= 10^6

## Format

A string

### Output

A number representing smallest window length that contains all unique characters of the given string.

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}aabcbcdbca`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4 ```

Question Video

Discussions

Show Discussion

Related Resources