![]() |
VOOZH | about |
Given a string S and an integer K, the task is to find the total number of strings that can be formed by inserting exactly K characters at any position of the string S. Since the answer can be large, print it modulo 109+7.
Examples:
Input: S = "a" K = 1
Output: 51
Explanation:
Since any of the 26 characters can be inserted at before 'a' or after 'a', a total of 52 possible strings can be formed.
But the string "aa" gets formed twice. Hence count of distinct strings possible is 51.
Input: S = "abc" K = 2
Output: 6376
Approach:
The idea is to find the number of strings that contains the str as a subsequence. Follow the steps below to solve the problem:
(total number of strings) - (number of strings that don't contain the input string as a sub-sequence)
Below is the implementation of the above approach:
6376
Time Complexity: O(N), where N is the length of the given string.
Auxiliary Space: O(1)