Problem:-
Bob is very fond of strings so he is creating a new type of string. Help him in creating his new special string.
You are given a string of length and an integer . Now, you are required to find a string of length at most such that if you add this string number of times () let us say it is , then the frequency of each character in string should be greater than or equal to the frequency of the same character in the string . should cover all the characters of string .
Help Bob in finding the minimum possible value of .
Input format
- The first line contains an integer representing the maximum length of string that Bob can write.
- The second line contains a string representing the given string.
Output format
Print an integer denoting the minimum possible value of .
Constraints
where only contains lowercase letters, that is,
The total number of distinct characters in is always less than or equal to .
Given s = "aaabbc" and n = 4.
Frequency of each character is 'a' = 3, 'b' = 2, and 'c' = 1.
If we take ‘str’ = "aabc" and add this 2 times i.e "aabcaabc" the frequency of each character will be 'a' = 4, 'b' = 2, 'c' = 2. Here the frequency of each character is greater or equal to that of string ‘s’. i.e for 'a' 4 >= 3, 'b' 2 >= 2 and 'c' 2 >= 1.
Hence x= 2.
We can't find any other string 'str' of length n such that x< 2
Code:-
Solution 2 ( C++ language):-
Solution 3 (java language):-
keywords:-
Recommended Post:-
- codechef problems:-
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation
0 Comments