All problems
Delta Encoding
Problem
Encode a list of integers as its first element followed by the differences between consecutive elements.
For example [4, 7, 9, 15] becomes [4, 3, 2, 6]. Return an empty list for empty input.
Hint
The first value is kept as the starting point for the differences.
Test cases
case 1
in: [[4,7,9,15]]
expected: [4,3,2,6]
case 2
in: [[5]]
expected: [5]
case 3
in: [[]]
expected: []
case 4
in: [[-3,0,-3]]
expected: [-3,3,-3]
case 5
in: [[10,10,10]]
expected: [10,0,0]
Starter codePython
def delta_encode(nums):
# Your code here
pass5 test cases · run your code against them in the editor