I group spells by damage and replace each damage x with a single weight total[x] = x * count(x). Because choosing damage x forbids x±1 and x±2, I can only combine damages that differ by at least 3. I sort the unique damage values and run a dynamic programming over that sorted list: for each index i with value vals[i], either skip it (carry dp[i-1]) or take total[vals[i]] plus the best dp from the largest index j with vals[j] ≤ vals[i] - 3. I find that j with bisect_right and use a prefix_max array for O(1) lookup of the best dp up to any index. The answer is the last dp value.
class Solution:
def maximumTotalDamage(self, power: List[int]) -> int:I notice the teleport pattern partitions indices into k independent chains: indices r, r+k, r+2k, ... for each residue r = 0..k-1. Starting at any index means picking a suffix of one of those chains and summing all elements in that suffix. So for each chain I compute the maximum suffix sum (scanning its elements from the end toward the front), and the answer is the maximum among those k values.
class Solution:
def maximumEnergy(self, energy: List[int], k: int) -> int:I sort the potions array once. For each spell, I compute the minimum potion strength needed so that spell * potion >= success, which is needed = ceil(success / spell). Then I binary-search (bisect_left) in the sorted potions to find the first index with value >= needed; the number of successful potions for that spell is m - index.
class Solution:
def successfulPairs(self, spells: List[int], potions: List[int], success: int) -> List[int]:I used a hash map to track which lakes are currently full and a min-heap to manage the available dry days. When it rains over a lake, I check if it's already full—if so, I must have previously scheduled a dry day for it; otherwise, a flood occurs. On dry days, I store their indices in a heap so I can later assign them efficiently to the lakes that need drying before their next rain. This ensures I always dry the most urgent lake first and avoid floods optimally.
class Solution:I approach this problem by treating the grid as a graph where each cell represents a node, and I aim to find a path from the top-left to the bottom-right that minimizes the highest elevation encountered along the way. Since water rises over time, the minimum time required to reach the destination equals the smallest possible “maximum elevation” on any valid path. To achieve this, I use a min-heap (priority queue) similar to Dijkstra’s algorithm, always exploring the cell with the lowest elevation first while keeping track of the maximum elevation seen so far. Once I reach the bottom-right cell, that maximum elevation represents the minimum time needed to swim across.
class Solution:
def swimInWater(self, grid: List[List[int]]) -> int:I start two BFSs (or DFSs): one from all Pacific-border cells (top row + left column) and one from all Atlantic-border cells (bottom row + right column). For each search I only move from a cell to a neighbor if the neighbor's height is greater than or equal to the current cell's height (this simulates water flowing downhill from neighbor → current, so reversing the direction finds all cells that can flow to that ocean). Cells reachable by both searches can flow to both oceans.
class Solution:
def pacificAtlantic(self, heights: List[List[int]]) -> List[List[int]]:I use two pointers at the edges and calculate the area formed by the two heights. Since the container height is limited by the shorter line, I move the pointer pointing to the shorter line inward to try and maximize the area. I repeat until the two pointers meet, keeping track of the maximum area found.
class Solution:
def maxArea(self, height: List[int]) -> int: