Given an integer K and a string str of lowercase English characters, the task is to find a string s such that when s is repeated exactly K times, it gives a permutation of S. If no such string exists, print -1.
Input: str = “aabb”, k = 2
“ab” when repeated 2 times gives “abab” which is a permutation of “aabb”
Input: str = “aabb”, k = 3
Approach: An efficient approach is to count the frequency of each character of the given string. If the frequency of any character is not divisible by k then the solution is not possible and print -1. Otherwise, add every character (frequency / k) times to the resultant string and print the generated string in the end.
Below is the implementation of the above approach:
- Longest sub string of 0's in a binary string which is repeated K times
- Number of subsequences as "ab" in a string repeated K times
- Minimum number of times A has to be repeated such that B is a substring of it
- Largest element in the array that is repeated exactly k times
- Check if a string can be repeated to make another string
- Count of times second string can be formed from the characters of first string
- Minimum length of string having all permutation of given string.
- Queries for characters in a repeated string
- Find the first repeated word in a string
- Find the first repeated character in a string
- Find repeated character present first in a string
- Remove Duplicate/Repeated words from String
- Count occurrences of a character in a repeated string
- Smallest length string with repeated replacement of two distinct adjacent
- Minimum steps to delete a string after repeated deletion of palindrome substrings
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.