Input: S = "aabcbc", K = 3, cost[] = {2, 1, 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}
Output: 4
Explanation:
One way to construct a string of size K(= 3) is:
Form the string "abb" taking two 'b's with a cost of (2*1 = 2), and one 'a' with a cost of (1*2 = 2).
Therefore, the total cost to construct the string "abb" is (2 + 2 = 4), which is the minimum possible.
Input: S = "aaaca", K = 1, cost[] = {2, 1, 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}
Output: 2