본문 바로가기

min14

1018. Find the smallest integer in the array Given an array of integers your solution should find the smallest integer. For example: Given [34, 15, 88, 2] your solution will return 2 Given [34, -345, -1, 100] your solution will return -345 You can assume, for the purpose of this kata, that the supplied array will not be empty. Solution: # 1 def find_smallest_int(arr): return sorted(arr, reverse=True).pop() # 2 def find_smallest_int(arr): r.. 2022. 10. 18.
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.
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.
Find the unique number There is an array with some numbers. All numbers are equal except for one. Try to find it! find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 It’s guaranteed that array contains at least 3 numbers. The tests contain some very huge arrays, so think about performance. Solution: def find_uniq(arr): n = arr[0] == arr[-1] and arr[0] or arr[1] return [i for i in arr if n != i.. 2022. 8. 8.
SQL Basics: Up and Down Given a table of random numbers as follows: numbers table schema id number1 number2 Your job is to return table with similar structure and headings, where if the sum of a column is odd, the column shows the minimum value for that column, and when the sum is even, it shows the max value. You must use a case statement. output table schema number1 number2 Solution: SELECT CASE WHEN MOD(SUM(number1).. 2022. 6. 21.
SQL Basics: Simple MIN / MAX or this challenge you need to create a simple MIN / MAX statement that will return the Minimum and Maximum ages out of all the people. people table schema id name age select table schema age_min (minimum of ages) age_max (maximum of ages) Solution: SELECT MIN(age) AS age_min, MAX(age) AS age_max FROM people Result: age_min age_max 11 99 2022. 5. 24.