We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Functional Programming
  3. Ad Hoc
  4. Remove Duplicates
  5. Discussions

Remove Duplicates

Problem
Submissions
Leaderboard
Discussions

Sort 11 Discussions, By:

votes

Please Login in order to post a comment

  • dmytrolypai 5 years ago+ 0 comments

    This is the same problem as in String Reductions under the Recursion subdomain, or am I missing something? Thanks!

    9|
    Permalink
  • dhirajhimani 3 years ago+ 0 comments
    println(scala.io.StdIn.readLine().foldLeft("")((acc:String , x) => if (acc.contains(x)) acc else acc + x))
    
    1|
    Permalink
  • xdavidliu 4 days ago+ 0 comments

    Haskell

    import qualified Data.Set as S
    
    remDupe "" _ = ""
    remDupe (c:cs) seen = 
      if S.member c seen
      then remDupe cs seen
      else c:(remDupe cs $ S.insert c seen)
    
    main = do cs <- getLine
              putStr $ remDupe cs S.empty
    
    0|
    Permalink
  • lvbarbosa 4 months ago+ 0 comments

    Haskel (n^2)

    import           Data.List (nub)
    
    main :: IO ()
    main = interact nub
    
    0|
    Permalink
  • marianomacchi 2 years ago+ 0 comments

    Clojure

    Using recursion:

    (defn remove-duplicates [input-string seen]
            (if (not (empty? input-string))
                (let [current-char (first input-string)]
                    (if (.contains seen (str current-char)) 
                        (remove-duplicates (rest input-string) seen)
                        (remove-duplicates (rest input-string) (str seen current-char))))
                seen))
    
    (println (remove-duplicates (read-line) ""))
    

    Note: from clojure 1.9, contains can be replaced with clojure.string/includes?

    Using built-in functions:

    (println (apply str (distinct (read-line)))
    
    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature