diff --git a/introductory.go b/introductory.go index ab0688e..e8e4f63 100644 --- a/introductory.go +++ b/introductory.go @@ -45,3 +45,36 @@ func MissingNumber(n int, numbers []int) int { return -3 } + +func Repetitions(dna string) int { + curC := ' ' + maxL := 0 + curL := 0 + + for _, c := range dna { + if c == curC { + curL += 1 + } else { + curC = c + curL = 1 + } + + if curL > maxL { + maxL = curL + } + } + + return maxL +} + +func IncreasingArray(size int, arr []int) int { + moves := 0 + + for i := 0; i < len(arr)-1; i++ { + if arr[i] > arr[i+1] { + moves += arr[i] - arr[i+1] + } + } + + return moves +} diff --git a/introductory_test.go b/introductory_test.go index a20c4fa..e648f48 100644 --- a/introductory_test.go +++ b/introductory_test.go @@ -14,3 +14,15 @@ func TestMissingNumber(t *testing.T) { assert.Equal(t, 4, MissingNumber(5, []int{2, 3, 1, 5})) assert.Equal(t, 7, MissingNumber(9, []int{2, 3, 1, 5, 4, 6, 9, 8})) } + +func TestRepetitions(t *testing.T) { + assert.Equal(t, 0, Repetitions("")) + assert.Equal(t, 3, Repetitions("ATTCGGGA")) + assert.Equal(t, 4, Repetitions("AGGTTCGGGGA")) +} + +func TestIncreasingArray(t *testing.T) { + assert.Equal(t, 0, IncreasingArray(5, []int{})) + assert.Equal(t, 0, IncreasingArray(5, []int{3})) + assert.Equal(t, 5, IncreasingArray(5, []int{3, 2, 5, 1, 7})) +}