코딩테스트

[JS] LeetCode - 2. Add Two Numbers
https://leetcode.com/problems/add-two-numbers/ Add Two Numbers - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single dig..

[JS] 봉우리
문제 지도 정보가 N*N 격자판에 주어진다. 각 격자에는 그 지역의 높이가 쓰여있고, 각 격자판의 숫자 중 자신의 상하좌우 숫자보다 큰 숫자는 봉우리 지역이다. 봉우리가 몇 개 있는지 알아내는 프로그램을 작성하시오. (1= 0 && ny = arr[i][j] ) { flag = 0; break; } } if (flag) answer++; } } return answer; } arr = [ [5, 3, 7, 2, 3], [3, 7, 1, 6, 1], [7, 2, 5, 3, 4], [4, 3, 6, 4, 1], [8, 7, 3, 5, 2], ]; arr[i][j]의 상하좌우를 확인하기 위해서 dx, dy 배열을 선언해주고 [i-1][j], [i][j+1], [i+1][j]..
[JS] 일곱 난쟁이
문제 아홉 난쟁이 모두가 자기가 일곱 난쟁이라고 주장한다. 일곱 난쟁이의 키의 합이 100이고 아홉 난쟁이의 키가 주어졌을 때, 그 중 일곱 난쟁이를 찾는 프로그램을 작성하시오. (아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우 아무거나 출력) 입력 예제 20 7 23 19 10 15 25 8 13 출력 예제 20 7 23 19 10 8 13 정답 function solution(arr) { let answer = arr; let sum = answer.reduce((a, b) => a + b, 0); for (let i = 0; i < 8; i++) { for (let j = i + 1; j < 9; j++) { if (sum - (answer[i] + answer[j]) == 100..

[JS] LeetCode - 53. Maximum Subarray / 카데인 알고리즘(Kadane's Algorithm)
Maximum Subarray - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array. Input, Output 예시 Input: nums =..