dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
87 lines
2.1 KiB
Markdown
87 lines
2.1 KiB
Markdown
---
|
|
id: 698a1a73ade5ac0e19180fa2
|
|
title: "Challenge 199: Sequential Difference"
|
|
challengeType: 29
|
|
dashedName: challenge-199
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given an array of numbers, return a new array containing the value needed to get from each number to the next number.
|
|
|
|
- For the last number, use `0` since there is no next number.
|
|
|
|
For example, given `[1, 2, 4, 7]`, return `[1, 2, 3, 0]`.
|
|
|
|
# --hints--
|
|
|
|
`find_differences([1, 2, 4, 7])` should return `[1, 2, 3, 0]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(find_differences([1, 2, 4, 7]), [1, 2, 3, 0])`)
|
|
}})
|
|
```
|
|
|
|
`find_differences([10, 15, 19, 22, 24, 25])` should return `[5, 4, 3, 2, 1, 0]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(find_differences([10, 15, 19, 22, 24, 25]), [5, 4, 3, 2, 1, 0])`)
|
|
}})
|
|
```
|
|
|
|
`find_differences([25, 20, 16, 13, 11, 10])` should return `[-5, -4, -3, -2, -1, 0]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(find_differences([25, 20, 16, 13, 11, 10]), [-5, -4, -3, -2, -1, 0])`)
|
|
}})
|
|
```
|
|
|
|
`find_differences([0, 1, 2, 2, 3, 3, 4, 5])` should return `[1, 1, 0, 1, 0, 1, 1, 0]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(find_differences([0, 1, 2, 2, 3, 3, 4, 5]), [1, 1, 0, 1, 0, 1, 1, 0])`)
|
|
}})
|
|
```
|
|
|
|
`find_differences([1, 2, 5, 12, 34, -15, -1, 41, 113, -222, -99, -40, 10, -18, -6, -2, -1])` should return `[1, 3, 7, 22, -49, 14, 42, 72, -335, 123, 59, 50, -28, 12, 4, 1, 0]`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(find_differences([1, 2, 5, 12, 34, -15, -1, 41, 113, -222, -99, -40, 10, -18, -6, -2, -1]), [1, 3, 7, 22, -49, 14, 42, 72, -335, 123, 59, 50, -28, 12, 4, 1, 0])`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def find_differences(arr):
|
|
|
|
return arr
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def find_differences(arr):
|
|
result = []
|
|
|
|
for i in range(len(arr)):
|
|
if i == len(arr) - 1:
|
|
result.append(0)
|
|
else:
|
|
result.append(arr[i + 1] - arr[i])
|
|
|
|
return result
|
|
```
|