Skip to content

Instantly share code, notes, and snippets.

@jamtur01
Last active June 23, 2025 14:17
Show Gist options
  • Save jamtur01/3c61c29e2d42fe924ab67c1b3b62f455 to your computer and use it in GitHub Desktop.
Save jamtur01/3c61c29e2d42fe924ab67c1b3b62f455 to your computer and use it in GitHub Desktop.
(defn remove-sirens [sirens]
(let [sorted (sort-by :end sirens)]
(loop [remaining sorted
last-end Integer/MIN_VALUE
keep-count 0]
(if (empty? remaining)
(- (count sirens) keep-count)
(let [{:keys [start end]} (first remaining)]
(if (>= start last-end)
(recur (rest remaining) end (inc keep-count))
(recur (rest remaining) last-end keep-count)))))))
#'user/remove-sirens
user=> (remove-sirens [{:start 1 :end 5}
{:start 3 :end 7}
{:start 6 :end 9}
{:start 8 :end 10}])
2
user=> (remove-sirens [{:start 0 :end 3}
{:start 2 :end 4}
{:start 5 :end 7}
{:start 6 :end 8}
{:start 8 :end 10}])
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment