Given an integer N and a lowercase string. The string is repeated infinitely. The task is to find the No. of occurrences of a given character x in first N letters.
Input : N = 10 str = "abcac" Output : 4 Explanation: "abcacabcac" is the substring from the infinitely repeated string. In first 10 letters 'a' occurs 4 times. Input: N = 10, str = "aba" Output : 7
1. Find the occurrences of character ‘a’ in the given string.
2. Find the No. of repetitions which are required to find the ‘a’ occurrences.
3. Multiply the single string occurrences to the No. of repetitions.
4. If given n is not the multiple of given string size then we will find the ‘a’ occurrences in the remaining substring.
Below is the implementation of above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Map every character of one string to another such that all occurrences are mapped to the same character
- Replace all occurrences of character X with character Y in given string
- Find the first repeated character in a string
- Find repeated character present first in a string
- Efficiently find first repeated character in a string without using any additional data structure in one traversal
- Print the string by ignoring alternate occurrences of any character
- Remove all occurrences of a character in a string
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Remove all occurrences of a character in a string | Recursive approach
- Count occurrences of a string that can be constructed from another given string
- Repeated Character Whose First Appearance is Leftmost
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Check if all occurrences of a character appear together
- Minimize ASCII values sum after removing all occurrences of one character
- Find the number of occurrences of a character upto preceding position
- Check if a string can be repeated to make another string
- Longest sub string of 0's in a binary string which is repeated K times
- Check if any permutation of string is a K times repeated string
- Check if given string is a substring of string formed by repeated concatenation of z to a
- Count of occurrences of a "1(0+)1" pattern in a string
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.