Company: Deutsche Bank
Difficulty: medium
A Beautiful Sequence! You are given a string s = s1 s2 ... sn of length n , which contains only the letters a and b . Find the lexicographically smallest possible subsequence of s of length k having at least x occurrences of the letter b . A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements without changing the order of the remaining elements. String A is lexicographically smaller than string B if A is shorter than B ( |A| < |B| ) and A is a prefix of B , or if neither of them is a prefix of the other and, at the first position where they differ, the character in A is smaller than the character in B . Note It is guaranteed that an answer always exists. Example Let n be 6, k be 4, x be 2 and s be aababb . The subsequences of s of length 4 that have at least 2 b 's are { aabb, abab, abbb, babb } . The lexicographically smallest among them is aabb , which is the required answer. Function description Complete the solve function provi