Code Signal_练习题_Array Replace】的更多相关文章

Given an array of integers, replace all the occurrences of elemToReplace with substitutionElem. Example For inputArray = [1, 2, 1], elemToReplace = 1, and substitutionElem = 3, the output should bearrayReplace(inputArray, elemToReplace, substitutionE…
Let's define digit degree of some positive integer as the number of times we need to replace this number with the sum of its digits until we get to a one digit number. Given an integer, find its digit degree. Example For n = 5, the output should bedi…
Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a). Example For inputString = "crazy", the output should bealphabeticShift(inputString) = "dsbaz". 我的解答: def alphabeticShift(inp…
Given a string, find out if its characters can be rearranged to form a palindrome. Example For inputString = "aabb", the output should bepalindromeRearranging(inputString) = true. We can rearrange "aabb" to make "abba", which…
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the second item weighs weight2 and is worth value2. What is the total maximum value of the items you can take with you, assuming that your max weight capa…
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed meters due to the lack of sun heat. Initially, plant is 0 meters tall. We plant the seed at the beginning of a day. We want to know when the height o…
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Example For inputArray = [2, 3, 5, 1, 6] and k = 2, the output should bearrayMaxConsecutiveSum(inputArray, k) = 8.All possible sums of 2 consecutive element…
Given a string, find the number of different characters in it. Example For s = "cabca", the output should bedifferentSymbolsNaive(s) = 3. There are 3 different characters a, b and c. 我的解答: def differentSymbolsNaive(s): return len(set(s)) 一模一样 膜拜…
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int", the output should befirstDigit(inputString) = '1'; For inputString = "q2q-q", the output should befirstDigit(inputString) = '2'; For inputSt…
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and k = 3, the output should beextractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10]. 我的解答: def extractEachKth(inputArray, k): return…