CodeSignal/Arcade36 CodeSignal [36/60] differentSymbolsNaive Problem: Given a string, find the number of different characters in it. Example For s = "cabca", the output should be differentSymbolsNaive(s) = 3. There are 3 different characters a, b and c. -Summary- 1. Create a temporary set variable to not have a duplicate value 2. Using for loop, if the character is already in the set, we skip and continue. If the first character faced, we add in to set an.. 2020. 5. 25. CodeSignal [35/60] firstDigit Problem: Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int", the output should be firstDigit(inputString) = '1'; For inputString = "q2q-q", the output should be firstDigit(inputString) = '2'; For inputString = "0ss", the output should be firstDigit(inputString) = '0'. -Summary- 1. isdigit() 함수를 이용하여 char 하나하나 비교후, if we found a 'True' value, then we ret.. 2020. 5. 25. CodeSignal [34/60] extractEachKth Problem: 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]. -Summary- 1. Create a 'ans' list for answer list 2. While loop을 돌리면서 index 가 지워지는 번호에 해당하지 않는경우 ans list에 넣어준다. 3. loop을 다 돌리면 지워지는 Kth index element만 지워진 'ans' list값을 return. Additional.. 2020. 5. 24. CodeSignal [33/60] stringsRearrangement Problem 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. 5. 23. CodeSignal [32/60] absoluteValuesSumMinimization Problem: Given a sorted array of integers a, your task is to determine which element of a is closest to all other values of a. In other words, find the element x in a, which minimizes the following sum:abs(a[0] - x) + abs(a[1] - x) + ... + abs(a[a.length - 1] - x) (where abs denotes the absolute value) If there are several possible answers, output the smallest one. Example: For a = [2, 4, 7], th.. 2020. 5. 22. CodeSignal [31/60] depositProfit Problem: 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, thresho.. 2020. 5. 22. 이전 1 2 3 4 5 6 다음