sum56 0917. Largest pair sum in array Given a sequence of numbers, find the largest pair sum in the sequence. For example [10, 14, 2, 23, 19] --> 42 (= 23 + 19) [99, 2, 2, 23, 19] --> 122 (= 99 + 23) Input sequence contains minimum two elements and every element is an integer. Solution: def largest_pair_sum(numbers): return sum(sorted(numbers)[-2:]) 2022. 9. 17. 0827. Sum Arrays Write a function that takes an array of numbers and returns the sum of the numbers. The numbers can be negative or non-integer. If the array does not contain any numbers then you should return 0. Examples Input: [1, 5.2, 4, 0, -1] Output: 9.2 Input: [] Output: 0 Input: [-2.398] Output: -2.398 Assumptions You can assume that you are only given numbers. You cannot assume the size of the array. You.. 2022. 8. 27. Sum of Minimums! Given a 2D ( nested ) list ( array, vector, .. ) of size m * n, your task is to find the sum of the minimum values in each row. For Example: [ [ 1, 2, 3, 4, 5 ] # minimum value of row is 1 , [ 5, 6, 7, 8, 9 ] # minimum value of row is 5 , [ 20, 21, 34, 56, 100 ] # minimum value of row is 20 ] So the function should return 26 because the sum of the minimums is 1 + 5 + 20 = 26. Note: You will alwa.. 2022. 8. 21. 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. Row Weights Scenario Several people are standing in a row divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1, and so on. Task Given an array of positive integers (the weights of the people), return a new array/tuple of two integers, where the first one is the total weight of team 1, and the second one is the total weight of team 2. Notes Array .. 2022. 8. 16. Playing with digits Some numbers have funny properties. For example: 89 --> 8¹ + 9² = 89 * 1 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51 Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p we want to find a positive integer k, if it exists, such that the sum of the digits of n taken to the successive powers of p is equal.. 2022. 8. 15. 이전 1 2 3 4 5 6 7 ··· 10 다음