Sort 9 Discussions, By:
Please Login in order to post a comment
This is the same problem as in String Reductions under the Recursion subdomain, or am I missing something? Thanks!
Correct ! Same problem ... with easier test cases !
println(scala.io.StdIn.readLine().foldLeft("")((acc:String , x) => if (acc.contains(x)) acc else acc + x))
For simplicity it could had been
(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))))
(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)))
let dup list=
match list with
| -> 
|head :: tail -> List.fold (fun op head -> if List.contains head op then op else head :: op )[head] tail
let result = dup (List.ofSeq str)
let op = System.String.Concat(Array.ofList(result))
printfn "%s" op
This problem is a duplicate of https://www.hackerrank.com/challenges/string-reductions/problem