Commit 6c06400

mo khan <mo.khan@gmail.com>
2020-08-19 22:43:41
Solve daily challenge
1 parent 57fb3f8
Changed files (1)
2020
08
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!'