summaryrefslogtreecommitdiff
path: root/2020/08/19/main.rb
blob: ece33aa5b0f4bae27d6839f06964516c23a91e99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def assert_equal(x, y)
  raise [x, y].inspect unless x == y
end

class Solution
  # time: O(n)
  # space: O(1)
  def self.run(items)
    max = nil
    hit = 0

    for i in items
      if max.nil?
        max = i
      elsif i > max
        hit += 1
      end

      max = i
      return false if hit > 1
    end

    true
  end
end

assert_equal true, Solution.run([13, 4, 7])
assert_equal false, Solution.run([5,1,3,2,5])

puts 'Yay!'