본문 바로가기

Sorted27

Consecutive strings You are given an array(list) strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings taken in the array. Examples: strarr = ["tree", "foling", "trashy", "blue", "abcdef", "uvwxyz"], k = 2 Concatenate the consecutive strings of strarr by 2, we get: treefoling (length 10) concatenation of strarr[0] and strarr[1] folingtrashy (" 12) co.. 2022. 8. 13.
Descending Order Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number. Examples: Input: 42145 Output: 54421 Input: 145263 Output: 654321 Input: 123456789 Output: 987654321 Solution: def descending_order(num): return int("".join(sorted([i for i in str(num)], r.. 2022. 8. 5.
Form The Minimum Task Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates). Notes: Only positive integers will be passed to the function (> 0 ), no negatives or zeros. Input >> Output Examples minValue ({1, 3, 1}) ==> return (13) Explanation: (13) is the minimum number could be formed from {1, 3, 1} , Without duplications minVal.. 2022. 8. 2.
Anagram Detection An anagram is the result of rearranging the letters of a word to produce a new word (see wikipedia). Note: anagrams are case insensitive Complete the function to return true if the two arguments given are anagrams of each other; return false otherwise. Examples "foefet" is an anagram of "toffee" "Buckethead" is an anagram of "DeathCubeK" Solution: def is_anagram(test, original): if len(test) < l.. 2022. 7. 21.
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.
Two to One Description: Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters - each taken only once - coming from s1 or s2. Examples: a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq" longest(a, b) -> "abcdefklmopqwxy" a = "abcdefghijklmnopqrstuvwxyz" longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" Solution: 1. Concatenate strin.. 2022. 4. 26.