Given a very large number N in form of string and a number K, the task is to print all the K-digit repeating numbers whose frequency is greater than 1.
Input: str = “123412345123456”, K = 4
1234 – 3
2345 – 2
The 4-digit numbers having frequency greater than 1 is 1234 and 2345.
Input: N = 1432543214325432, K = 5
14325 – 2
32543 – 2
43254 – 2
The 5-digit numbers having frequency greater than 1 is 14325, 32543, and 43254.
Approach: Since the number is given in the form of a string, therefore the idea is to store all the substring of size K in a map with their frequency. Now, while iterating the Map print only those substrings which have a frequency greater than one along with the number of times they appear.
Below is the implementation of the above approach:
1234 - 3 2345 - 2
Time Complexity: O(N*K)
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.
- Print all 3 digit repeating numbers in a very large number
- Recursive sum of digit in n^x, where n and x are very large
- Number of factors of very large number N modulo M where M is any prime number
- GCD of two numbers when one of them can be very large
- Check whether a very large number of the given form is a multiple of 3.
- How to store a very large number of more than 100 digits in C++
- Find (a^b)%m where 'a' is very large
- Find (a^b)%m where 'b' is very large
- Series summation if T(n) is given and n is very large
- Comparing X^Y and Y^X for very large values of X and Y
- Count of N-digit numbers having digit XOR as single digit
- Find Last Digit of a^b for Large Numbers
- Last digit of Product of two Large or Small numbers (a * b)
- Multiply large integers under large modulo
- Count of Numbers in Range where first digit is equal to last digit of the number
- Print all the non-repeating words from the two given sentences
- Print all n-digit numbers whose sum of digits equals to given sum
- Print all n-digit numbers with absolute difference between sum of even and odd digits is 1
- Generate a number such that the frequency of each digit is digit times the frequency in given number
- Count n digit numbers not having a particular digit
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.