본문 바로가기

프로그래밍 기술 노트/Problem Solving

(7)
[PS/C#] Leet Code - Algorithms - [Sum of Nodes with Even-Valued Grandparent] / [Minimum Depth of Binary Tree] leetcode.com/problems/minimum-depth-of-binary-tree/ Minimum Depth of Binary Tree - 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 leetcode.com/problems/sum-of-nodes-with-even-valued-grandparent/ Sum of Nodes with Even-Valued Grandparent - LeetCode Level up your coding skills and q..
[PS/C#] HackerRand - Algorithms - The Maximum Subarray www.hackerrank.com/challenges/maxsubarray/problem The Maximum Subarray | HackerRank Given an array find the maximum possible sum of two types of subsequences. www.hackerrank.com static int[] maxSubarray(int[] arr) { var maxElement = arr.Max(); var sumPositive = arr.Any(x=>x>0); var maxOfSubseq = sumPositive ? arr.Where(x=>x>0).Sum() : maxElement; var dp = new int[] { arr[0], arr[0] }; var sum = ..
[PS/Clojure] HackerRand - Algorithms - Queen's Attack 알고리즘도 쉽고 구현도 쉬웠어야 하는문제 분명 맞게 푼거 같은데 테스트케이스에서 절반이 자꾸 틀려서 이것저것 다 시도해보다가 코드가 드럽게 길어졌다. 근데 맨처음 위치파악하는 조건문에서 조건하나를 빠트렸던문제였음 ㅡㅡ 맨처음 알고리즘이 제일 깔끔했는데 너무 많이 바뀌어버려서 돌아갈수없다.. www.hackerrank.com/challenges/queens-attack-2/problem Queen's Attack II | HackerRank Find the number of squares the queen can attack. www.hackerrank.com github.com/Lee-WonJun/ProblemSolving/blob/master/Brute%20Force/Queen's%20Attack%20..
[PS/Clojure] HackerRand - Algorithms - Absolute Permutation 아.. 뭔가 더 짤수있을꺼같은데.. Stream 규칙을 어떻게 세워야 할지 모르겠다. 필자가 적용한 알고리즘의 기초는 k가 2인경우 : 2 2 -2 -2 2 2 -2 -2 .... k가 3인경우 : 3 3 3 -3 -3 -3 3 3 3 -3 -3 -3 .. 이렇게 스트림에 더한것이 정상적인지 확인. www.hackerrank.com/challenges/absolute-permutation/problem Absolute Permutation | HackerRank Find lexicographically smallest absolute permutation. www.hackerrank.com github.com/Lee-WonJun/ProblemSolving/blob/master/Brute%20Force/A..
[PS/Clojure] HackerRand - Algorithms - Forming a Magic Square Implementation 항목의 Magic Square, BruteForce 로 풀었다. 처음에는 time out나서 BruteForce 가 아닌가 했는데.. filter 를 안걸어주었었다. 모든 순열을 구하는데 사용한 permutations 코드는 그냥 인터넷에서 긁어왔다 ;; C++ 은 next_permutation이 STL 에 있는데 clojure에 있는 clojure.math.combinatorics 가 HackerRank에서 지원을 안해준다 크흠.. Forming a Magic Square | HackerRank Find the minimum cost of converting a 3 by 3 matrix into a magic square. www.hackerrank.com Lee-WonJun..
[PS/Clojure] HackerRand - Algorithms - Sherlock and Cost DP 를 사용하는 Sherlock and Cost 난 못풀었다ㅜ 코드는 설명을 듣고 Clojure로 구현한 코드. Sherlock and Cost | HackerRank Given array A, B and relation between them find the cost of array A. www.hackerrank.com Lee-WonJun/ProblemSolving 알고리즘 세미나 . Contribute to Lee-WonJun/ProblemSolving development by creating an account on GitHub. github.com (defn abs [x] (max (- x) x)) (defn fun ([v] (fun v 0 0)) ( [v dp1 dp2] (if (= (co..
[PS/Clojure] HackerRand - Algorithms - Equal 클로저를 아주 잘 지원해주는 몇안되는 알고리즘 사이트 HackerRank 지인과 함께 알고리즘 공부중이다. 각자 C++/Python/Clojure 로 문제 풀이중. 첫문제는 DP 를 사용하는 Equal 알고리즘은 약하기 때문에... 친구의 힌트를 듣고 풀었다. Equal | HackerRank Calculate minimum number of such operations needed to ensure that every colleague has the same number of chocolates. www.hackerrank.com 내풀이는 다음과 같다. Lee-WonJun/ProblemSolving 알고리즘 세미나 . Contribute to Lee-WonJun/ProblemSolving develop..