aboutsummaryrefslogtreecommitdiff
path: root/racket/leetcode/lc-896-monotonic-array.rkt
blob: fa43244b1906255f0fb2ae90c124c317ca3b3a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#lang racket
(define/contract (is-monotonic test-list)
  (-> (listof exact-integer?) boolean?)
  (cond [(empty? (cdr test-list)) #true]
        [((car test-list) . > . (cadr test-list))
         (is-monotonic-direction test-list >=)]
        [((car test-list) . < . (cadr test-list))
         (is-monotonic-direction test-list <=)]
        [else (is-monotonic (cdr test-list))]))

(define/contract (is-monotonic-direction test-list dir)
  (-> (listof exact-integer?) procedure? boolean?)
  (cond [(empty? (cdr test-list)) #true]
        [((car test-list) . dir . (cadr test-list))
         (is-monotonic-direction (cdr test-list) dir)]
        [else #false]))