This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-05
Channels
- # announcements (2)
- # babashka (9)
- # bangalore-clj (4)
- # beginners (20)
- # calva (5)
- # cider (1)
- # clara (2)
- # clojure (11)
- # clojure-italy (2)
- # clojure-spec (11)
- # clojure-uk (4)
- # clojurescript (34)
- # clojutre (7)
- # code-reviews (5)
- # cursive (3)
- # datascript (7)
- # fulcro (7)
- # graalvm (8)
- # jackdaw (1)
- # malli (1)
- # nrepl (4)
- # off-topic (225)
- # reagent (23)
- # reitit (14)
- # remote-jobs (1)
- # ring-swagger (1)
- # shadow-cljs (19)
- # tools-deps (10)
hey guys, need some help the problem is quite simple:
Given two unsorted arrays team-a and team-b. They may contain duplicates.
For each element in team-b count elements less than or equal to it in array team-a
my solution was:
(defn solution [team-a team-b]
(let [steam-a (sort team-a)
search #(java.util.Collections/binarySearch steam-a %1)
mapper (comp inc search)]
(mapv #(Math/abs (mapper %1)) team-b)))
the problem is , for huge inputs 100K items for team-a and 100K items for team-b array, the solution is taking ~ 150s
the time limit is only 8s, how can I improve the solution ?If (count (distinct team-a))
is small, you can use frequencies and buildup another array with cumulative sums, and make it bit faster.