Eat Study Love

먹고 공부하고 사랑하라

코딩 57

Guess Number Higher or Lower II[Math,Dynamic Programming,Game Theory]

https://leetcode.com/problems/guess-number-higher-or-lower-ii/description/We are playing the Guessing Game. The game will work as follows:I pick a number between 1 and n.You guess a number.If you guess the right number, you win the game.If you guess the wrong number, then I will tell you whether the number I picked is higher or lower, and you will continue guessing.Every time you guess a wrong n..

Coding_Practice 2024.11.05

Binary Grid Question[Loop & Graph]

list of list[int] 의 data type을 받아서 가장 긴 connected 1's length를 반환하는 함수를 만들어야 한다. Matrix 는 2차원이다보니까 m*n Matrix를 생각하면 되고, 주어진 2차원 Matrix에서 어떤 것을 0에서 1로 바꿀 지 잘 고민해야하고 x, y축 index 헷갈리지 않게 주의해야 한다. 이거때문에 index overflow로 애좀 먹음.. 꿀팁은 python deque만 있으면 queue / stack 다 구현할 수 있다는 것이고, python의 경우 if 문에서 0  그리고 맨 처음 언급했듯이, x / y축 len과 idx following을 잘 해야 한다. 이런 종류의 문제는 무작정 coding에 들어가지 말고, 머릿속으로 또는 빈 종이에 구조를..

Coding_Practice 2024.11.04

Kth Smallest Element in a BST[Tree,Depth-First Search,Binary Search Tree,Binary Tree]

https://leetcode.com/problems/kth-smallest-element-in-a-bst/description/Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree. Example 1:Input: root = [3,1,4,null,2], k = 1Output: 1Example 2:Input: root = [5,3,6,2,4,null,null,1], k = 3Output: 3 Constraints:The number of nodes in the tree is n.1 0 Follow up: ..

Coding_Practice 2024.10.30

MaxProfit(Given a log of stock prices compute the maximum possible earning)

https://app.codility.com/programmers/lessons/9-maximum_slice_problem/max_profit/ MaxProfit coding task - Learn to Code - CodilityGiven a log of stock prices compute the maximum possible earning.app.codility.comAn array A consisting of N integers is given. It contains daily prices of a stock share for a period of N consecutive days. If a single share was bought on day P and sold on day Q, where 0..

Coding_Practice 2024.10.30

Maximum Depth of N-ary Tree[Tree,Depth-First Search,Breadth-First Search]

https://leetcode.com/problems/maximum-depth-of-n-ary-tree/description/?envType=problem-list-v2&envId=treeGiven a n-ary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See ..

Coding_Practice 2024.10.29

MinMaxDivision(Divide array A into K blocks and minimize the largest sum of any block)

https://app.codility.com/programmers/lessons/14-binary_search_algorithm/min_max_division/ MinMaxDivision coding task - Learn to Code - CodilityDivide array A into K blocks and minimize the largest sum of any block.app.codility.comYou are given integers K, M and a non-empty array A consisting of N integers. Every element of the array is not greater than M.You should divide this array into K block..

Coding_Practice 2024.10.16