Flatten and sort an array
Challenge: Given a two-dimensional array of integers, return the flattened version of the array with all the integers in the sorted (ascending) order. Example: Given [[3, 2, 1], [4, 6, 5], [], [9, 7, 8]], your function should return [1, 2, 3, 4, 5, 6, 7, 8, 9]. Solution: def flatten_and_sort(array): arr = [] for i in array: arr.extend(i) return sorted(arr) Other Solution: from itertools import c..
2022. 8. 20.
Find the stray number
You are given an odd-length array of integers, in which all of them are the same, except for one single number. Complete the method which accepts such an array, and returns that single different number. The input array will always be valid! (odd-length >= 3) Examples [1, 1, 2] ==> 2 [17, 17, 3, 17, 17, 17, 17] ==> 3 Solution: def stray(arr): import collections return [k for k, v in collections.C..
2022. 8. 19.