Find Longest Substring with k Unique Characters

Given a string you need to print longest possible substring that has exactly k unique characters. If there are more than one substring of longest possible length, return the lexicographically largest one.

Example:

"aabbcc" and k = 1 can produce "aa", "bb" and "cc", therefore "cc" should be returned.

"aabbcc" and k = 2 should return "bbcc".

Contributed by Berkan Teber