blob: 60436b10ea82cc4ebd6bd467c0bfe44afa174cc4 (
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
31
32
33
|
# frozen_string_literal: true
def assert_equal(x, y)
raise [x, y].inspect unless x == y
end
class Solution
def self.run(string)
max, current = 0, 0
0.upto(string.size - 1) do |i|
if string[i] == string[i-1]
max = maximum(max, current)
current = 0
end
current += 1
end
maximum(max, current)
end
def self.maximum(x, y)
x > y ? x : y
end
end
assert_equal Solution.run('abrkaabcdefghijjxxx'), 10
assert_equal Solution.run('aaabcd'), 4
puts "YAY!"
# step 1. understand the problem
# step 2. pick a solution
# step 3. write the solution
|