본문 바로가기

코딩연습11

LeetCode 189. Rotate Array Problem: Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] Explanation: rotate 1 steps to the right: [7,1,2,3,4,5,6] rotate 2 step.. 2020. 5. 22.
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.
LeetCode 01. Two Sum Problem: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. Summary: 1. nums list를 돌며 target-num을 하였을때 다른 number가 dict 안에 있는지 확인. 2.. 2020. 5. 21.
CodeSignal [30/60] circleOfNumbers 문제: Consider integer numbers from 0 to n - 1 written down along the circle in such a way that the distance between any two neighboring numbers is equal (note that 0 and n - 1 are neighboring, too). Given n and firstNumber, find the number which is written in the radially opposite position to firstNumber. Example: Example For n = 10 and firstNumber = 2, the output should be circleOfNumbers(n, fir.. 2020. 5. 21.
LeetCode 36. Valid Sudoku [Medium] 문제: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. A partially filled sudoku which is valid. The Sudoku board could be pa.. 2020. 5. 20.