Lexicographically Minimal Subsequence
InterviewTime limit2sMemory limit512 MB
Given a string s and an integer k, output the lexicographically smallest length-k subsequence of s.
- Level
Medium5 of 10
- Topics
- Stack, Greedy, String, Two pointers
- Solved
- No attempts yet
Problem
You are given a string and an integer . Find the lexicographically minimal subsequence of whose length is .
Input
The first line contains a string (). It consists of lowercase Latin letters.
The second line contains an integer (), the length of the resulting subsequence.
Output
Output the lexicographically minimal subsequence of whose length is .
Notes
A string is called a subsequence of string .
A string is lexicographically less than a string if there exists a number such that and . Characters in strings are compared by their ASCII codes.