[LeetCode] 3066. Minimum Operations to Exceed Threshold Value II (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명You are given a 0-indexed integer array nums, and an integer k. In one operation, you will: Take the two smallest integers x and y in nums.Remove x and y from nums.Add min(x, y) * 2 + max(x, y) anywhere in the array. Note that you can only apply the described operation if nums contains at least two elements. nums. Return the minimum number of operations needed so that all element..
[LeetCode] 2342. Max Sum of a Pair With Equal Sum of Digits (Python)
·
알고리즘/LeetCode
난이도: Medium문제 설명 You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j]. Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions. 문제 예제Example 1:Input: nums = [18,43,36,13,7]Output: 54E..
[LeetCode] 407. Trapping Rain Water II (Python)
·
알고리즘/LeetCode
문제 설명Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining. 문제 예제Example 1:Input: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]Output: 4Explanation: After the rain, water is trapped between the blocks.We have two small ponds 1 and 3 units trapped.The total volume of water trapped is ..
[LeetCode] 1368. Minimum Cost to Make at Least One Valid Path in a Grid (Python)
·
알고리즘/LeetCode
난이도: Hard문제 설명Given an m x n grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign of grid[i][j] can be:1 which means go to the cell to the right. (i.e go from grid[i][j] to grid[i][j + 1])2 which means go to the cell to the left. (i.e go from grid[i][j] to grid[i][j - 1])3 which means go to the lower cell. (i.e go from grid..
[LeetCode] 3286. Find a Safe Walk Through a Grid (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given an m x n binary matrix grid and an integer health. You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1). You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive. Cells (i, j) with grid[i][j] = 1 are considered unsafe and reduce your health by 1. Return t..
[LeetCode] 1962. Remove Stones to Minimize the Total (Python)
·
알고리즘/LeetCode
난이도: Medium 문제 설명You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remove floor(piles[i] / 2) stones from it.Notice that you can apply the operation on the same pile more than once. Return the minimum possible total number of stones rema..