Python/CodeSignal Algorithm(21)
-
[Python] CodeSignal 문제 풀이 (40~42)
40. Given a string, output its longest prefix which contains only digits. [Example] For inputString = "123aa1", the output should be longestDigitsPrefix(inputString) = "123". [Solution] -ing # def longestDigitsPrefix(inputString): a = inputString.split() result = "" if inputString.isdigit(): return inputString for i in range(len(a)): s = "" if any(sym in a[i] for sym in '!@#$%^&*()'): continue f..
2020.03.31 -
[Python] CodeSignal 문제 풀이 (37~39)
37. 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 be arrayMaxConsecutiveSum(inputArray, k) = 8. All possible sums of 2 consecutive elements are: 2 + 3 = 5; 3 + 5 = 8; 5 + 1 = 6; 1 + 6 = 7. Thus, the answer is 8. [Soluton] # def arrayMaxConsecutiveSum(inputArray, k): a = inputAr..
2020.03.31 -
[Python] CodeSignal 문제 풀이 (34~36)
34. 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 be extractEachKth(inputArray, k) = [1, 2, 4, 5, 7, 8, 10]. [Solution] # def extractEachKth(inputArray, k): a = inputArray del a[k-1::k] return a # def extractEachKth(inputArray, k): del inputArray[k-1::k] return inputArray 35. Find the leftmost dig..
2020.03.31 -
[Python] CodeSignal 문제 풀이 (33~35)
33. Given an array of equal-length strings, you'd like to know if it's possible to rearrange the order of the elements in such a way that each consecutive pair of strings differ by exactly one character. Return true if it's possible, and false if not. Note: You're only rearranging the order of the strings, not the order of the letters within the strings! [Example] For inputArray = ["aba", "bbb",..
2020.03.21 -
[Python] CodeSignal 문제 풀이 (31~33)
31. You have deposited a specific amount of money into your bank account. Each year your balance increases at the same growth rate. With the assumption that you don't make any additional deposits, find out how long it would take for your balance to pass a specific threshold. [Example] For deposit = 100, rate = 20, and threshold = 170, the output should be depositProfit(deposit, rate, threshold) ..
2020.03.12 -
[Python] CodeSignal 문제 풀이 (28~30)
28. Given a string, your task is to replace each of its characters by the next one in the English alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a). [Example] For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz". [Solution] # def alphabeticShift(inputString): os = inputString ns = "" for i in range(len(os)): if os[i] == 'z': ns +=..
2020.03.12