Skip to content

Commit ab34a41

Browse files
committed
Add 53.. tough one
1 parent 5396e8f commit ab34a41

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/ex/q053.clj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;; https://4clojure.oxal.org/#/problem/053
2+
3+
(ns ex.q053)
4+
5+
(defn ans
6+
"Problem 53, Longest Increasing Sub-Seq"
7+
[coll]
8+
(->> coll
9+
(partition 2 1) ;; create overlapping pairs
10+
(partition-by #(= (inc (first %)) (second %))) ;; partition by increasing pairs
11+
(filter #(= (inc (ffirst %)) (second (first %)))) ;; drop violations
12+
(sort-by count)
13+
last ;; grab longest sequence
14+
(reduce concat)
15+
dedupe)) ;; remove overlapping elements

test/ex/q053_test.clj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
;; https://4clojure.oxal.org/#/problem/053
2+
3+
(ns ex.q053-test
4+
(:require [clojure.test :as t]
5+
[ex.q053 :as sut]))
6+
7+
(t/deftest test-q53
8+
(t/testing "Problem 53, Longest Increasing Sub-Seq"
9+
(t/is (= [0 1 2 3] (sut/ans [1 0 1 2 3 0 4 5])))
10+
(t/is (= [5 6] (sut/ans [5 6 1 3 2 7])))
11+
(t/is (= [3 4 5] (sut/ans [2 3 3 4 5])))
12+
(t/is (= [] (sut/ans [7 6 5 4])))))

0 commit comments

Comments
 (0)