{"id":"c4adbcf1-7e89-4cb1-96b0-62345906b405","name":"Count Of Substrings Having At Most K Unique Characters","description":"1. You are given a string(str) and a number K.\r\n2. You have to find the count of substrings of the given string that contains at most K unique characters.","inputFormat":"A string\r\nA number","outputFormat":"A number representing the count of substrings with at most K unique characters.","constraints":"1 &lt;= length of string &lt;= 10^5\r\n1 &lt;= K &lt;= 26","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n \nint solution(string str, int k) {\n\t// write your code here\n}\n\nint main() {\n string str;\n int k;\n cin >> str >> k;\n\tcout << solution(str,k);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str, int k) {\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 String str = scn.next();\r\n int k = scn.nextInt();\r\n\t\tSystem.out.println(solution(str,k));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabcbcdbca\r\n2","sampleOutput":"23\r\n","questionVideo":"https://www.youtube.com/embed/shsYUyF7pEs?end=309","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":"5abf7b51-ef27-4626-8bc8-8290fc366034","name":"Count Of Substrings Having At Most K Unique Characters","slug":"count-of-substrings-having-at-most-k-unique-characters","type":1}],"next":{"id":"1a396ae0-51f0-481d-bf86-6fe09538ba20","name":"Count Of Substrings Having At Most K Unique Characters MCQ","type":0,"slug":"count-of-substrings-having-at-most-k-unique-characters-mcq"},"prev":{"id":"f863c1bb-a3cf-415e-880d-18e83b28fa92","name":"Longest Substring with At Most K Unique Characters","type":3,"slug":"longest-substring-with-at-most-k-unique-characters"}}}

Count Of Substrings Having At Most K Unique Characters

1. You are given a string(str) and a number K. 2. You have to find the count of substrings of the given string that contains at most K unique characters.

{"id":"c4adbcf1-7e89-4cb1-96b0-62345906b405","name":"Count Of Substrings Having At Most K Unique Characters","description":"1. You are given a string(str) and a number K.\r\n2. You have to find the count of substrings of the given string that contains at most K unique characters.","inputFormat":"A string\r\nA number","outputFormat":"A number representing the count of substrings with at most K unique characters.","constraints":"1 &lt;= length of string &lt;= 10^5\r\n1 &lt;= K &lt;= 26","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n \nint solution(string str, int k) {\n\t// write your code here\n}\n\nint main() {\n string str;\n int k;\n cin >> str >> k;\n\tcout << solution(str,k);\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str, int k) {\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 String str = scn.next();\r\n int k = scn.nextInt();\r\n\t\tSystem.out.println(solution(str,k));\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabcbcdbca\r\n2","sampleOutput":"23\r\n","questionVideo":"https://www.youtube.com/embed/shsYUyF7pEs?end=309","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":"5abf7b51-ef27-4626-8bc8-8290fc366034","name":"Count Of Substrings Having At Most K Unique Characters","slug":"count-of-substrings-having-at-most-k-unique-characters","type":1}],"next":{"id":"1a396ae0-51f0-481d-bf86-6fe09538ba20","name":"Count Of Substrings Having At Most K Unique Characters MCQ","type":0,"slug":"count-of-substrings-having-at-most-k-unique-characters-mcq"},"prev":{"id":"f863c1bb-a3cf-415e-880d-18e83b28fa92","name":"Longest Substring with At Most K Unique Characters","type":3,"slug":"longest-substring-with-at-most-k-unique-characters"}}}
plane

Editor


Loading...

Count Of Substrings Having At Most K Unique Characters

easy

1. You are given a string(str) and a number K. 2. You have to find the count of substrings of the given string that contains at most K unique characters.

Constraints

1 <= length of string <= 10^5 1 <= K <= 26

Format

Input

A string A number

Output

A number representing the count of substrings with at most K unique characters.

Example

Sample Input

aabcbcdbca 2

Sample Output

23

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode