본문 바로가기
728x90

알고리즘/코드시그널27

Codesignal - buildPalindrome Given a string, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome. Example For st = "abcdc", the output should be buildPalindrome(st) = "abcdcba". Input/Output [execution time limit] 20 seconds (swift) [input] string stGuaranteed constraints: 3 ≤ st.length ≤ 10. A string consisting of lowercase English letters. [outp.. 2021. 5. 6.
Codesignal - firstDigit 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’. Input/Output [execution time limit] 20 seconds (swift) [input] string inputString A string cont.. 2021. 5. 6.
Codesignal - find Email Domain An email address such as "John.Smith@example.com" is made up of a local part ("John.Smith"), an "@" symbol, then a domain part ("example.com"). The domain name part of an email address may only consist of letters, digits, hyphens and dots. The local part, however, also allows a lot of different special characters. Here you can look at several examples of correct and incorrect email addresses. Gi.. 2021. 5. 6.
Codesignal - extractEachKth 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]. Input/Output [execution time limit] 20 seconds (swift) [input] array.integer inputArray Guaranteed constraints: 5 ≤ inputArray.length ≤ 15, -20 ≤ inputArray[i] ≤ 20. [input] integer k Guaranteed .. 2021. 5. 3.
Codesignal - evenDigingsOnly Check if all digits of the given integer are even. Example For n = 248622, the output should be evenDigitsOnly(n) = true; For n = 642386, the output should be evenDigitsOnly(n) = false. Input/Output [execution time limit] 20 seconds (swift) [input] integer n Guaranteed constraints: 1 ≤ n ≤ 109. [output] boolean true if all digits of n are even, false otherwise. 풀이 주어지는 숫자의 각 자리수에 해당하는 숫자가 짝수일때만 .. 2021. 5. 3.
Codesignal - digitDegree 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 be digitDegree(n) = 0; For n = 100, the output should be digitDegree(n) = 1. 1 + 0 + 0 = 1. For n = 91, the output should be digitDegree(n) = 2. 9 + 1 =.. 2021. 5. 2.
Codesignal - differentSymbolsNaive 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. Input/Output [execution time limit] 20 seconds (swift) [input] string sGuaranteed constraints: 3 ≤ s.length ≤ 1000. A string of lowercase English letters. [output] integer 설명 주어지는 문자열에서 서로다른 문자의 수를 리턴하라 풀이 Set의 중복 .. 2021. 5. 2.
Codesignal - depositProfit 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) = 3. E.. 2021. 5. 2.
Codesignal - commonCharacterCount 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". 설명 s1과 s2의 문자열을 분석하여 똑같은 문자의 개수를 구한다. 풀이 s1의 "aabcc"에 a가 2개, s2의 "adcaa"에도 a가 3개 => count에 2 s1의 "aabcc"에 c가 2개, s2의 "adcaa"에 c가 한개 => count에 1 총합 2+1 3을 리턴한다. func commonCharac.. 2021. 5. 1.