Eat Study Love

먹고 공부하고 사랑하라

Python 159

코딩테스트 문제 4개 Review

C - 2개 / C++ - 2개 이렇게 총 4개의 코딩문제를 3시간에 거쳐서 풀어보았다. 문제는 Time / Space Complexcity를 크게 고려하지 않고, 정답만 도출되면 인정되는 부분이라 어거지로 코드를 짜서 답을 도출해내는 데에는 성공을 했으나.. 앞으로 좀 더 효율적인 코딩을 하기 위해선 Coding Review정도는 하고 넘어가는 것이 좋을 거 같아 글을 적어본다. 문제의 출처도 제공되진 않지만, 시험이 끝나고 내가 스스로 복기 + 구글링/GPT를 이용해서 문제 출처를 추려내어 보았다.  1번 문제https://school.programmers.co.kr/learn/courses/30/lessons/42627 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을..

Coding_Practice 2024.12.02

Maximum Difference Between Node and Ancestor(Tree,Depth-First Search,Binary Tree)

https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/description/Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b.A node a is an ancestor of b if either: any child of a is equal to b or any child of a is an ancestor of b. Example 1:Input: root = [8,3,10,1,6,null,14,nul..

Coding_Practice 2024.11.28

Maximum Depth of Binary Tree(Tree,Depth-First Search,Breadth-First Search,Binary Tree)

https://leetcode.com/problems/maximum-depth-of-binary-tree/description/Given the root of a binary tree, return its maximum depth.A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. Example 1:Input: root = [3,9,20,null,null,15,7]Output: 3Example 2:Input: root = [1,null,2]Output: 2 Constraints:The number of nodes in the tre..

Coding_Practice 2024.11.28

The K Weakest Rows in a Matrix(Array,Binary Search,Sorting,Heap (Priority Queue),Matrix)

https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/description/You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0's in each row.A row i is weaker than a row j if one of the following is true:The number of soldiers in row..

Coding_Practice 2024.11.28

Car Pooling(Array,Sorting,Heap (Priority Queue),Simulation,Prefix Sum)

https://leetcode.com/problems/car-pooling/description/There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).You are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] indicates that the ith trip has numPassengersi passengers and the locations to pick them up and drop them off are fromi and toi ..

Coding_Practice 2024.11.28

heap 자료구조 (Priority queue /Min&Max Heap) 뿌시기

Python / C / C++에서 Array / Linked List 기반으로 heap 구조를 만들어보겠다. Skeleton Code는 GPT를 참고했으며, Min/Max heap은 사실 한 끝 차이라 이 둘을 그냥 번갈아가면서 구현해보기로 한다. 1. Python - Array - Min heapclass PriorityQueueArray: def __init__(self, is_min=True): self.heap = [] self.is_min = is_min # True for min-heap, False for max-heap def parent(self, i): return (i - 1) // 2 def left_child(self, i):..

SW 만학도/C 2024.11.25

Meeting Room Allocation Problem

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.입출력 예시Example 1:Input: intervals = [[0,30],[5,10],[15,20]]Output: 2Example 2:Input: intervals = [[7,10],[2,4]]Output: 1제약사항1  Leetcode의 meeting room #2 문제이다. 문제확인을 위해 유료결제가 필요하지만 그냥 구글링해서 문제를 긁어왔다. 실습시간에도 사용된 문제이니 함 풀어보자   1. C++쉬운 줄 알고 아래처럼 풀었는데,쉽지 않았다....

Coding_Practice 2024.11.25

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