Smallest K-Length Subsequence With Occurrences of a Letter — LeetCode 2030 Python Solution
- Problem
- #2030
- Pattern
- Stack
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given a string s, an integer k, a letter letter, and an integer repetition. Return the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times.
Example
- Input
- s = "leet", k = 3, letter = "e", repetition = 1
- Output
- "eet"
- Explanation
- There are four subsequences of length 3 that have the letter 'e' appear at least 1 time:
Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) |
| Space | O(1) to O(n) auxiliary |
Pattern: Stack
When the most recent unresolved thing is the one that matters, use a stack. LeetCode 2030. Smallest K-Length Subsequence With Occurrences of a Letter is filed here because LeetCode tags it Stack, which is the vocabulary this hub collects.
The stack guide has the Python template for the pattern and the 194 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 2030. Smallest K-Length Subsequence With Occurrences of a Letter?
- LeetCode 2030. Smallest K-Length Subsequence With Occurrences of a Letter is rated Hard on LeetCode.
- What topics does LeetCode 2030. Smallest K-Length Subsequence With Occurrences of a Letter cover?
- LeetCode 2030. Smallest K-Length Subsequence With Occurrences of a Letter is tagged Stack, Greedy, String and Monotonic Stack on LeetCode.