Python/CodeSignal Algorithm(21)
-
[Python] CodeSignal 문제 풀이 (25~27)
25. 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 be arrayReplace(inputArray, elemToReplace, substitutionElem) = [3, 2, 3]. [Solution] # def arrayReplace(inputArray, elemToReplace, substitutionElem): a = inputArray for i in range(len(a)): if(a[i] ..
2020.03.12 -
[Python] CodeSignal 문제 풀이 (22~24)
22. You are given an array of integers representing coordinates of obstacles situated on a straight line. Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to make jumps of the same length represented by some integer. Find the minimal length of the jump enough to avoid all the obstacles. [Example] [Solution] - ing # def avoidObstacles(inputArray): a ..
2020.03.12 -
[Python] CodeSignal 문제 풀이 (19~21)
19. Call two arms equally strong if the heaviest weights they each are able to lift are equal. Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms. Given your and your friend's arms' lifting capabilities find out if you two are equally strong. [Example] For yourLeft = 10, yourRight = 15, f..
2020.03.12 -
[Python] CodeSignal 문제 풀이 (16~18)
16. Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements in one of the arrays. Given two arrays a and b, check whether they are similar. [Example] For a = [1, 2, 3] and b = [1, 2, 3], the output should be areSimilar(a, b) = true. The arrays are equal, no need to swap any elements. For a = [1, 2, 3] and b = [2, 1, 3], the output should be areS..
2020.03.12 -
[Python] CodeSignal 문제 풀이 (13~15)
13. Write a function that reverses characters in (possibly nested) parentheses in the input string. Input strings will always be well-formed with matching ()s. [Example] For inputString = "(bar)", the output should be reverseInParentheses(inputString) = "rab"; For inputString = "foo(bar)baz", the output should be reverseInParentheses(inputString) = "foorabbaz"; For inputString = "foo(bar)baz(bli..
2020.03.12 -
[Python] CodeSignal 문제 풀이 (10~12)
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". [Solution] def commonCharacterCount(s1, s2): s1_digit = list(set(s1)) s2_digit = list(set(s2)) sum = 0 ch = "" for i in range(len(s1_digit)): if (s1_digit[i] in s2_digit):..
2020.02.29