master
1def assert_equal(x, y)
2 raise [x, y].inspect unless x == y
3end
4
5class Solution
6 # time: O(n)
7 # space: O(1)
8 def self.run(items)
9 max = nil
10 hit = 0
11
12 for i in items
13 if max.nil?
14 max = i
15 elsif i > max
16 hit += 1
17 end
18
19 max = i
20 return false if hit > 1
21 end
22
23 true
24 end
25end
26
27assert_equal true, Solution.run([13, 4, 7])
28assert_equal false, Solution.run([5,1,3,2,5])
29
30puts 'Yay!'