← 返回 google 的题目列表Largest Number Subsequences of K Digits from Sequence
类型:online_judge
google
Given a sequence S of N digits, find a subsequence of K digits such that the number formed by these K digits (in order) is the largest.
Examples given:
S = "1", K = 1, answer = "1" # Single digit
S = "10", K = 1, answer = "1" # Zero included
S = "0000", K = 2, answer = "00" # All zeros
S = "1000", K = 3, answer = "100" # Leading zeros
More examples:
S = "98765", K = 2, answer = "98"
S = "98765", K = 3, answer = "987"
S = "98765", K = 4, answer = "9876"
S = "19191", K = 2, answer = "91"
S = "19191", K = 3, answer = "991"
S = "19191", K = 4, answer = "9191"
Example
Input
S = "1", K = 1