본문 바로가기

Queues: A Tale of Two Stacks A queue is an abstract data type that maintains the order in which elements were added to it, allowing the oldest elements to be removed from the front and new elements to be added to the rear. This is called a First-In-First-Out(FIFO) data structure because the first element added to the queue (i.e., the one that has been waiting the longest) is always the first one to be removed.A basic queue .. 더보기
Level 2 - 최솟값 만들기 자연수로 이루어진 길이가 같은 수열 A,B가 있습니다. 최솟값 만들기는 A, B에서 각각 한 개의 숫자를 뽑아 두 수를 곱한 값을 누적하여 더합니다. 이러한 과정을 수열의 길이만큼 반복하여 최종적으로 누적된 값이 최소가 되도록 만드는 것이 목표입니다.예를 들어 A = [1, 2] , B = [3, 4] 라면A에서 1, B에서 4를 뽑아 곱하여 더합니다.A에서 2, B에서 3을 뽑아 곱하여 더합니다.수열의 길이만큼 반복하여 최솟값 10을 얻을 수 있으며, 이 10이 최솟값이 됩니다. 수열 A,B가 주어질 때, 최솟값을 반환해주는 getMinSum 함수를 완성하세요. 풀이 import java.util.*; class TryHelloWorld { public int getMinSum(int []A, int .. 더보기
Level 2 - 소수 찾기 numberOfPrime 메소드는 정수 n을 매개변수로 입력받습니다.1부터 입력받은 숫자 n 사이에 있는 소수의 개수를 반환하도록 numberOfPrime 메소드를 만들어 보세요.소수는 1과 자기 자신으로만 나누어지는 수를 의미합니다. (1은 소수가 아닙니다.)10을 입력받았다면, 1부터 10 사이의 소수는 [2,3,5,7] 4개가 존재하므로 4를 반환 5를 입력받았다면, 1부터 5 사이의 소수는 [2,3,5] 3개가 존재하므로 3를 반환 풀이 class NumOfPrime { int numberOfPrime(int n) { int result = 0; // 함수를 완성하세요. for (int i = 2; i 더보기
Day 11: 2D Arrays Context Given a 2D Array, :1 1 1 0 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 We define an hourglass in to be a subset of values with indices falling in this pattern in 's graphical representation:a b c d e f g There are hourglasses in , and an hourglass sum is the sum of an hourglass' values.Task Calculate the hourglass sum for every hourglass in , then print the maximum ho.. 더보기
Stacks: Balanced Brackets A bracket is considered to be any one of the following characters: (, ), {, }, [, or ].Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exact same type. There are three types of matched pairs of brackets: [], {}, and ().A matching pair of brackets is not balanced if the set of brackets .. 더보기
Level 2 - 콜라츠 추측 1937년 Collatz란 사람에 의해 제기된 이 추측은, 입력된 수가 짝수라면 2로 나누고, 홀수라면 3을 곱하고 1을 더한 다음, 결과로 나온 수에 같은 작업을 1이 될 때까지 반복할 경우 모든 수가 1이 된다는 추측입니다. 예를 들어, 입력된 수가 6이라면 6→3→10→5→16→8→4→2→1 이 되어 총 8번 만에 1이 됩니다. collatz 함수를 만들어 입력된 수가 몇 번 만에 1이 되는지 반환해 주세요. 단, 500번을 반복해도 1이 되지 않는다면 –1을 반환해 주세요. 풀이 class Collatz { public int collatz(int num) { int answer = 0; while (true){ if (num % 2 == 0){ num = num / 2; } else { num .. 더보기
Linked Lists: Detect a Cycle A linked list is said to contain a cycle if any node is visited more than once while traversing the list.Complete the function provided in the editor below. It has one parameter: a pointer to a Node object named that points to the head of a linked list. Your function must return a boolean denoting whether or not there is a cycle in the list. If there is a cycle, return true; otherwise, return fa.. 더보기
Level 2 - 정수 내림차순으로 배치하기 reverseInt 메소드는 int형 n을 매개변수로 입력받습니다. n에 나타나는 숫자를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요. 예를들어 n이 118372면 873211을 리턴하면 됩니다. n은 양의 정수입니다. 풀이 import java.util.*; public class ReverseInt { public int reverseInt(int n){ String strNum = String.valueOf(n); int[] arr = new int[strNum.length()]; for (int i = 0; i 더보기
Level 1 - 최대공약수와 최소공배수 두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환해주는 gcdlcm 함수를 완성해 보세요. 배열의 맨 앞에 최대공약수, 그 다음 최소공배수를 넣어 반환하면 됩니다. 예를 들어 gcdlcm(3,12) 가 입력되면, [3, 12]를 반환해주면 됩니다. 풀이 import java.util.Arrays; class TryHelloWorld { public int[] gcdlcm(int a, int b) { if( a 더보기
Day 10: Binary Numbers Task Given a base- integer, , convert it to binary (base-). Then find and print the base- integer denoting the maximum number of consecutive 's in 's binary representation.Input FormatA single integer, .ConstraintsOutput FormatPrint a single base- integer denoting the maximum number of consecutive 's in the binary representation of .Sample Input 15 Sample Output 11 Sample Input 213 Sample Output.. 더보기