본문 바로가기

algorithm63

[HackerRank] New Year Chaos 1. Problem https://www.hackerrank.com/challenges/new-year-chaos/problem?h_l=interview&playlist_slugs[]=interview-preparation-kit&playlist_slugs[]=arrays 2. Feedback 못풀음. 힌트 보고 풀음. 규칙 bribe 는 한 사람이 최대 2번 까지 가능 앞에 있는 얘는 뒤에 있는 얘한테 bribe 를 못 줌. Brute force 로 풀어볼려는데, Swap 해서 규칙을 찾아서 프로그래밍화 하는 방법을 못찾음. 입력 받은 상태를 초기 상태로 변환하는 방법으로 풀음. 최대 2번 바꿀 수 있으며, 초기상태는 오름차순이기에, 끝에서부터 최대 index 2 이내의 값이, 앞의 값이 뒤에 값보다 .. 2018. 10. 11.
[HackerRank] Sock Merchant 1. Link to the problem https://www.hackerrank.com/challenges/sock-merchant/problem?h_l=interview&playlist_slugs[]=interview-preparation-kit&playlist_slugs[]=warmup 2. Feedback 색깔이 맞는 양말 개수를 구하라. 메모리를 이용하여 문제 해결. Map 에 데이터를 담아 양말 색깔을 누적시킨 뒤, 나누기 2하여 양말 개수를 구함. 최종적으로 구한 양말 개수를 누적하여 답 추출 3. Source public class SockMerchant { public static void main(String [] args) { Scanner in = new Scanner(System... 2018. 10. 11.
[HackerRank] Organizing Containers of Balls 1. Problem https://www.hackerrank.com/challenges/organizing-containers-of-balls/problem 2. Feedback 수학적으로 풀어야한다는건 알았는데 못풀었음. Swap 을 해서 같은 종류의 공을 가질 수 있는지에 대한 확실한 풀이를 못찾았음. 답을 보니 container 가 가지는 공의 합과 BallType 의 합이 같으면, Possible 임. container 가 가지는 공의 합과 BallType 의 합이 정렬했을 때 같다면, Swap 을 했을 때, Possible 이라는 것을 알 수 있음. container 끼리 서로 가지고 있는 교환하여 BallType 의 개수에 맞추는 것이 핵심 결국 container 의 합을 정렬한 것 = Bal.. 2018. 7. 12.
[HackerRank] Forming a Magic Square 1. Problem https://www.hackerrank.com/challenges/magic-square-forming/problem 2. Feedback 3*3의 마방진은 답이 정해져있다. 정해진 답 속에서 입력받은 square 를 하나씩 비교해서 cost 를 계산한다. 제일 낮은 값이 정답이다. 3. Source public class FormingAMagicSquare { private static int answer[][] = { {2,9,4,7,5,3,6,1,8}, {4,3,8,9,5,1,2,7,6}, {4,9,2,3,5,7,8,1,6}, {8,3,4,1,5,9,6,7,2}, {8,1,6,3,5,7,4,9,2}, {2,7,6,9,5,1,4,3,8}, {6,1,8,7,5,3,2,9,4}, {.. 2018. 7. 3.