본문 바로가기

enumerate15

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.
1020. Convert a string to an array Write a function to split a string and convert it into an array of words. Examples (Input ==> Output): "Robin Singh" ==> ["Robin", "Singh"] "I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"] Solution: from typing import List def string_to_array(s: str) -> List[str]: return split(s) def split(s: str, c: str = " ") -> List[str]: list, ci = [], 0 for i.. 2022. 10. 20.
0930. Count of positives, sum of negatives Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array. Example For input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15], you should return [10, -65]. Solution: def sorted_arr(func): def w.. 2022. 9. 30.
Alternate capitalization Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index 0 will be considered even. For example, capitalize("abcdef") = ['AbCdEf', 'aBcDeF']. See test cases for more examples. The input will be a lowercase string with no spaces. Good luck! Solution: def capitalize(s): return [''.join(v.lower() if i%2==1 else v.upper() for i, v i.. 2022. 8. 23.
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.
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.