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
1.4 KiB
1.4 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6821ebee237de8297eaee796 | Challenge 20: Array Duplicates | 29 | challenge-20 |
--description--
Given an array of integers, return an array of integers that appear more than once in the initial array, sorted in ascending order. If no values appear more than once, return an empty array.
- Only include one instance of each value in the returned array.
--hints--
find_duplicates([1, 2, 3, 4, 5]) should return [].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_duplicates([1, 2, 3, 4, 5]), [])`)
}})
find_duplicates([1, 2, 3, 4, 1, 2]) should return [1, 2].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_duplicates([1, 2, 3, 4, 1, 2]), [1, 2])`)
}})
find_duplicates([2, 34, 0, 1, -6, 23, 5, 3, 2, 5, 67, -6, 23, 2, 43, 2, 12, 0, 2, 4, 4]) should return [-6, 0, 2, 4, 5, 23].
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_duplicates([2, 34, 0, 1, -6, 23, 5, 3, 2, 5, 67, -6, 23, 2, 43, 2, 12, 0, 2, 4, 4]), [-6, 0, 2, 4, 5, 23])`)
}})
--seed--
--seed-contents--
def find_duplicates(arr):
return arr
--solutions--
def find_duplicates(arr):
seen = set()
duplicates = set()
for num in arr:
if num in seen:
duplicates.add(num)
else:
seen.add(num)
return sorted(duplicates)