본문 바로가기

코딩92

CodeSignal [56/60] digitsProduct Problem: Given an integer product, find the smallest positive (i.e. greater than 0) integer the product of whose digits is equal to product. If there is no such integer, return -1 instead. Example For product = 12, the output should be digitsProduct(product) = 26; For product = 19, the output should be digitsProduct(product) = -1. -Summary- 1. we search the number from 1 to 10000. 2. change the .. 2020. 5. 28.
CodeSignal [55/60] differentSquares Problem: Given a rectangular matrix containing only digits, calculate the number of different 2 × 2 squares in it. Example For the output should be differentSquares(matrix) = 6. Here are all 6 different 2 × 2 squares: 1 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 3 2 3 2 1 -Summary- 1. set variable을 만들어서 matrix 의 4*4 의 각 숫자를 string으로 만들어 저장해준다. 2. 만약 똑같은 value가 이미 있다면 저장되지 않고, 똑같은 value가 없다면 새로 저장될 것이다... 2020. 5. 28.
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.