본문 바로가기

CodeSignal42

CodeSignal [54/60] sumUpNumbers Problem: CodeMaster has just returned from shopping. He scanned the check of the items he bought and gave the resulting string to Ratiorg to figure out the total number of purchased items. Since Ratiorg is a bot he is definitely going to automate it, so he needs a program that sums up all the numbers which appear in the given input. Help Ratiorg by writing a function that returns the sum of numb.. 2020. 5. 28.
CodeSignal [53/60] validTime Problem: Check if the given string is a correct time representation of the 24-hour clock. Example For time = "13:58", the output should be validTime(time) = true; For time = "25:51", the output should be validTime(time) = false; For time = "02:76", the output should be validTime(time) = false. -Summary- 1. Check if 'HH' part and 'MM' part is valid (Valid only if 'HH' is between 0 to 23 and 'MM' .. 2020. 5. 28.
CodeSignal [52/60] longestWord Problem: Define a word as a sequence of consecutive English letters. Find the longest word from the given string. Example For text = "Ready, steady, go!", the output should be longestWord(text) = "steady". -Summary- 1. loop through the text and keep add until it meets a special character. 2. Once it encounters a special character, append the saved word to the temp_list. 3. For the last word that.. 2020. 5. 28.
CodeSignal [51/60] deleteDigit Problem: Given some integer, find the maximal number you can obtain by deleting exactly one digit of the given number. Example For n = 152, the output should be deleteDigit(n) = 52; For n = 1001, the output should be deleteDigit(n) = 101. -Summary- 1. 현재 index에서 next index가 큰 값인 경우만 지워주면 항상 제일 큰 숫자가 되므로, 해당되는 index를 찾아준다. 2. 찾은후에는 그 index만 지우고 return. 만약에 loop을 다 돈 이후에도, 지운 숫자가 없다면 마지막 숫자만 지워준다... 2020. 5. 28.
CodeSignal [50/60] chessKnight Problem: Given a position of a knight on the standard chessboard, find the number of different moves the knight can perform. The knight can move to a square that is two squares horizontally and one square vertically, or two squares vertically and one square horizontally away from it. The complete move therefore looks like the letter L. Check out the image below to see all valid moves for a knigh.. 2020. 5. 28.
CodeSignal [49/60] lineEncoding Problem: Given a string, return its encoding defined as follows: First, the string is divided into the least possible number of disjoint substrings consisting of identical characters for example, "aabbbc" is divided into ["aa", "bbb", "c"] Next, each substring with length greater than one is replaced with a concatenation of its length and the repeating character for example, substring "bbb" is r.. 2020. 5. 27.