Given a sorted list of integers, your job is examine the list and produce an array of strings that represent the ranges in the format of "start->end"
- Assume the input will be a non empty
- The list will always be ordered.
- The list will only contain integers.
Given the input [1,2,3,4,8,9,10,12,13,14]
, your function should
return:
["1->4", "8->10", "12->14"]
Given the input [1,2,3,4,9,10,15]
, your function should return:
["1->4","9->10"]
If you are looking to write some tests here are some example assertions you could implement:
# Testing input with only 1 return value
assert ranges([1, 2]) == ["1->2"]
# Testing input with no return value
assert ranges([1]) == []
# Testing input with multiple return values
assert ranges([1,2,3,4,5,8,9,10]) == ["1->5", "8->10"]
Challenge and solution created by slandau3