You are viewing a single comment's thread. Return to all comments →
Can someone give any hint about test 5?
Tried about 5-6 different variants on clojure. And all terminated by timeout.
Don't create too many intermedite string objects. That is the key. The below solution passes all test cases.
(require '[clojure.string :as str])
(defn indices 
(reductions + 1 (cycle [-1 3])))
(defn permute [s]
(let [n (count s)]
(str/join (map #(nth s %) (take n (indices))))))
(let [input (slurp *in*)
[q & strings] (str/split-lines input)]
(doseq [s strings]
(println (permute s))))