Commit 6c06400
Changed files (1)
2020
08
19
2020/08/19/main.rb
@@ -0,0 +1,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!'