본문 바로가기

ZIP7

0118. Ordered Count of Characters Count the number of occurrences of each character and return it as a (list of tuples) in order of appearance. For empty output return (an empty list). Consult the solution set-up for the exact data structure implementation depending on your language. Example: ordered_count("abracadabra") == [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] Solution: def ordered_count(inp): from collections impo.. 2023. 1. 18.
1211. Maximum Product Task Given an array of integers , Find the maximum product obtained from multiplying 2 adjacent numbers in the array. Notes Array/list size is at least 2. Array/list numbers could be a mixture of positives, negatives also zeroes . Input >> Output Examples adjacentElementsProduct([1, 2, 3]); ==> return 6 Explanation: The maximum product obtained from multiplying 2 * 3 = 6, and they're adjacent nu.. 2022. 12. 11.
0923. Sum of differences in array Your task is to sum the differences between consecutive pairs in the array in descending order. Example [2, 1, 10] --> 9 In descending order: [10, 2, 1] Sum: (10 - 2) + (2 - 1) = 8 + 1 = 9 If the array is empty or the array has only one element the result should be 0 (Nothing in Haskell, None in Rust). Solution: def sort(func): def wrapper(arr): return func(sorted(arr, reverse=True)) return wrap.. 2022. 9. 23.
Sort the odd Task You will be given an array of numbers. You have to sort the odd numbers in ascending order while leaving the even numbers at their original positions. Examples [7, 1] => [1, 7] [5, 8, 6, 3, 4] => [3, 8, 6, 5, 4] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] => [1, 8, 3, 6, 5, 4, 7, 2, 9, 0] Solution: def sort_array(source_array): a,b = [],[] for i, v in enumerate(source_array): if v%2==1: a.append(v) b.ap.. 2022. 8. 2.
Check the exam The first input array is the key to the correct answers to an exam, like ["a", "a", "b", "d"]. The second one contains a student's submitted answers. The two arrays are not empty and are the same length. Return the score for this array of answers, giving +4 for each correct answer, -1 for each incorrect answer, and +0 for each blank answer, represented as an empty string (in C the space characte.. 2022. 7. 24.
Sort array by string length Description: Write a function that takes an array of strings as an argument and returns a sorted array containing the same strings, ordered from shortest to longest. For example, if this array were passed as an argument: ["Telescopes", "Glasses", "Eyes", "Monocles"] Your function would return the following array: ["Eyes", "Glasses", "Monocles", "Telescopes"] All of the strings in the array passe.. 2022. 4. 29.