Matching Pairs
Imagine grouping numbers into pairs where both values in each pair must be the same. Write a function divide_array that receives a list of 2n numbers. Return True if all numbers can be split into equal-value pairs. If any number is left without a matching partner, return False.
Примеры
Ввод
[3, 2, 3, 2, 2, 2]Вывод
TrueВвод
[1, 2, 3, 4]Вывод
FalseВвод
[1, 1]Вывод
TrueНужно реализовать
def divide_array(nums: list[int]) -> bool:
Теги
arrayhashmapdict
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
[3,2,3,2,2,2]Expected
True2
Input
[1,2,3,4]Expected
False3
Input
[1,1]Expected
True4
Input
[1,1,2,2,3,3]Expected
True5
Input
[1,1,1,2]Expected
False6
Input
[5,5,5,5]Expected
TrueFocus radio
Paused · SomaFM · Fluid