Skip to content
RED SAGSkills
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)
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions