hard20 pts · first answer countshash-mapsliding-windowdebugging
Bug in an at-most-two-distinct window
This window should allow at most 2 distinct characters, but it shrinks forever once a third one appears. What is missing?
cnt.set(ch, (cnt.get(ch) ?? 0) + 1)
while (cnt.size > 2) {
const out = s[left++]
cnt.set(out, cnt.get(out) - 1)
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- What a sliding window coversBackend Developer
- Updating a fixed-size window sumBackend Developer
- Best three-day sales windowBackend Developer
- Sliding window time complexityBackend Developer
- Shape of a variable-size window loopBackend Developer
- Length of a windowBackend Developer