Given two strings A and B. Your task is to remove a few characters from string A so that the number of substrings of A that match string B is exactly K. Find the least number of characters that must be removed from string A so that the mentioned condition is satisfied.
Note: Both strings A and B contain lowercase English letters, that is, a-z only.

Function description
Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the answer: