conversations
listlengths
2
2
[ { "from": "user", "value": "Given a list of integers `nums`, find the maximum product of any two distinct elements in the list. Return the maximum product. For example, given `nums = [5, 3, -1, 9, -7]`, the maximum product would be `5 * 9 = 45`." }, { "from": "assistant", "value": "<think>\nOkay...
[ { "from": "user", "value": "Given a list of integers `nums`, consider a list of all possible subarrays. Return the length of the shortest subarray whose sum is equal to or greater than a given integer `target`. If no such subarray exists, return 0." }, { "from": "assistant", "value": "<think>\nO...
[ { "from": "user", "value": "Given an array of integers `arr`, you are to form a sequence by starting from the first element and at each step moving to the next different element (i.e., an element that hasn't been visited yet in the current sequence). Your task is to find the length of the longest subsequenc...
[ { "from": "user", "value": "A tropical island is represented by a grid of size `m x n` where each cell contains a certain number of coconuts. You are positioned at the top-left cell of the grid and want to collect coconuts while moving to the bottom-right cell. You can only move either down or right at any ...
[ { "from": "user", "value": "You are given a list of strings `words` and a string `s` representing a concatenation of an arbitrary order of all words from the list `words`. Each word from the list appears exactly once in the concatenated string `s`. Implement a function to return all possible starting indice...
[ { "from": "user", "value": "Given an integer `n`, return the list of prime numbers less than `n`. Your solution should use the Sieve of Eratosthenes algorithm to ensure optimal performance." }, { "from": "assistant", "value": "<think>\nOkay, I need to solve this problem where I have to find all ...
[ { "from": "user", "value": "Given two integers `a` and `b`, return the smallest **positive integer** that is a multiple of both `a` and `b`. If the smallest multiple does not exist within a reasonable range (i.e., if either `a` or `b` is non-positive), return `-1`." }, { "from": "assistant", "va...
[ { "from": "user", "value": "You are given an array of integers `nums` and an integer `target`. Your task is to find whether there exist two distinct indices `i` and `j` in the array such that the absolute difference between `nums[i]` and `nums[j]` is equal to `target`. Return `true` if such indices exist, o...
[ { "from": "user", "value": "You are given an integer array `heights` representing the heights of students in a class. A subsequence `seq` is defined as an orderly list of students where each subsequent student is taller than the previous one. You need to find and return the length of the longest subsequence...
[ { "from": "user", "value": "Write a function that receives two integers, `start` and `end`, and returns the **sum of all prime numbers** in the inclusive range `[start, end]`. If there are no prime numbers in the given range, the function should return `0`." }, { "from": "assistant", "value": "<...
[ { "from": "user", "value": "You have a rectangular grid of size `m x n`, initially filled with water. You are given an array `cells` where `cells[i] = [r_i, c_i]` represents a land cell (`land`) placed at row `r_i` and column `c_i` (0-indexed). Each day, you place one `land` cell on the grid until all the c...
[ { "from": "user", "value": "You are given an integer `amount` and an array of integers `coins` representing the available denominations of coins. Write a function to compute the number of combinations that make up that amount. You may assume that you have an infinite number of each kind of coin. Return the ...
[ { "from": "user", "value": "Given a matrix of dimensions `n x n` representing the connections in an undirected, weighted graph, where `matrix[i][j]` contains the weight of the edge between nodes `i` and `j`, and `matrix[i][j] = 0` indicates no direct edge exists between node `i` and node `j`. Design an algo...
[ { "from": "user", "value": "You are given a list of `n` strings called `words` and another string called `order` that represents the order of the alphabet (a permutation of the lowercase English letters). Write a function to determine if the given `words` are sorted in lexicographical order according to the...
[ { "from": "user", "value": "Given an array of integers `nums` representing the amount of rain in millimeters for each day, design an algorithm to determine the maximum amount of rain that can be collected between two days. The rain can only be collected if there is a day with no rain between the two selecte...
[ { "from": "user", "value": "You are given two **0-indexed** integer arrays, `start` and `end`, each of length `n`, where `start[i]` and `end[i]` represent the start and end points of the `i-th` interval. A point is said to be covered by an interval if it lies between the start and end points of that interva...
[ { "from": "user", "value": "You are given a string `s` consisting of only lowercase English letters. You can perform the following operation on `s` as many times as you want: Choose any character that appears at least twice in the string and remove all its occurrences. Return the length of the shortest stri...
[ { "from": "user", "value": "Given a string `s` and an integer `k`, return the number of substrings in `s` of length `k` with no repeated characters. You need to efficiently determine the count without generating all possible substrings." }, { "from": "assistant", "value": "<think>\nAlright, I've...
[ { "from": "user", "value": "Given a string `s` containing only lowercase English letters, return the number of distinct substrings that can be formed. Substrings that are repeated in the string should be counted only once. Try to achieve this in O(n^2) time complexity by considering all possible substrings ...
[ { "from": "user", "value": "Given a `k x k` `board` of cells represented by `0` (empty) and `1` (occupied), you need to find the size of the largest square sub-grid consisting entirely of `0`s. Each cell in the square must be empty, and it must form a contiguous block on the board. Return an integer represe...
[ { "from": "user", "value": "You are given two strings, `word1` and `word2`. A string `word1` can be transformed into string `word2` using the following operation: you can choose any character in `word1` and replace it with another character. The transformation cost between two characters `c1` and `c2` is de...
[ { "from": "user", "value": "Write a function to solve the following problem:\n\nYou're given two integer arrays, `arr1` and `arr2`, sorted in non-decreasing order and containing `m` and `n` elements respectively. Find the median of the two sorted arrays. The overall run-time complexity should be `O(log (m+n...
[ { "from": "user", "value": "You are given a sorted integer array `nums` that may contain duplicates, and a target value `target`. Write a function to determine the **first** and **last** position of `target` in `nums`. If `target` is not found in the array, return `[-1, -1]`. \nYour function should run in ...
[ { "from": "user", "value": "Given a list of integers `nums`, and an integer `k`, return _the length of the shortest contiguous subarray whose sum is greater than or equal to `k`. If there is no such subarray, return `0`.\n\nNote: Your solution must achieve better than O(n^2) time complexity." }, { "...
[ { "from": "user", "value": "You are given a string `s` containing only lowercase English letters. A **palindrome** is a string that reads the same backward as forward. Write a function that returns the length of the longest palindromic substring in `s`. Your implementation should have a linearithmic or bett...
[ { "from": "user", "value": "Given a string `s` and a string `t`, your task is to find the minimum window in `s` which contains all the characters from `t`. If such a window does not exist, return an empty string. If there are multiple minimal windows, return the one which starts first. \n\nNote that when th...
[ { "from": "user", "value": "Given an array of integers `arr`, return a new array `result` where `result[i]` is the product of all the elements of `arr` except `arr[i]` without using division. You must solve it in O(n) time complexity and O(1) space complexity, except for the output array `result`.\n\nExampl...
[ { "from": "user", "value": "You are tasked with designing a synchronous messaging application for a small group of users. The application uses an array of strings `messages`, where each string represents a message sent by one of the users. Each message is sent in chronological order. However, due to network...
[ { "from": "user", "value": "You are given a list of non-negative integers `nums` that represent the possible stock prices of a company. Each value in `nums` corresponds to a specific time period, with `nums[i]` representing the stock price at time `i`. Determine the maximum possible profit that can be achie...
[ { "from": "user", "value": "A company has a fleet of delivery drones. Each drone can carry a maximum weight. You are provided with an array of integers `packages` where each element represents the weight of a package and an integer `maxWeight`, which is the maximum weight a drone can carry. Your task is to ...
[ { "from": "user", "value": "You are given a **0-indexed** string `s`, where each character is either `a` or `b`. Your task is to transform `s` into a palindrome with the minimum number of character replacements. Return _the **minimum** number of replacements needed to make `s` a palindrome._ A **palindrome*...
[ { "from": "user", "value": "You are given a string `text` consisting of lowercase English letters and an integer `k`. Your task is to find and return the **length of the longest substring** of `text` that contains at most `k` distinct characters. A **substring** is a contiguous sequence of characters within...
[ { "from": "user", "value": "Given a linked list, split it into `k` consecutive linked list parts. The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null if `k` is greater than the length of the list. Return a...
[ { "from": "user", "value": "You are given an unsorted integer array `arr` of length `n` and an integer `k`. Find the `k`th largest element in the array. Note that it is the `k`th largest element in the sorted order, not the `k`th distinct element. Your task is to complete the function `findKthLargest` that ...
[ { "from": "user", "value": "You are given an array of integers `arr` and an integer `k`. The task is to find the smallest window (contiguous subarray) in the array `arr` such that the sum of the elements in this window is greater than or equal to `k`. If there is no such window, return -1. Implement a funct...
[ { "from": "user", "value": "You are given a list of airline tickets represented by pairs of departure and arrival airports `[from, to]`. Reconstruct the itinerary in order using the given list of tickets. \n\nAll of the tickets belong to a man who departs from `\"JFK\"`. Thus, the itinerary must begin with ...
[ { "from": "user", "value": "Given a directed acyclic graph (DAG) with `n` nodes labeled from `0` to `n-1`, and a list of edges where `edges[i] = [fromi, toi]` representing a directed edge from `fromi` to `toi`, return _a boolean indicating whether the graph contains a valid topological ordering_. A topologi...
[ { "from": "user", "value": "You are given a list of strings `words` where each string consists of lowercase English letters. Two strings `s1` and `s2` are said to be **similar** if: \n* They are of the same length.\n* For every letter at position `i` in `s1`, the letter at position `i` in `s2` is eithe...
[ { "from": "user", "value": "Given an array of integers `nums` sorted in non-decreasing order, and an integer `target`, find the two distinct indices `i` and `j` (0-indexed) such that `nums[i] + nums[j]` equals `target`. Return the indices as a tuple `(i, j)` where `i < j`. If no such indices exist, return `...
[ { "from": "user", "value": "Given a list of integers `nums`, find the maximum length of a contiguous subarray where the absolute difference between any two elements in this subarray is less than or equal to `k`. Write a function `maxLengthSubarray(nums: List[int], k: int) -> int` that takes in the list `num...
[ { "from": "user", "value": "Given two integers `n` and `m`, and an array `edges` where `edges[i] = [a, b]` represents an undirected edge between nodes `a` and `b`, determine if it's possible to color the nodes of the graph with two colors such that no two adjacent nodes share the same color. Return `true` i...
[ { "from": "user", "value": "You are given a string `s` consisting of only digits. You can swap two adjacent characters in the string at most once. Return the maximum number of unique substrings of length `k` that can be obtained by performing at most one swap. If it's not possible to obtain any unique subst...
[ { "from": "user", "value": "Given an array of integers `arr`, you need to return a new array `answer` such that `answer[i]` is equal to the product of all the elements of `arr` except `arr[i]`. You must solve it without using division and in `O(n)` time and space complexity." }, { "from": "assistant...
[ { "from": "user", "value": "You are given a 2D grid of integers where each entry represents the altitude of a cell. You can move up, down, left, or right from a cell, but you can only move to another cell if the altitude difference between the current cell and the next cell is at most 1. Your task is to det...
[ { "from": "user", "value": "You are given a **0-indexed** array of integers `heights` where `heights[i]` represents the height of the `i-th` tree. You can perform operations to increase the height of the trees. An operation consists of choosing an index `i` in `heights` and increasing the height of the tree...
[ { "from": "user", "value": "Write a function that takes an array of integers `nums` and an integer `k`, and returns an array of the `k` most frequent elements. The result should be sorted by frequency from highest to lowest. If there are multiple elements with the same frequency, sort them by their value in...
[ { "from": "user", "value": "You are given an array `heights` representing the heights of a collection of buildings, each corresponding to the width of `1 unit` on a 2D skyline perspective. The goal is to calculate the **maximum area** of a rectangle formed by one or more adjacent buildings in the array. The...
[ { "from": "user", "value": "You are given a `0-indexed` integer array `arr` and an integer `val`. You are allowed to perform the following operation multiple times: choose an index `i` such that `0 <= i < arr.length` and subtract `val` from `arr[i]` if `arr[i]` is greater than or equal to `val`. Return _the...
[ { "from": "user", "value": "You are given a list of `n` integers representing the heights of buildings in a city skyline. The sun rises from the left (index 0) and sets to the right (index `n-1`). A building can block the view of a shorter building to its right. Design a program to determine the number of b...
[ { "from": "user", "value": "You are given an integer array `heights` representing the height of buildings. The buildings are consecutively placed next to each other with each building occupying `1` unit of width. There is a requirement to arrange banners of unit width on the rooftops of some buildings. The ...
[ { "from": "user", "value": "You are given a string `text` consisting of lowercase English letters and a string `pattern` also consisting of lowercase English letters. Your task is to find the length of the shortest substring in `text` that contains all the characters in `pattern` (including duplicates). If ...
[ { "from": "user", "value": "Given a string `log` consisting of characters 'U' (uphill), 'D' (downhill), and '_' (flat terrain), representing a path in a mountain hiking trail. Determine the number of valleys encountered during the hike. A valley is defined as any sequence of consecutive steps below sea leve...
[ { "from": "user", "value": "Given two sorted arrays `nums1` and `nums2` of size `m` and `n`, respectively, return the median of the two sorted arrays. The overall run-time complexity should be `O(log (m+n))`. You may assume `nums1` and `nums2` cannot be both empty.\n\nImplement a function:\n\n```python\ndef...
[ { "from": "user", "value": "You are given an m x n binary matrix 'grid'. An island is a group of connected `1`s (connected horizontally or vertically). The grid is completely surrounded by `0`s, and there is exactly one island in the grid. The island does not have any \"lakes\", meaning the `1`s inside the ...
[ { "from": "user", "value": "You are given an array `arr` of integers where each element appears exactly twice, except for one element which appears exactly once. Return the element that appears only once. You must solve the problem in linear time and without using extra space that grows with the input size....
[ { "from": "user", "value": "You are given an array of integers `nums` and an integer `k`. A **subarray** is a contiguous part of an array. A subarray is called **good** if there are **at least** `k` different integers in the subarray. Return the number of **good** subarrays of `nums`. Since the number of su...
[ { "from": "user", "value": "Given an `n x n` 2D matrix `a` containing integers, rotate the matrix 90 degrees clockwise in place. This means you need to modify the input matrix within the same memory, without using a separate 2D matrix for the rotation. You can achieve this by first transposing the matrix, a...
[ { "from": "user", "value": "Given a string representing an arithmetic expression that contains non-negative integers, addition `'+'`, subtraction `'-'`, multiplication `'*'`, and division `'/'`, implement a function to compute the result. Note that:\n\n* Division is integer division, where the result is the...
[ { "from": "user", "value": "You are given a list of `courses` as `course_list` where each course is a pair of two integers `[a, b]` representing a course `a` that you want to take and a prerequisite course `b` that you must take before `a`. Given a total of `num_courses` courses, define whether it is possib...
[ { "from": "user", "value": "You are given an array of integers `nums` representing a permutation of the numbers from 1 to `n`. You need to reconstruct and return the lexicographically smallest permutation of the numbers from 1 to `n` that a given array `nums` can be rearranged into by swapping two adjacent ...
[ { "from": "user", "value": "You are given a list of `n` strings `words` where each string consists of lowercase alphabetical characters. You are also given a string `pattern` that you need to search for within the list. A word in `words` matches the pattern if swapping certain characters in the word can mak...
[ { "from": "user", "value": "You are given a list of **weighted edges** representing an undirected graph and an integer `n`, which corresponds to the number of nodes (numbered from `0` to `n-1`). Each edge is represented as a triplet `[u, v, w]` where `u` and `v` denote the two nodes the edge connects, and `...
[ { "from": "user", "value": "You are given a list of `n` integers, where `n` is larger than or equal to `3`, representing the vertices of a potential triangle. Your task is to find the maximum perimeter of a non-degenerate triangle that can be formed with the given integers. A triangle is non-degenerate if a...
[ { "from": "user", "value": "You are given a **0-indexed** string `s` comprising only digits, and a positive integer `k`. You need to determine the **smallest** integer that can be obtained by removing exactly `k` digits from `s`. The result should preserve the relative order of the digits in `s`. \n\nFor ex...
[ { "from": "user", "value": "You are given a sequence of integers where each integer appears exactly twice, except for one element that appears exactly once. Write a function to find the element that appears exactly once within the sequence. Your solution should have a linear runtime complexity and use only ...
[ { "from": "user", "value": "Given two strings `s` and `t` consisting of only lowercase alphabets, write a function to determine if `s` can be transformed into `t` by performing at most one edit. An edit is defined as:\n1. Inserting a character\n2. Removing a character\n3. Replacing a character" }, { ...
[ { "from": "user", "value": "Given a grid of size `n x n` filled with positive integers, you are allowed to move either right or down from any cell, starting from the top-left corner. Write a function to find the minimum path sum from the top-left corner to the bottom-right corner of the grid. Return the min...
[ { "from": "user", "value": "You are given a **0-indexed** string `word`, consisting of lowercase English letters. You need to perform **cyclic shifts** on the string. A cyclic shift moves the last character of the string to the front, the second last character to the second position, and so forth. Given an ...
[ { "from": "user", "value": "Given a matrix `mat` containing integers where each row is sorted in ascending order from left to right and each column is sorted in ascending order from top to bottom, write a function that searches for a target integer `x` and returns a tuple of its coordinates (row, column) if...
[ { "from": "user", "value": "You are given a **0-indexed** integer array `nums` and an integer `threshold`. You need to find a **positive integer divisor** `d` such that, when every element in the array is divided by `d` and rounded up to the nearest integer, the sum of those resulting values is less than or...
[ { "from": "user", "value": "You are given a string `s` consisting of lowercase English letters and an integer `k`. A **k-length substring** of `s` is any substring with exactly `k` characters. Return _the number of distinct **k-length substrings** of `s`_. If `k` is greater than the length of `s`, return `0...
[ { "from": "user", "value": "You are given a **0-indexed** integer array `heights` where `heights[i]` represents the height of the `i`-th tree in a row of trees. A tree is considered **visible** if there are no taller or equal height trees to its right. Return _the number of visible trees_.\n\nNote: A tree t...
[ { "from": "user", "value": "Given a string `s` and an array of integers `indices` of the same length, transform the string according to the following rule: for every valid index `i`, the character `s[i]` should be moved to `indices[i]`. Return the transformed string. It is guaranteed that the given indices ...
[ { "from": "user", "value": "A company conducts a ping-pong tournament where `n` players compete against each other. Each player is assigned a unique ID from `1` to `n`. You are given the results of the matches in an array `matches`, where `matches[i] = [winneri, loseri]` indicates that player `winneri` defe...
[ { "from": "user", "value": "You are given two **0-indexed** integer arrays `startTime` and `endTime` representing the start and end times of `n` intervals, where `startTime[i]` and `endTime[i]` denote the start and end of the `i-th` interval, respectively. An interval `[a, b)` overlaps an interval `[c, d)` ...
[ { "from": "user", "value": "You are given an array `events` where each event occurs at a specific time `t`. Each entry in the array `events` is a pair of integers `[startTime, endTime]` which represents an event that starts at `startTime` and ends at `endTime`. A person can attend an event if their current ...
[ { "from": "user", "value": "Given an integer array `nums`, return an array `result` of length `nums.length` where `result[i]` is the number of distinct elements in the subarray `nums[i...len(nums)-1]` (0-indexed) with the last element always being `nums[len(nums)-1]`. A **subarray** is a contiguous non-empt...
[ { "from": "user", "value": "You are given an integer array `nums` and an integer `k`. We call an array interval a contiguous subarray containing `k` elements. `k`-interval sum is the sum of the elements within that interval. Create a function that returns the maximum `k`-interval sum in the `nums` array. If...
[ { "from": "user", "value": "Given a `m x n` grid containing integers, you need to find the maximum sum of any rectangle within the grid. The rectangle must be made up of at least one element. Your task is to write a function that returns the maximum possible sum considering all possible rectangles that can ...
[ { "from": "user", "value": "You are given an integer array `arr` of length `n` and an integer `m`. Your task is to find the **minimum length of a contiguous subarray** of `arr` whose **sum** is **greater than or equal** to `m`. If there is no such subarray, return `0`. \n\nFor example, given `arr = [2, 1, 5...
[ { "from": "user", "value": "You are given a list of integers `nums` and a target integer `target`. Each integer in `nums` represents a different coin denomination, and you can use each coin denomination an unlimited number of times. Return the minimum number of coins required to make the `target` amount. If...
[ { "from": "user", "value": "Given an integer array `nums` and an integer `k`, return the maximum sum of `k` consecutive elements in the array. If `nums` has fewer than `k` elements, return `-1`. Try to solve the problem in O(n) time complexity." }, { "from": "assistant", "value": "<think>\nOkay,...
[ { "from": "user", "value": "You are given a `0-indexed` integer array `elevations` of length `n` where `elevations[i]` denotes the elevation level of the `i-th` location in a sequence of mountains. You are to build a road such that it starts at any location and ends at any location, forming a contiguous pat...
[ { "from": "user", "value": "Given an array of integers `heights` representing the heights of students in a line. Each student can see the scenery if there are no taller students directly standing in front of them. Return the number of students that can see the scenery. A student is considered as seeing the ...
[ { "from": "user", "value": "You are given a string `s` consisting of lowercase letters, and you are tasked with finding the lexicographically smallest subsequence of `s` that contains all the distinct characters of `s` exactly once. \n\nTo solve this problem, implement the function `smallestSubsequence(s: s...
[ { "from": "user", "value": "You are given a string `s` and an array of indices `indices`. `indices` is a permutation of numbers from `0` to `s.length - 1`. You need to shuffle the string such that the character at the `i`-th position moves to `indices[i]` in the shuffled string. Return the shuffled string."...
[ { "from": "user", "value": "Given a list of `n` integers and an integer `k`, partition the list such that: \n- All elements less than `k` come before elements equal to `k`, which must come before elements greater than `k`. \n- Relative ordering of elements in each partition should be preserved. \n\nReturn t...
[ { "from": "user", "value": "You are given a string `inputStr` consisting of alphanumeric characters and symbols. A **valid password** is defined as one that meets the following criteria:\n- Contains at least one uppercase letter.\n- Contains at least one lowercase letter.\n- Contains at least one digit.\n- ...
[ { "from": "user", "value": "Given an integer array `nums`, move all `0`s to the end of the array while maintaining the relative order of the non-zero elements. _Modify the array in-place and do not return anything from your function._" }, { "from": "assistant", "value": "<think>\nOkay, I've got ...
[ { "from": "user", "value": "You are given a 2D integer matrix `grid` of size `m x n` and an integer `threshold`. Each cell in the `grid` represents the elevation of a point within a region. A region is defined as a group of connected cells with elevation values greater or equal to `threshold`. Two cells are...
[ { "from": "user", "value": "A **peak element** in an array is an element that is strictly greater than its neighbors. Given an integer array `nums`, where 1 ≤ `nums.length` ≤ 1000, find a **peak element** and return its index. The array may contain multiple peak elements, in that case return the index to an...
[ { "from": "user", "value": "Given a string `s` containing only lowercase letters, find and return the first non-repeating character in `s`. If all characters are repeating, return '_'." }, { "from": "assistant", "value": "<think>\nOkay, I need to solve this problem where I have to find the first...
[ { "from": "user", "value": "You are given an integer array `cars`, where `cars[i]` represents the speed of the `i-th` car in a race. The ranking of cars in the race is defined such that the car with a higher speed ranks higher. If two cars have the same speed, they tie and share the same rank. Your task is ...
[ { "from": "user", "value": "Given an array `arr` of integers where every integer appears an even number of times except for exactly **two** integers which appear an odd number of times, return _the two integers that appear an odd number of times_. The result should be in ascending order. You should implemen...
[ { "from": "user", "value": "Given a list of `n` integers, `arr`, and an integer `m`, shift the elements of the list to the right by `m` positions without using any extra space (in-place). If `m` is larger than `n`, you should consider `m = m % n`. Return the modified list after the shift." }, { "fro...
[ { "from": "user", "value": "You are given a string `instructions` consisting only of the characters `'G'`, `'L'`, and `'R'`. `'G'` means go straight 1 unit, `'L'` means turn 90 degrees to the left, and `'R'` means turn 90 degrees to the right. The robot starts at `(0, 0)` facing north. Your task is to deter...
[ { "from": "user", "value": "You are given two strings `s` and `t` consisting of lowercase letters. You can select any substring of `s` and rearrange the characters in that substring. Determine if you can transform `s` into `t` by applying the aforementioned operation at most once. Return `true` if it is pos...
[ { "from": "user", "value": "You are given a string `s` consisting of lowercase English letters. You need to find the longest substring containing only unique characters and return its length. If the string is empty, return 0. Your task is to implement a function that executes this requirement efficiently." ...
[ { "from": "user", "value": "You are given a 2D integer array `grid` consisting of `0`s and `1`s. A cell is called **lucky** if in its row and column there is no other `1` present. Return _a list of all lucky cells' coordinates_ where each coordinate is represented as a list `[r, c]` in **ascending order** b...
[ { "from": "user", "value": "You are given an array of integers `heights` representing a landscape, where `heights[i]` is the height of the point `i`. Rainwater will be trapped between the heights. Your task is to compute the maximum amount of water that can be trapped after raining. The water is only trappe...