Eat Study Love

먹고 공부하고 사랑하라

coding test 33

Battleships in a Board(Array,Depth-First Search,Matrix)

https://leetcode.com/problems/battleships-in-a-board/description/Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board.Battleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least..

Coding_Practice 2024.11.21

Min Cost to Connect All Points(Array,Union Find,Graph,Minimum Spanning Tree)

https://leetcode.com/problems/min-cost-to-connect-all-points/description/You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.Return the minimum cost to make all poin..

Coding_Practice 2024.11.12

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

Find Minimum in Rotated Sorted Array2[Array,Binary Search]

https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/description/Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,4,4,5,6,7] might become:[4,5,6,7,0,1,4] if it was rotated 4 times.[0,1,4,4,5,6,7] if it was rotated 7 times.Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the ..

Coding_Practice 2024.10.31

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

Find if Path Exists in Graph[Depth-First Search,Breadth-First Search,Union Find,Graph]

https://leetcode.com/problems/find-if-path-exists-in-graph/description/?envType=problem-list-v2&envId=graphThere is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-directional edge between vertex ui and vertex vi. Every vertex pair is c..

Coding_Practice 2024.10.28