Skip to content
← Back to the archive

11 September 2026 · Advanced track

Badge Scanner Duplicate Window

Advanced Lists

Detect whether the same badge was scanned twice within a limited number of scans.

A building's badge scanner logs the badge id used at every entry, in order. You are also given a maximum gap, k. Look for any two scans of the same badge id whose positions in the log are at most k scans apart. Return true if such a pair of scans exists anywhere in the log, and false otherwise. A gap of k means the two positions can differ by k or fewer - for example, with k equal to 1, the same badge scanned twice in a row counts, but the same badge scanned with one other scan in between does not.

Constraints

  • badge_ids has between 1 and 1000 entries
  • each badge id has between 1 and 20 characters
  • k is a whole number between 0 and 1000

Function signature

def has_duplicate_within_window(badge_ids, k):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.