본문 바로가기

Programming/Python

(5)
[python] codeSignal 문제풀이 (10) 10. Given two strings, find the number of common characters between them. Example) For s1 = "aabcc" and s2 = "adcaa", the output should be commonCharacterCount(s1, s2) = 3. Strings have 3 common characters - 2 "a"s and 1 "c". 1 2 3 4 5 6 def commonCharacterCount(s1, s2): count = 0 common_ch = set(s1) & set(s2) for i in common_ch: count += min(s1.count(i), s2.count(i)) return count 1 2 3 4 5 # so..
[python] codeSignal 문제풀이 (9) 9. Given an array of strings, return another array containing all of its longest strings. Example ) For inputArray = ["aba", "aa", "ad", "vcd", "aba"], the output should be allLongestStrings(inputArray) = ["aba", "vcd", "aba"]. 1 2 3 4 5 6 7 8 9 10 11 def allLongestStrings(inputArray): array_len = [] for i in range(len(inputArray)): array_len.append(len(inputArray[i])) len_max = max(array_len) n..
[python] codeSignal 문제풀이 (7~8) 7. Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. Note: sequence a0, a1, ..., an is considered to be a strictly increasing if a0 < a1 < ... < an. Sequence containing only one element is also considered to be strictly increasing. 어떤 수들이 나열되어 있을 때, 그 수열 중에 한 숫자만 빼서 증가 수열이 될 수 있..
[python] codeSignal 문제풀이 (4~6) 4. Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. Example) For inputArray = [3, 6, -2, -5, 7, 3], the output should be adjacentElementsProduct(inputArray) = 21. 7 and 3 produce the largest product. 1 2 def adjacentElementsProduct(inputArray): return max([inputArray[i] * inputArray[i+1] for i in range(len(inputArray) -1)]) 5. B..
[python] codeSignal 문제풀이 (1~3) 1. Write a function that returns the sum of two numbers. Example) For param1 = 1 and param2 = 2, the output should be add(param1, param2) = 3. 1 2 3 def add(param1, param2): return param1 + param2 2. Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc. Example) Fo..