slug_name stringlengths 6 77 | meta_info dict | id stringlengths 1 4 | difficulty stringclasses 3 values | pretty_content listlengths 0 1 | solutions listlengths 2 121 | prompt stringlengths 107 1.32k | generator_code stringclasses 1 value | convert_online stringclasses 1 value | convert_offline stringclasses 1 value | evaluate_offline stringclasses 1 value | entry_point stringclasses 1 value | test_cases stringclasses 1 value | acRate float64 13.8 89.6 | Difficulty Level stringclasses 5 values | demons stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
convert-1d-array-into-2d-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> 1-dimensional (1D) integer array <code>original</code>, and two integers, <code>m</code> and <code>n</code>. You are tasked with creating a 2-dimensional (2D) array with <code> m</code> rows and <code>n</code> columns using <strong>all</strong> the elements from <code>original</code>.</p>\n\n<p>The elements from indices <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>) of <code>original</code> should form the first row of the constructed 2D array, the elements from indices <code>n</code> to <code>2 * n - 1</code> (<strong>inclusive</strong>) should form the second row of the constructed 2D array, and so on.</p>\n\n<p>Return <em>an </em><code>m x n</code><em> 2D array constructed according to the above procedure, or an empty 2D array if it is impossible</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img src=\"https://assets.leetcode.com/uploads/2021/08/26/image-20210826114243-1.png\" style=\"width: 500px; height: 174px;\" />\n<pre>\n<strong>Input:</strong> original = [1,2,3,4], m = 2, n = 2\n<strong>Output:</strong> [[1,2],[3,4]]\n<strong>Explanation:</strong> The constructed 2D array should contain 2 rows and 2 columns.\nThe first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.\nThe second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> original = [1,2,3], m = 1, n = 3\n<strong>Output:</strong> [[1,2,3]]\n<strong>Explanation:</strong> The constructed 2D array should contain 1 row and 3 columns.\nPut all three elements in original into the first row of the constructed 2D array.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> original = [1,2], m = 1, n = 1\n<strong>Output:</strong> []\n<strong>Explanation:</strong> There are 2 elements in original.\nIt is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= original.length <= 5 * 10<sup>4</sup></code></li>\n\t<li><code>1 <= original[i] <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= m, n <= 4 * 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2022",
"questionId": "2132",
"questionTitle": "Convert 1D Array Into 2D Array",
"questionTitleSlug": "convert-1d-array-into-2d-array",
"similarQuestions": "[{\"title\": \"Reshape the Matrix\", \"titleSlug\": \"reshape-the-matrix\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"71.9K\", \"totalSubmission\": \"119K\", \"totalAcceptedRaw\": 71909, \"totalSubmissionRaw\": 118958, \"acRate\": \"60.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Matrix",
"slug": "matrix"
},
{
"name": "Simulation",
"slug": "simulation"
}
]
}
}
} | 2022 | Easy | [
"You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original.\n\nThe elements from indices 0 to n - 1 (inclusive) of original should form the first row of the c... | [
{
"hash": 6798023042220047000,
"runtime": "869ms",
"solution": "class Solution(object):\n def construct2DArray(self, original, m, n):\n \"\"\"\n :type original: List[int]\n :type m: int\n :type n: int\n :rtype: List[List[int]]\n \"\"\"\n \n if m... | class Solution(object):
def construct2DArray(self, original, m, n):
"""
:type original: List[int]
:type m: int
:type n: int
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 60.4 | Level 1 | Hi |
count-elements-with-strictly-smaller-and-greater-elements | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code>, return <em>the number of elements that have <strong>both</strong> a strictly smaller and a strictly greater element appear in </em><code>nums</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [11,7,2,15]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.\nElement 11 has element 7 strictly smaller than it and element 15 strictly greater than it.\nIn total there are 2 elements having both a strictly smaller and a strictly greater element appear in <code>nums</code>.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-3,3,3,90]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The element 3 has the element -3 strictly smaller than it and the element 90 strictly greater than it.\nSince there are two elements with the value 3, in total there are 2 elements having both a strictly smaller and a strictly greater element appear in <code>nums</code>.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 100</code></li>\n\t<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2148",
"questionId": "2269",
"questionTitle": "Count Elements With Strictly Smaller and Greater Elements ",
"questionTitleSlug": "count-elements-with-strictly-smaller-and-greater-elements",
"similarQuestions": "[{\"title\": \"Find Smallest Letter Greater Than Target\", \"titleSlug\": \"find-smallest-letter-greater-than-target\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"51.6K\", \"totalSubmission\": \"86.9K\", \"totalAcceptedRaw\": 51573, \"totalSubmissionRaw\": 86884, \"acRate\": \"59.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2148 | Easy | [
"Given an integer array nums, return the number of elements that have both a strictly smaller and a strictly greater element appear in nums.\n\n \nExample 1:\n\nInput: nums = [11,7,2,15]\nOutput: 2\nExplanation: The element 7 has the element 2 strictly smaller than it and the element 11 strictly greater than it.\nE... | [
{
"hash": 8296767120513950000,
"runtime": "36ms",
"solution": "class Solution(object):\n def countElements(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n res = 0\n for i in nums:\n if min(nums)<i and max(nums)>i:\n ... | class Solution(object):
def countElements(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 59.4 | Level 1 | Hi |
random-pick-with-weight | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array of positive integers <code>w</code> where <code>w[i]</code> describes the <strong>weight</strong> of the <code>i<sup>th</sup></code> index.</p>\n\n<p>You need to implement the function <code>pickIndex()</code>, which <strong>randomly</strong> picks an index in the range <code>[0, w.length - 1]</code> (<strong>inclusive</strong>) and returns it. The <strong>probability</strong> of picking an index <code>i</code> is <code>w[i] / sum(w)</code>.</p>\n\n<ul>\n\t<li>For example, if <code>w = [1, 3]</code>, the probability of picking index <code>0</code> is <code>1 / (1 + 3) = 0.25</code> (i.e., <code>25%</code>), and the probability of picking index <code>1</code> is <code>3 / (1 + 3) = 0.75</code> (i.e., <code>75%</code>).</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["Solution","pickIndex"]\n[[[1]],[]]\n<strong>Output</strong>\n[null,0]\n\n<strong>Explanation</strong>\nSolution solution = new Solution([1]);\nsolution.pickIndex(); // return 0. The only option is to return 0 since there is only one element in w.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["Solution","pickIndex","pickIndex","pickIndex","pickIndex","pickIndex"]\n[[[1,3]],[],[],[],[],[]]\n<strong>Output</strong>\n[null,1,1,1,1,0]\n\n<strong>Explanation</strong>\nSolution solution = new Solution([1, 3]);\nsolution.pickIndex(); // return 1. It is returning the second element (index = 1) that has a probability of 3/4.\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 1\nsolution.pickIndex(); // return 0. It is returning the first element (index = 0) that has a probability of 1/4.\n\nSince this is a randomization problem, multiple answers are allowed.\nAll of the following outputs can be considered correct:\n[null,1,1,1,1,0]\n[null,1,1,1,1,1]\n[null,1,1,1,0,0]\n[null,1,1,1,0,1]\n[null,1,0,1,0,0]\n......\nand so on.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= w.length <= 10<sup>4</sup></code></li>\n\t<li><code>1 <= w[i] <= 10<sup>5</sup></code></li>\n\t<li><code>pickIndex</code> will be called at most <code>10<sup>4</sup></code> times.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "528",
"questionId": "912",
"questionTitle": "Random Pick with Weight",
"questionTitleSlug": "random-pick-with-weight",
"similarQuestions": "[{\"title\": \"Random Pick Index\", \"titleSlug\": \"random-pick-index\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Random Pick with Blacklist\", \"titleSlug\": \"random-pick-with-blacklist\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Random Point in Non-overlapping Rectangles\", \"titleSlug\": \"random-point-in-non-overlapping-rectangles\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"398.4K\", \"totalSubmission\": \"860K\", \"totalAcceptedRaw\": 398351, \"totalSubmissionRaw\": 859997, \"acRate\": \"46.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Binary Search",
"slug": "binary-search"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
},
{
"name": "Randomized",
"slug": "randomized"
}
]
}
}
} | 528 | Medium | [
"You are given a 0-indexed array of positive integers w where w[i] describes the weight of the ith index.\n\nYou need to implement the function pickIndex(), which randomly picks an index in the range [0, w.length - 1] (inclusive) and returns it. The probability of picking an index i is w[i] / sum(w).\n\n\n\tFor exa... | [
{
"hash": 8700684830926317000,
"runtime": "1040ms",
"solution": "class Solution(object):\n\n def __init__(self, w):\n \"\"\"\n :type w: List[int]\n \"\"\"\n self.prefix_sums = []\n prefix_sum = 0\n for weight in w:\n prefix_sum += weight\n ... | class Solution(object):
def __init__(self, w):
"""
:type w: List[int]
"""
def pickIndex(self):
"""
:rtype: int
"""
# Your Solution object will be instantiated and called as such:
# obj = Solution(w)
# param_1 = obj.pickIndex()
| None | None | None | None | None | None | 46.3 | Level 4 | Hi |
student-attendance-record-i | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code> representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:</p>\n\n<ul>\n\t<li><code>'A'</code>: Absent.</li>\n\t<li><code>'L'</code>: Late.</li>\n\t<li><code>'P'</code>: Present.</li>\n</ul>\n\n<p>The student is eligible for an attendance award if they meet <strong>both</strong> of the following criteria:</p>\n\n<ul>\n\t<li>The student was absent (<code>'A'</code>) for <strong>strictly</strong> fewer than 2 days <strong>total</strong>.</li>\n\t<li>The student was <strong>never</strong> late (<code>'L'</code>) for 3 or more <strong>consecutive</strong> days.</li>\n</ul>\n\n<p>Return <code>true</code><em> if the student is eligible for an attendance award, or </em><code>false</code><em> otherwise</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "PPALLP"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> The student has fewer than 2 absences and was never late 3 or more consecutive days.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "PPALLL"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> The student was late 3 consecutive days in the last 3 days, so is not eligible for the award.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 1000</code></li>\n\t<li><code>s[i]</code> is either <code>'A'</code>, <code>'L'</code>, or <code>'P'</code>.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "551",
"questionId": "551",
"questionTitle": "Student Attendance Record I",
"questionTitleSlug": "student-attendance-record-i",
"similarQuestions": "[{\"title\": \"Student Attendance Record II\", \"titleSlug\": \"student-attendance-record-ii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"196.9K\", \"totalSubmission\": \"405.8K\", \"totalAcceptedRaw\": 196913, \"totalSubmissionRaw\": 405801, \"acRate\": \"48.5%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
}
]
}
}
} | 551 | Easy | [
"You are given a string s representing an attendance record for a student where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:\n\n\n\t'A': Absent.\n\t'L': Late.\n\t'P': Present.\n\n\nThe student is eligible for an atten... | [
{
"hash": 4820777532749193000,
"runtime": "6ms",
"solution": "class Solution(object):\n def checkRecord(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"\n d = {}\n for i in s:\n if i in d:\n d[i] += 1\n else:\n ... | class Solution(object):
def checkRecord(self, s):
"""
:type s: str
:rtype: bool
"""
| None | None | None | None | None | None | 48.5 | Level 1 | Hi |
find-the-width-of-columns-of-a-grid | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> <code>m x n</code> integer matrix <code>grid</code>. The width of a column is the maximum <strong>length </strong>of its integers.</p>\n\n<ul>\n\t<li>For example, if <code>grid = [[-10], [3], [12]]</code>, the width of the only column is <code>3</code> since <code>-10</code> is of length <code>3</code>.</li>\n</ul>\n\n<p>Return <em>an integer array</em> <code>ans</code> <em>of size</em> <code>n</code> <em>where</em> <code>ans[i]</code> <em>is the width of the</em> <code>i<sup>th</sup></code> <em>column</em>.</p>\n\n<p>The <strong>length</strong> of an integer <code>x</code> with <code>len</code> digits is equal to <code>len</code> if <code>x</code> is non-negative, and <code>len + 1</code> otherwise.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> grid = [[1],[22],[333]]\n<strong>Output:</strong> [3]\n<strong>Explanation:</strong> In the 0<sup>th</sup> column, 333 is of length 3.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> grid = [[-15,1,3],[15,7,12],[5,6,-2]]\n<strong>Output:</strong> [3,1,2]\n<strong>Explanation:</strong> \nIn the 0<sup>th</sup> column, only -15 is of length 3.\nIn the 1<sup>st</sup> column, all integers are of length 1. \nIn the 2<sup>nd</sup> column, both 12 and -2 are of length 2.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 <= m, n <= 100 </code></li>\n\t<li><code>-10<sup>9</sup> <= grid[r][c] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2639",
"questionId": "2675",
"questionTitle": "Find the Width of Columns of a Grid",
"questionTitleSlug": "find-the-width-of-columns-of-a-grid",
"similarQuestions": "[{\"title\": \"Next Greater Numerically Balanced Number\", \"titleSlug\": \"next-greater-numerically-balanced-number\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"23.2K\", \"totalSubmission\": \"35.1K\", \"totalAcceptedRaw\": 23230, \"totalSubmissionRaw\": 35107, \"acRate\": \"66.2%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 2639 | Easy | [
"You are given a 0-indexed m x n integer matrix grid. The width of a column is the maximum length of its integers.\n\n\n\tFor example, if grid = [[-10], [3], [12]], the width of the only column is 3 since -10 is of length 3.\n\n\nReturn an integer array ans of size n where ans[i] is the width of the ith column.\n\n... | [
{
"hash": 481931849028665600,
"runtime": "93ms",
"solution": "class Solution(object):\n def findColumnWidth(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: List[int]\n \"\"\"\n m=len(grid)\n n=len(grid[0])\n ans=[]\n for i in range... | class Solution(object):
def findColumnWidth(self, grid):
"""
:type grid: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 66.2 | Level 1 | Hi |
minimum-operations-to-make-a-special-number | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> string <code>num</code> representing a non-negative integer.</p>\n\n<p>In one operation, you can pick any digit of <code>num</code> and delete it. Note that if you delete all the digits of <code>num</code>, <code>num</code> becomes <code>0</code>.</p>\n\n<p>Return <em>the <strong>minimum number of operations</strong> required to make</em> <code>num</code> <i>special</i>.</p>\n\n<p>An integer <code>x</code> is considered <strong>special</strong> if it is divisible by <code>25</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> num = "2245047"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Delete digits num[5] and num[6]. The resulting number is "22450" which is special since it is divisible by 25.\nIt can be shown that 2 is the minimum number of operations required to get a special number.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> num = "2908305"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> Delete digits num[3], num[4], and num[6]. The resulting number is "2900" which is special since it is divisible by 25.\nIt can be shown that 3 is the minimum number of operations required to get a special number.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> num = "10"\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> Delete digit num[0]. The resulting number is "0" which is special since it is divisible by 25.\nIt can be shown that 1 is the minimum number of operations required to get a special number.\n\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= num.length <= 100</code></li>\n\t<li><code>num</code> only consists of digits <code>'0'</code> through <code>'9'</code>.</li>\n\t<li><code>num</code> does not contain any leading zeros.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2844",
"questionId": "3046",
"questionTitle": "Minimum Operations to Make a Special Number",
"questionTitleSlug": "minimum-operations-to-make-a-special-number",
"similarQuestions": "[{\"title\": \"Remove K Digits\", \"titleSlug\": \"remove-k-digits\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Remove Digit From Number to Maximize Result\", \"titleSlug\": \"remove-digit-from-number-to-maximize-result\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"23.3K\", \"totalSubmission\": \"62.4K\", \"totalAcceptedRaw\": 23312, \"totalSubmissionRaw\": 62416, \"acRate\": \"37.3%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Enumeration",
"slug": "enumeration"
}
]
}
}
} | 2844 | Medium | [
"You are given a 0-indexed string num representing a non-negative integer.\n\nIn one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.\n\nReturn the minimum number of operations required to make num special.\n\nAn integer x is considered special if... | [
{
"hash": -7389505197678562000,
"runtime": "25ms",
"solution": "class Solution(object):\n def minimumOperations(self, num):\n amount_0 = 0\n digit_flag = False\n end_flag = False\n num = '0' + num\n for digit in num[ : : -1]:\n if not end_flag:\n ... | class Solution(object):
def minimumOperations(self, num):
"""
:type num: str
:rtype: int
"""
| None | None | None | None | None | None | 37.3 | Level 4 | Hi |
shortest-cycle-in-a-graph | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a <strong>bi-directional </strong>graph with <code>n</code> vertices, where each vertex is labeled from <code>0</code> to <code>n - 1</code>. The edges in the graph are represented by a given 2D integer array <code>edges</code>, where <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> denotes an edge between vertex <code>u<sub>i</sub></code> and vertex <code>v<sub>i</sub></code>. Every vertex pair is connected by at most one edge, and no vertex has an edge to itself.</p>\n\n<p>Return <em>the length of the <strong>shortest </strong>cycle in the graph</em>. If no cycle exists, return <code>-1</code>.</p>\n\n<p>A cycle is a path that starts and ends at the same node, and each edge in the path is used only once.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/01/04/cropped.png\" style=\"width: 387px; height: 331px;\" />\n<pre>\n<strong>Input:</strong> n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The cycle with the smallest length is : 0 -> 1 -> 2 -> 0 \n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/01/04/croppedagin.png\" style=\"width: 307px; height: 307px;\" />\n<pre>\n<strong>Input:</strong> n = 4, edges = [[0,1],[0,2]]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> There are no cycles in this graph.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>1 <= edges.length <= 1000</code></li>\n\t<li><code>edges[i].length == 2</code></li>\n\t<li><code>0 <= u<sub>i</sub>, v<sub>i</sub> < n</code></li>\n\t<li><code>u<sub>i</sub> != v<sub>i</sub></code></li>\n\t<li>There are no repeated edges.</li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "2608",
"questionId": "2671",
"questionTitle": "Shortest Cycle in a Graph",
"questionTitleSlug": "shortest-cycle-in-a-graph",
"similarQuestions": "[{\"title\": \"Redundant Connection\", \"titleSlug\": \"redundant-connection\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Longest Cycle in a Graph\", \"titleSlug\": \"longest-cycle-in-a-graph\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Divide Nodes Into the Maximum Number of Groups\", \"titleSlug\": \"divide-nodes-into-the-maximum-number-of-groups\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"14.3K\", \"totalSubmission\": \"39.1K\", \"totalAcceptedRaw\": 14341, \"totalSubmissionRaw\": 39105, \"acRate\": \"36.7%\"}",
"topicTags": [
{
"name": "Breadth-First Search",
"slug": "breadth-first-search"
},
{
"name": "Graph",
"slug": "graph"
}
]
}
}
} | 2608 | Hard | [
"There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge between vertex ui and vertex vi. Every vertex pair is connected by at most one edge, and no vertex has a... | [
{
"hash": 1731721897637424400,
"runtime": "1974ms",
"solution": "class Solution:\n def findShortestCycle(self, n, edges):\n adj = [[] for _ in range(n)]\n for e in edges:\n adj[e[0]].append(e[1])\n adj[e[1]].append(e[0])\n\n min_cycle = n + 1\n for i ... | class Solution(object):
def findShortestCycle(self, n, edges):
"""
:type n: int
:type edges: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 36.7 | Level 5 | Hi |
decode-xored-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a <strong>hidden</strong> integer array <code>arr</code> that consists of <code>n</code> non-negative integers.</p>\n\n<p>It was encoded into another integer array <code>encoded</code> of length <code>n - 1</code>, such that <code>encoded[i] = arr[i] XOR arr[i + 1]</code>. For example, if <code>arr = [1,0,2,1]</code>, then <code>encoded = [1,2,3]</code>.</p>\n\n<p>You are given the <code>encoded</code> array. You are also given an integer <code>first</code>, that is the first element of <code>arr</code>, i.e. <code>arr[0]</code>.</p>\n\n<p>Return <em>the original array</em> <code>arr</code>. It can be proved that the answer exists and is unique.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> encoded = [1,2,3], first = 1\n<strong>Output:</strong> [1,0,2,1]\n<strong>Explanation:</strong> If arr = [1,0,2,1], then first = 1 and encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> encoded = [6,2,7,3], first = 4\n<strong>Output:</strong> [4,2,0,7,4]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 10<sup>4</sup></code></li>\n\t<li><code>encoded.length == n - 1</code></li>\n\t<li><code>0 <= encoded[i] <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= first <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1720",
"questionId": "1839",
"questionTitle": "Decode XORed Array",
"questionTitleSlug": "decode-xored-array",
"similarQuestions": "[{\"title\": \"Find The Original Array of Prefix Xor\", \"titleSlug\": \"find-the-original-array-of-prefix-xor\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"135K\", \"totalSubmission\": \"157K\", \"totalAcceptedRaw\": 134968, \"totalSubmissionRaw\": 157030, \"acRate\": \"86.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Bit Manipulation",
"slug": "bit-manipulation"
}
]
}
}
} | 1720 | Easy | [
"There is a hidden integer array arr that consists of n non-negative integers.\n\nIt was encoded into another integer array encoded of length n - 1, such that encoded[i] = arr[i] XOR arr[i + 1]. For example, if arr = [1,0,2,1], then encoded = [1,2,3].\n\nYou are given the encoded array. You are also given an intege... | [
{
"hash": 462600336965689660,
"runtime": "168ms",
"solution": "class Solution(object):\n def decode(self, encoded, first):\n \"\"\"\n :type encoded: List[int]\n :type first: int\n :rtype: List[int]\n \"\"\"\n\n encoded = [first] + encoded\n\n for i in ... | class Solution(object):
def decode(self, encoded, first):
"""
:type encoded: List[int]
:type first: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 86 | Level 1 | Hi |
find-all-people-with-secret | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer <code>n</code> indicating there are <code>n</code> people numbered from <code>0</code> to <code>n - 1</code>. You are also given a <strong>0-indexed</strong> 2D integer array <code>meetings</code> where <code>meetings[i] = [x<sub>i</sub>, y<sub>i</sub>, time<sub>i</sub>]</code> indicates that person <code>x<sub>i</sub></code> and person <code>y<sub>i</sub></code> have a meeting at <code>time<sub>i</sub></code>. A person may attend <strong>multiple meetings</strong> at the same time. Finally, you are given an integer <code>firstPerson</code>.</p>\n\n<p>Person <code>0</code> has a <strong>secret</strong> and initially shares the secret with a person <code>firstPerson</code> at time <code>0</code>. This secret is then shared every time a meeting takes place with a person that has the secret. More formally, for every meeting, if a person <code>x<sub>i</sub></code> has the secret at <code>time<sub>i</sub></code>, then they will share the secret with person <code>y<sub>i</sub></code>, and vice versa.</p>\n\n<p>The secrets are shared <strong>instantaneously</strong>. That is, a person may receive the secret and share it with people in other meetings within the same time frame.</p>\n\n<p>Return <em>a list of all the people that have the secret after all the meetings have taken place. </em>You may return the answer in <strong>any order</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1\n<strong>Output:</strong> [0,1,2,3,5]\n<strong>Explanation:\n</strong>At time 0, person 0 shares the secret with person 1.\nAt time 5, person 1 shares the secret with person 2.\nAt time 8, person 2 shares the secret with person 3.\nAt time 10, person 1 shares the secret with person 5.\nThus, people 0, 1, 2, 3, and 5 know the secret after all the meetings.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3\n<strong>Output:</strong> [0,1,3]\n<strong>Explanation:</strong>\nAt time 0, person 0 shares the secret with person 3.\nAt time 2, neither person 1 nor person 2 know the secret.\nAt time 3, person 3 shares the secret with person 0 and person 1.\nThus, people 0, 1, and 3 know the secret after all the meetings.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1\n<strong>Output:</strong> [0,1,2,3,4]\n<strong>Explanation:</strong>\nAt time 0, person 0 shares the secret with person 1.\nAt time 1, person 1 shares the secret with person 2, and person 2 shares the secret with person 3.\nNote that person 2 can share the secret at the same time as receiving it.\nAt time 2, person 3 shares the secret with person 4.\nThus, people 0, 1, 2, 3, and 4 know the secret after all the meetings.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= meetings.length <= 10<sup>5</sup></code></li>\n\t<li><code>meetings[i].length == 3</code></li>\n\t<li><code>0 <= x<sub>i</sub>, y<sub>i </sub><= n - 1</code></li>\n\t<li><code>x<sub>i</sub> != y<sub>i</sub></code></li>\n\t<li><code>1 <= time<sub>i</sub> <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= firstPerson <= n - 1</code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "2092",
"questionId": "2213",
"questionTitle": "Find All People With Secret",
"questionTitleSlug": "find-all-people-with-secret",
"similarQuestions": "[{\"title\": \"Reachable Nodes In Subdivided Graph\", \"titleSlug\": \"reachable-nodes-in-subdivided-graph\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"23.7K\", \"totalSubmission\": \"69.3K\", \"totalAcceptedRaw\": 23708, \"totalSubmissionRaw\": 69296, \"acRate\": \"34.2%\"}",
"topicTags": [
{
"name": "Depth-First Search",
"slug": "depth-first-search"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search"
},
{
"name": "Union Find",
"slug": "union-find"
},
{
"name": "Graph",
"slug": "graph"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2092 | Hard | [
"You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi have a meeting at timei. A person may attend multiple meetings at the same time. Finally, you are gi... | [
{
"hash": 6836467366817438000,
"runtime": "2165ms",
"solution": "class Solution(object):\n def findAllPeople(self, n, meetings, firstPerson):\n \"\"\"\n :type n: int\n :type meetings: List[List[int]]\n :type firstPerson: int\n :rtype: List[int]\n \"\"\"\n\n ... | class Solution(object):
def findAllPeople(self, n, meetings, firstPerson):
"""
:type n: int
:type meetings: List[List[int]]
:type firstPerson: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 34.2 | Level 5 | Hi |
reward-top-k-students | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two string arrays <code>positive_feedback</code> and <code>negative_feedback</code>, containing the words denoting positive and negative feedback, respectively. Note that <strong>no</strong> word is both positive and negative.</p>\n\n<p>Initially every student has <code>0</code> points. Each positive word in a feedback report <strong>increases</strong> the points of a student by <code>3</code>, whereas each negative word <strong>decreases</strong> the points by <code>1</code>.</p>\n\n<p>You are given <code>n</code> feedback reports, represented by a <strong>0-indexed</strong> string array <code>report</code> and a <strong>0-indexed</strong> integer array <code>student_id</code>, where <code>student_id[i]</code> represents the ID of the student who has received the feedback report <code>report[i]</code>. The ID of each student is <strong>unique</strong>.</p>\n\n<p>Given an integer <code>k</code>, return <em>the top </em><code>k</code><em> students after ranking them in <strong>non-increasing</strong> order by their points</em>. In case more than one student has the same points, the one with the lower ID ranks higher.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is studious","the student is smart"], student_id = [1,2], k = 2\n<strong>Output:</strong> [1,2]\n<strong>Explanation:</strong> \nBoth the students have 1 positive feedback and 3 points but since student 1 has a lower ID he ranks higher.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> positive_feedback = ["smart","brilliant","studious"], negative_feedback = ["not"], report = ["this student is not studious","the student is smart"], student_id = [1,2], k = 2\n<strong>Output:</strong> [2,1]\n<strong>Explanation:</strong> \n- The student with ID 1 has 1 positive feedback and 1 negative feedback, so he has 3-1=2 points. \n- The student with ID 2 has 1 positive feedback, so he has 3 points. \nSince student 2 has more points, [2,1] is returned.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= positive_feedback.length, negative_feedback.length <= 10<sup>4</sup></code></li>\n\t<li><code>1 <= positive_feedback[i].length, negative_feedback[j].length <= 100</code></li>\n\t<li>Both <code>positive_feedback[i]</code> and <code>negative_feedback[j]</code> consists of lowercase English letters.</li>\n\t<li>No word is present in both <code>positive_feedback</code> and <code>negative_feedback</code>.</li>\n\t<li><code>n == report.length == student_id.length</code></li>\n\t<li><code>1 <= n <= 10<sup>4</sup></code></li>\n\t<li><code>report[i]</code> consists of lowercase English letters and spaces <code>' '</code>.</li>\n\t<li>There is a single space between consecutive words of <code>report[i]</code>.</li>\n\t<li><code>1 <= report[i].length <= 100</code></li>\n\t<li><code>1 <= student_id[i] <= 10<sup>9</sup></code></li>\n\t<li>All the values of <code>student_id[i]</code> are <strong>unique</strong>.</li>\n\t<li><code>1 <= k <= n</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2512",
"questionId": "2603",
"questionTitle": "Reward Top K Students",
"questionTitleSlug": "reward-top-k-students",
"similarQuestions": "[{\"title\": \"Queue Reconstruction by Height\", \"titleSlug\": \"queue-reconstruction-by-height\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"K Highest Ranked Items Within a Price Range\", \"titleSlug\": \"k-highest-ranked-items-within-a-price-range\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"17.1K\", \"totalSubmission\": \"38K\", \"totalAcceptedRaw\": 17062, \"totalSubmissionRaw\": 37957, \"acRate\": \"45.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Heap (Priority Queue)",
"slug": "heap-priority-queue"
}
]
}
}
} | 2512 | Medium | [
"You are given two string arrays positive_feedback and negative_feedback, containing the words denoting positive and negative feedback, respectively. Note that no word is both positive and negative.\n\nInitially every student has 0 points. Each positive word in a feedback report increases the points of a student by... | [
{
"hash": 5400471257637837000,
"runtime": "291ms",
"solution": "class Solution(object):\n def topStudents(self, positive_feedback, negative_feedback, report, student_id, k):\n \"\"\"\n :type positive_feedback: List[str]\n :type negative_feedback: List[str]\n :type report: ... | class Solution(object):
def topStudents(self, positive_feedback, negative_feedback, report, student_id, k):
"""
:type positive_feedback: List[str]
:type negative_feedback: List[str]
:type report: List[str]
:type student_id: List[int]
:type k: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 45 | Level 4 | Hi |
find-minimum-time-to-finish-all-jobs | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>jobs</code>, where <code>jobs[i]</code> is the amount of time it takes to complete the <code>i<sup>th</sup></code> job.</p>\n\n<p>There are <code>k</code> workers that you can assign jobs to. Each job should be assigned to <strong>exactly</strong> one worker. The <strong>working time</strong> of a worker is the sum of the time it takes to complete all jobs assigned to them. Your goal is to devise an optimal assignment such that the <strong>maximum working time</strong> of any worker is <strong>minimized</strong>.</p>\n\n<p><em>Return the <strong>minimum</strong> possible <strong>maximum working time</strong> of any assignment. </em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> jobs = [3,2,3], k = 3\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> By assigning each person one job, the maximum time is 3.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> jobs = [1,2,4,7,8], k = 2\n<strong>Output:</strong> 11\n<strong>Explanation:</strong> Assign the jobs the following way:\nWorker 1: 1, 2, 8 (working time = 1 + 2 + 8 = 11)\nWorker 2: 4, 7 (working time = 4 + 7 = 11)\nThe maximum working time is 11.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k <= jobs.length <= 12</code></li>\n\t<li><code>1 <= jobs[i] <= 10<sup>7</sup></code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1723",
"questionId": "1825",
"questionTitle": "Find Minimum Time to Finish All Jobs",
"questionTitleSlug": "find-minimum-time-to-finish-all-jobs",
"similarQuestions": "[{\"title\": \"Minimum Number of Work Sessions to Finish the Tasks\", \"titleSlug\": \"minimum-number-of-work-sessions-to-finish-the-tasks\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Find Minimum Time to Finish All Jobs II\", \"titleSlug\": \"find-minimum-time-to-finish-all-jobs-ii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"24.9K\", \"totalSubmission\": \"58.9K\", \"totalAcceptedRaw\": 24906, \"totalSubmissionRaw\": 58869, \"acRate\": \"42.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Backtracking",
"slug": "backtracking"
},
{
"name": "Bit Manipulation",
"slug": "bit-manipulation"
},
{
"name": "Bitmask",
"slug": "bitmask"
}
]
}
}
} | 1723 | Hard | [
"You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.\n\nThere are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Your ... | [
{
"hash": -3190427970232279000,
"runtime": "252ms",
"solution": "class Solution(object):\n def minimumTimeRequired(self, jobs, k):\n \"\"\"\n :type jobs: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n count = [0 for _ in range(k)]\n memo = {}\n ... | class Solution(object):
def minimumTimeRequired(self, jobs, k):
"""
:type jobs: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 42.3 | Level 5 | Hi |
solving-questions-with-brainpower | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> 2D integer array <code>questions</code> where <code>questions[i] = [points<sub>i</sub>, brainpower<sub>i</sub>]</code>.</p>\n\n<p>The array describes the questions of an exam, where you have to process the questions <strong>in order</strong> (i.e., starting from question <code>0</code>) and make a decision whether to <strong>solve</strong> or <strong>skip</strong> each question. Solving question <code>i</code> will <strong>earn</strong> you <code>points<sub>i</sub></code> points but you will be <strong>unable</strong> to solve each of the next <code>brainpower<sub>i</sub></code> questions. If you skip question <code>i</code>, you get to make the decision on the next question.</p>\n\n<ul>\n\t<li>For example, given <code>questions = [[3, 2], [4, 3], [4, 4], [2, 5]]</code>:\n\n\t<ul>\n\t\t<li>If question <code>0</code> is solved, you will earn <code>3</code> points but you will be unable to solve questions <code>1</code> and <code>2</code>.</li>\n\t\t<li>If instead, question <code>0</code> is skipped and question <code>1</code> is solved, you will earn <code>4</code> points but you will be unable to solve questions <code>2</code> and <code>3</code>.</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>Return <em>the <strong>maximum</strong> points you can earn for the exam</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> questions = [[3,2],[4,3],[4,4],[2,5]]\n<strong>Output:</strong> 5\n<strong>Explanation:</strong> The maximum points can be earned by solving questions 0 and 3.\n- Solve question 0: Earn 3 points, will be unable to solve the next 2 questions\n- Unable to solve questions 1 and 2\n- Solve question 3: Earn 2 points\nTotal points earned: 3 + 2 = 5. There is no other way to earn 5 or more points.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> questions = [[1,1],[2,2],[3,3],[4,4],[5,5]]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> The maximum points can be earned by solving questions 1 and 4.\n- Skip question 0\n- Solve question 1: Earn 2 points, will be unable to solve the next 2 questions\n- Unable to solve questions 2 and 3\n- Solve question 4: Earn 5 points\nTotal points earned: 2 + 5 = 7. There is no other way to earn 7 or more points.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= questions.length <= 10<sup>5</sup></code></li>\n\t<li><code>questions[i].length == 2</code></li>\n\t<li><code>1 <= points<sub>i</sub>, brainpower<sub>i</sub> <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2140",
"questionId": "2262",
"questionTitle": "Solving Questions With Brainpower",
"questionTitleSlug": "solving-questions-with-brainpower",
"similarQuestions": "[{\"title\": \"House Robber\", \"titleSlug\": \"house-robber\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Frog Jump\", \"titleSlug\": \"frog-jump\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"92.7K\", \"totalSubmission\": \"168.8K\", \"totalAcceptedRaw\": 92744, \"totalSubmissionRaw\": 168810, \"acRate\": \"54.9%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
}
]
}
}
} | 2140 | Medium | [
"You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri].\n\nThe array describes the questions of an exam, where you have to process the questions in order (i.e., starting from question 0) and make a decision whether to solve or skip each question. Solving question i will ea... | [
{
"hash": 3365100168231912000,
"runtime": "1296ms",
"solution": "class Solution(object):\n def mostPoints(self, questions):\n \"\"\"\n :type questions: List[List[int]]\n :rtype: int\n \"\"\"\n cache = {}\n def dfs(i):\n if i >= len(questions):\n ... | class Solution(object):
def mostPoints(self, questions):
"""
:type questions: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 54.9 | Level 3 | Hi |
number-of-distinct-averages | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of <strong>even</strong> length.</p>\n\n<p>As long as <code>nums</code> is <strong>not</strong> empty, you must repetitively:</p>\n\n<ul>\n\t<li>Find the minimum number in <code>nums</code> and remove it.</li>\n\t<li>Find the maximum number in <code>nums</code> and remove it.</li>\n\t<li>Calculate the average of the two removed numbers.</li>\n</ul>\n\n<p>The <strong>average</strong> of two numbers <code>a</code> and <code>b</code> is <code>(a + b) / 2</code>.</p>\n\n<ul>\n\t<li>For example, the average of <code>2</code> and <code>3</code> is <code>(2 + 3) / 2 = 2.5</code>.</li>\n</ul>\n\n<p>Return<em> the number of <strong>distinct</strong> averages calculated using the above process</em>.</p>\n\n<p><strong>Note</strong> that when there is a tie for a minimum or maximum number, any can be removed.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [4,1,4,0,3,5]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong>\n1. Remove 0 and 5, and the average is (0 + 5) / 2 = 2.5. Now, nums = [4,1,4,3].\n2. Remove 1 and 4. The average is (1 + 4) / 2 = 2.5, and nums = [4,3].\n3. Remove 3 and 4, and the average is (3 + 4) / 2 = 3.5.\nSince there are 2 distinct numbers among 2.5, 2.5, and 3.5, we return 2.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,100]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong>\nThere is only one average to be calculated after removing 1 and 100, so we return 1.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= nums.length <= 100</code></li>\n\t<li><code>nums.length</code> is even.</li>\n\t<li><code>0 <= nums[i] <= 100</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2465",
"questionId": "2561",
"questionTitle": "Number of Distinct Averages",
"questionTitleSlug": "number-of-distinct-averages",
"similarQuestions": "[{\"title\": \"Two Sum\", \"titleSlug\": \"two-sum\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Finding Pairs With a Certain Sum\", \"titleSlug\": \"finding-pairs-with-a-certain-sum\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"36.1K\", \"totalSubmission\": \"62.2K\", \"totalAcceptedRaw\": 36056, \"totalSubmissionRaw\": 62176, \"acRate\": \"58.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Two Pointers",
"slug": "two-pointers"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2465 | Easy | [
"You are given a 0-indexed integer array nums of even length.\n\nAs long as nums is not empty, you must repetitively:\n\n\n\tFind the minimum number in nums and remove it.\n\tFind the maximum number in nums and remove it.\n\tCalculate the average of the two removed numbers.\n\n\nThe average of two numbers a and b i... | [
{
"hash": -2783585439444555000,
"runtime": "10ms",
"solution": "class Solution(object):\n def distinctAverages(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n #===============================#\n # Greedy-based traversal method #\n ... | class Solution(object):
def distinctAverages(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 58 | Level 1 | Hi |
odd-even-linked-list | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>head</code> of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return <em>the reordered list</em>.</p>\n\n<p>The <strong>first</strong> node is considered <strong>odd</strong>, and the <strong>second</strong> node is <strong>even</strong>, and so on.</p>\n\n<p>Note that the relative order inside both the even and odd groups should remain as it was in the input.</p>\n\n<p>You must solve the problem in <code>O(1)</code> extra space complexity and <code>O(n)</code> time complexity.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/03/10/oddeven-linked-list.jpg\" style=\"width: 300px; height: 123px;\" />\n<pre>\n<strong>Input:</strong> head = [1,2,3,4,5]\n<strong>Output:</strong> [1,3,5,2,4]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/03/10/oddeven2-linked-list.jpg\" style=\"width: 500px; height: 142px;\" />\n<pre>\n<strong>Input:</strong> head = [2,1,3,5,6,4,7]\n<strong>Output:</strong> [2,3,6,7,1,5,4]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the linked list is in the range <code>[0, 10<sup>4</sup>]</code>.</li>\n\t<li><code>-10<sup>6</sup> <= Node.val <= 10<sup>6</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "328",
"questionId": "328",
"questionTitle": "Odd Even Linked List",
"questionTitleSlug": "odd-even-linked-list",
"similarQuestions": "[{\"title\": \"Split Linked List in Parts\", \"titleSlug\": \"split-linked-list-in-parts\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"821.2K\", \"totalSubmission\": \"1.3M\", \"totalAcceptedRaw\": 821170, \"totalSubmissionRaw\": 1338216, \"acRate\": \"61.4%\"}",
"topicTags": [
{
"name": "Linked List",
"slug": "linked-list"
}
]
}
}
} | 328 | Medium | [
"Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list.\n\nThe first node is considered odd, and the second node is even, and so on.\n\nNote that the relative order inside both the even and odd groups should remai... | [
{
"hash": 4021180418709014500,
"runtime": "22ms",
"solution": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def oddEvenList(self, head):\n \"\"\"\n ... | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def oddEvenList(self, head):
"""
:type head: ListNode
:rtype: ListNode
"""
| None | None | None | None | None | None | 61.4 | Level 2 | Hi |
convert-an-array-into-a-2d-array-with-conditions | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code>. You need to create a 2D array from <code>nums</code> satisfying the following conditions:</p>\n\n<ul>\n\t<li>The 2D array should contain <strong>only</strong> the elements of the array <code>nums</code>.</li>\n\t<li>Each row in the 2D array contains <strong>distinct</strong> integers.</li>\n\t<li>The number of rows in the 2D array should be <strong>minimal</strong>.</li>\n</ul>\n\n<p>Return <em>the resulting array</em>. If there are multiple answers, return any of them.</p>\n\n<p><strong>Note</strong> that the 2D array can have a different number of elements on each row.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3,4,1,2,3,1]\n<strong>Output:</strong> [[1,3,4,2],[1,3],[1]]\n<strong>Explanation:</strong> We can create a 2D array that contains the following rows:\n- 1,3,4,2\n- 1,3\n- 1\nAll elements of nums were used, and each row of the 2D array contains distinct integers, so it is a valid answer.\nIt can be shown that we cannot have less than 3 rows in a valid array.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3,4]\n<strong>Output:</strong> [[4,3,2,1]]\n<strong>Explanation:</strong> All elements of the array are distinct, so we can keep all of them in the first row of the 2D array.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 200</code></li>\n\t<li><code>1 <= nums[i] <= nums.length</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2610",
"questionId": "2724",
"questionTitle": "Convert an Array Into a 2D Array With Conditions",
"questionTitleSlug": "convert-an-array-into-a-2d-array-with-conditions",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"35.4K\", \"totalSubmission\": \"42.4K\", \"totalAcceptedRaw\": 35406, \"totalSubmissionRaw\": 42424, \"acRate\": \"83.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
}
]
}
}
} | 2610 | Medium | [
"You are given an integer array nums. You need to create a 2D array from nums satisfying the following conditions:\n\n\n\tThe 2D array should contain only the elements of the array nums.\n\tEach row in the 2D array contains distinct integers.\n\tThe number of rows in the 2D array should be minimal.\n\n\nReturn the ... | [
{
"hash": -4358310297446099000,
"runtime": "35ms",
"solution": "class Solution(object):\n def findMatrix(self, nums):\n out = []\n while len(nums):\n p = []\n i=0\n while i < len(nums):\n if nums[i] not in p:\n p.append(... | class Solution(object):
def findMatrix(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 83.5 | Level 2 | Hi |
adding-two-negabinary-numbers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two numbers <code>arr1</code> and <code>arr2</code> in base <strong>-2</strong>, return the result of adding them together.</p>\n\n<p>Each number is given in <em>array format</em>: as an array of 0s and 1s, from most significant bit to least significant bit. For example, <code>arr = [1,1,0,1]</code> represents the number <code>(-2)^3 + (-2)^2 + (-2)^0 = -3</code>. A number <code>arr</code> in <em>array, format</em> is also guaranteed to have no leading zeros: either <code>arr == [0]</code> or <code>arr[0] == 1</code>.</p>\n\n<p>Return the result of adding <code>arr1</code> and <code>arr2</code> in the same format: as an array of 0s and 1s with no leading zeros.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr1 = [1,1,1,1,1], arr2 = [1,0,1]\n<strong>Output:</strong> [1,0,0,0,0]\n<strong>Explanation: </strong>arr1 represents 11, arr2 represents 5, the output represents 16.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr1 = [0], arr2 = [0]\n<strong>Output:</strong> [0]\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr1 = [0], arr2 = [1]\n<strong>Output:</strong> [1]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr1.length, arr2.length <= 1000</code></li>\n\t<li><code>arr1[i]</code> and <code>arr2[i]</code> are <code>0</code> or <code>1</code></li>\n\t<li><code>arr1</code> and <code>arr2</code> have no leading zeros</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1073",
"questionId": "1148",
"questionTitle": "Adding Two Negabinary Numbers",
"questionTitleSlug": "adding-two-negabinary-numbers",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"16.9K\", \"totalSubmission\": \"46.1K\", \"totalAcceptedRaw\": 16913, \"totalSubmissionRaw\": 46056, \"acRate\": \"36.7%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
}
]
}
}
} | 1073 | Medium | [
"Given two numbers arr1 and arr2 in base -2, return the result of adding them together.\n\nEach number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit. For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3. A number arr in array, f... | [
{
"hash": -5481275241620149000,
"runtime": "48ms",
"solution": "class Solution(object):\n def baseNeg2(self, n):\n if n == 0:\n return \"0\"\n\n ans = \"\"\n\n while abs(n) > 0:\n if n % (-2) == 0:\n ans = \"0\" + ans\n # n = n ... | class Solution(object):
def addNegabinary(self, arr1, arr2):
"""
:type arr1: List[int]
:type arr2: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 36.7 | Level 4 | Hi |
maximum-non-negative-product-in-a-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <code>m x n</code> matrix <code>grid</code>. Initially, you are located at the top-left corner <code>(0, 0)</code>, and in each step, you can only <strong>move right or down</strong> in the matrix.</p>\n\n<p>Among all possible paths starting from the top-left corner <code>(0, 0)</code> and ending in the bottom-right corner <code>(m - 1, n - 1)</code>, find the path with the <strong>maximum non-negative product</strong>. The product of a path is the product of all integers in the grid cells visited along the path.</p>\n\n<p>Return the <em>maximum non-negative product <strong>modulo</strong> </em><code>10<sup>9</sup> + 7</code>. <em>If the maximum product is <strong>negative</strong>, return </em><code>-1</code>.</p>\n\n<p>Notice that the modulo is performed after getting the maximum product.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/23/product1.jpg\" style=\"width: 244px; height: 245px;\" />\n<pre>\n<strong>Input:</strong> grid = [[-1,-2,-3],[-2,-3,-3],[-3,-3,-2]]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> It is not possible to get non-negative product in the path from (0, 0) to (2, 2), so return -1.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/23/product2.jpg\" style=\"width: 244px; height: 245px;\" />\n<pre>\n<strong>Input:</strong> grid = [[1,-2,1],[1,-2,1],[3,-4,1]]\n<strong>Output:</strong> 8\n<strong>Explanation:</strong> Maximum non-negative product is shown (1 * 1 * -2 * -4 * 1 = 8).\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/23/product3.jpg\" style=\"width: 164px; height: 165px;\" />\n<pre>\n<strong>Input:</strong> grid = [[1,3],[0,-4]]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> Maximum non-negative product is shown (1 * 0 * -4 = 0).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 <= m, n <= 15</code></li>\n\t<li><code>-4 <= grid[i][j] <= 4</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1594",
"questionId": "1716",
"questionTitle": "Maximum Non Negative Product in a Matrix",
"questionTitleSlug": "maximum-non-negative-product-in-a-matrix",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"22.7K\", \"totalSubmission\": \"67.9K\", \"totalAcceptedRaw\": 22693, \"totalSubmissionRaw\": 67889, \"acRate\": \"33.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 1594 | Medium | [
"You are given a m x n matrix grid. Initially, you are located at the top-left corner (0, 0), and in each step, you can only move right or down in the matrix.\n\nAmong all possible paths starting from the top-left corner (0, 0) and ending in the bottom-right corner (m - 1, n - 1), find the path with the maximum non... | [
{
"hash": -327087667536227000,
"runtime": "33ms",
"solution": "class Solution(object):\n def maxProductPath(self, grid):\n m = len(grid)\n n = len(grid[0])\n dp = [[(0, 0)] * n for _ in range(m)]\n for i in range(m):\n for j in range(n):\n curr = ... | class Solution(object):
def maxProductPath(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 33.4 | Level 4 | Hi |
smallest-index-with-equal-value | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, return <em>the <strong>smallest</strong> index </em><code>i</code><em> of </em><code>nums</code><em> such that </em><code>i mod 10 == nums[i]</code><em>, or </em><code>-1</code><em> if such index does not exist</em>.</p>\n\n<p><code>x mod y</code> denotes the <strong>remainder</strong> when <code>x</code> is divided by <code>y</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,2]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> \ni=0: 0 mod 10 = 0 == nums[0].\ni=1: 1 mod 10 = 1 == nums[1].\ni=2: 2 mod 10 = 2 == nums[2].\nAll indices have i mod 10 == nums[i], so we return the smallest index 0.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [4,3,2,1]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> \ni=0: 0 mod 10 = 0 != nums[0].\ni=1: 1 mod 10 = 1 != nums[1].\ni=2: 2 mod 10 = 2 == nums[2].\ni=3: 3 mod 10 = 3 != nums[3].\n2 is the only index which has i mod 10 == nums[i].\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3,4,5,6,7,8,9,0]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> No index satisfies i mod 10 == nums[i].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 100</code></li>\n\t<li><code>0 <= nums[i] <= 9</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2057",
"questionId": "2181",
"questionTitle": "Smallest Index With Equal Value",
"questionTitleSlug": "smallest-index-with-equal-value",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"53.3K\", \"totalSubmission\": \"73.8K\", \"totalAcceptedRaw\": 53342, \"totalSubmissionRaw\": 73780, \"acRate\": \"72.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
}
]
}
}
} | 2057 | Easy | [
"Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.\n\nx mod y denotes the remainder when x is divided by y.\n\n \nExample 1:\n\nInput: nums = [0,1,2]\nOutput: 0\nExplanation: \ni=0: 0 mod 10 = 0 == nums[0].\ni=1: 1 mod 10 = 1... | [
{
"hash": -7456380514997313000,
"runtime": "51ms",
"solution": "class Solution(object):\n def smallestEqual(self, nums):\n ans = None\n for i in range(0, len(nums)):\n if i % 10 == nums[i]:\n ans = i\n break\n else:\n pa... | class Solution(object):
def smallestEqual(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 72.3 | Level 1 | Hi |
collect-coins-in-a-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There exists an undirected and unrooted tree with <code>n</code> nodes indexed from <code>0</code> to <code>n - 1</code>. You are given an integer <code>n</code> and a 2D integer array edges of length <code>n - 1</code>, where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> in the tree. You are also given an array <code>coins</code> of size <code>n</code> where <code>coins[i]</code> can be either <code>0</code> or <code>1</code>, where <code>1</code> indicates the presence of a coin in the vertex <code>i</code>.</p>\n\n<p>Initially, you choose to start at any vertex in the tree. Then, you can perform the following operations any number of times: </p>\n\n<ul>\n\t<li>Collect all the coins that are at a distance of at most <code>2</code> from the current vertex, or</li>\n\t<li>Move to any adjacent vertex in the tree.</li>\n</ul>\n\n<p>Find <em>the minimum number of edges you need to go through to collect all the coins and go back to the initial vertex</em>.</p>\n\n<p>Note that if you pass an edge several times, you need to count it into the answer several times.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/03/01/graph-2.png\" style=\"width: 522px; height: 522px;\" />\n<pre>\n<strong>Input:</strong> coins = [1,0,0,0,0,1], edges = [[0,1],[1,2],[2,3],[3,4],[4,5]]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Start at vertex 2, collect the coin at vertex 0, move to vertex 3, collect the coin at vertex 5 then move back to vertex 2.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2023/03/02/graph-4.png\" style=\"width: 522px; height: 522px;\" />\n<pre>\n<strong>Input:</strong> coins = [0,0,0,1,1,0,0,1], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[5,6],[5,7]]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Start at vertex 0, collect the coins at vertices 4 and 3, move to vertex 2, collect the coin at vertex 7, then move back to vertex 0.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == coins.length</code></li>\n\t<li><code>1 <= n <= 3 * 10<sup>4</sup></code></li>\n\t<li><code>0 <= coins[i] <= 1</code></li>\n\t<li><code>edges.length == n - 1</code></li>\n\t<li><code>edges[i].length == 2</code></li>\n\t<li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code></li>\n\t<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>\n\t<li><code>edges</code> represents a valid tree.</li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "2603",
"questionId": "2717",
"questionTitle": "Collect Coins in a Tree",
"questionTitleSlug": "collect-coins-in-a-tree",
"similarQuestions": "[{\"title\": \"Minimum Height Trees\", \"titleSlug\": \"minimum-height-trees\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Sum of Distances in Tree\", \"titleSlug\": \"sum-of-distances-in-tree\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Maximum Score After Applying Operations on a Tree\", \"titleSlug\": \"maximum-score-after-applying-operations-on-a-tree\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"5.5K\", \"totalSubmission\": \"15K\", \"totalAcceptedRaw\": 5454, \"totalSubmissionRaw\": 15008, \"acRate\": \"36.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Tree",
"slug": "tree"
},
{
"name": "Graph",
"slug": "graph"
},
{
"name": "Topological Sort",
"slug": "topological-sort"
}
]
}
}
} | 2603 | Hard | [
"There exists an undirected and unrooted tree with n nodes indexed from 0 to n - 1. You are given an integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given an array coins of size n where coins[i] can b... | [
{
"hash": -7658071749248839000,
"runtime": "1984ms",
"solution": "class Solution(object):\n def collectTheCoins(self, coins, edges):\n \"\"\"\n :type coins: List[int]\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"\n n = len(coins)\n degree = [se... | class Solution(object):
def collectTheCoins(self, coins, edges):
"""
:type coins: List[int]
:type edges: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 36.3 | Level 5 | Hi |
count-asterisks | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code>, where every <strong>two</strong> consecutive vertical bars <code>'|'</code> are grouped into a <strong>pair</strong>. In other words, the 1<sup>st</sup> and 2<sup>nd</sup> <code>'|'</code> make a pair, the 3<sup>rd</sup> and 4<sup>th</sup> <code>'|'</code> make a pair, and so forth.</p>\n\n<p>Return <em>the number of </em><code>'*'</code><em> in </em><code>s</code><em>, <strong>excluding</strong> the </em><code>'*'</code><em> between each pair of </em><code>'|'</code>.</p>\n\n<p><strong>Note</strong> that each <code>'|'</code> will belong to <strong>exactly</strong> one pair.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "l|*e*et|c**o|*de|"\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The considered characters are underlined: "<u>l</u>|*e*et|<u>c**o</u>|*de|".\nThe characters between the first and second '|' are excluded from the answer.\nAlso, the characters between the third and fourth '|' are excluded from the answer.\nThere are 2 asterisks considered. Therefore, we return 2.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "iamprogrammer"\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> In this example, there are no asterisks in s. Therefore, we return 0.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "yo|uar|e**|b|e***au|tifu|l"\n<strong>Output:</strong> 5\n<strong>Explanation:</strong> The considered characters are underlined: "<u>yo</u>|uar|<u>e**</u>|b|<u>e***au</u>|tifu|<u>l</u>". There are 5 asterisks considered. Therefore, we return 5.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 1000</code></li>\n\t<li><code>s</code> consists of lowercase English letters, vertical bars <code>'|'</code>, and asterisks <code>'*'</code>.</li>\n\t<li><code>s</code> contains an <strong>even</strong> number of vertical bars <code>'|'</code>.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2315",
"questionId": "2401",
"questionTitle": "Count Asterisks",
"questionTitleSlug": "count-asterisks",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"58.6K\", \"totalSubmission\": \"71.6K\", \"totalAcceptedRaw\": 58567, \"totalSubmissionRaw\": 71608, \"acRate\": \"81.8%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
}
]
}
}
} | 2315 | Easy | [
"You are given a string s, where every two consecutive vertical bars '|' are grouped into a pair. In other words, the 1st and 2nd '|' make a pair, the 3rd and 4th '|' make a pair, and so forth.\n\nReturn the number of '*' in s, excluding the '*' between each pair of '|'.\n\nNote that each '|' will belong to exactly... | [
{
"hash": -6447063721341209000,
"runtime": "8ms",
"solution": "class Solution(object):\n def countAsterisks(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n number_of_asteriks = len([char for char in s if char == \"*\"])\n hits = 0\n paired =... | class Solution(object):
def countAsterisks(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 81.8 | Level 1 | Hi |
count-symmetric-integers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two positive integers <code>low</code> and <code>high</code>.</p>\n\n<p>An integer <code>x</code> consisting of <code>2 * n</code> digits is <strong>symmetric</strong> if the sum of the first <code>n</code> digits of <code>x</code> is equal to the sum of the last <code>n</code> digits of <code>x</code>. Numbers with an odd number of digits are never symmetric.</p>\n\n<p>Return <em>the <strong>number of symmetric</strong> integers in the range</em> <code>[low, high]</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> low = 1, high = 100\n<strong>Output:</strong> 9\n<strong>Explanation:</strong> There are 9 symmetric integers between 1 and 100: 11, 22, 33, 44, 55, 66, 77, 88, and 99.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> low = 1200, high = 1230\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> There are 4 symmetric integers between 1200 and 1230: 1203, 1212, 1221, and 1230.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= low <= high <= 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2843",
"questionId": "2998",
"questionTitle": " Count Symmetric Integers",
"questionTitleSlug": "count-symmetric-integers",
"similarQuestions": "[{\"title\": \"Palindrome Number\", \"titleSlug\": \"palindrome-number\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Sum of Digits in Base K\", \"titleSlug\": \"sum-of-digits-in-base-k\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"36.1K\", \"totalSubmission\": \"48.8K\", \"totalAcceptedRaw\": 36128, \"totalSubmissionRaw\": 48804, \"acRate\": \"74.0%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "Enumeration",
"slug": "enumeration"
}
]
}
}
} | 2843 | Easy | [
"You are given two positive integers low and high.\n\nAn integer x consisting of 2 * n digits is symmetric if the sum of the first n digits of x is equal to the sum of the last n digits of x. Numbers with an odd number of digits are never symmetric.\n\nReturn the number of symmetric integers in the range [low, high... | [
{
"hash": 8034749312254865000,
"runtime": "1546ms",
"solution": "class Solution(object):\n def countSymmetricIntegers(self, low, high):\n \"\"\"\n :type low: int\n :type high: int\n :rtype: int\n \"\"\"\n def listSum(arr):\n x = 0\n for ... | class Solution(object):
def countSymmetricIntegers(self, low, high):
"""
:type low: int
:type high: int
:rtype: int
"""
| None | None | None | None | None | None | 74 | Level 1 | Hi |
maximum-score-of-spliced-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, both of length <code>n</code>.</p>\n\n<p>You can choose two integers <code>left</code> and <code>right</code> where <code>0 <= left <= right < n</code> and <strong>swap</strong> the subarray <code>nums1[left...right]</code> with the subarray <code>nums2[left...right]</code>.</p>\n\n<ul>\n\t<li>For example, if <code>nums1 = [1,2,3,4,5]</code> and <code>nums2 = [11,12,13,14,15]</code> and you choose <code>left = 1</code> and <code>right = 2</code>, <code>nums1</code> becomes <code>[1,<strong><u>12,13</u></strong>,4,5]</code> and <code>nums2</code> becomes <code>[11,<strong><u>2,3</u></strong>,14,15]</code>.</li>\n</ul>\n\n<p>You may choose to apply the mentioned operation <strong>once</strong> or not do anything.</p>\n\n<p>The <strong>score</strong> of the arrays is the <strong>maximum</strong> of <code>sum(nums1)</code> and <code>sum(nums2)</code>, where <code>sum(arr)</code> is the sum of all the elements in the array <code>arr</code>.</p>\n\n<p>Return <em>the <strong>maximum possible score</strong></em>.</p>\n\n<p>A <strong>subarray</strong> is a contiguous sequence of elements within an array. <code>arr[left...right]</code> denotes the subarray that contains the elements of <code>nums</code> between indices <code>left</code> and <code>right</code> (<strong>inclusive</strong>).</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [60,60,60], nums2 = [10,90,10]\n<strong>Output:</strong> 210\n<strong>Explanation:</strong> Choosing left = 1 and right = 1, we have nums1 = [60,<u><strong>90</strong></u>,60] and nums2 = [10,<u><strong>60</strong></u>,10].\nThe score is max(sum(nums1), sum(nums2)) = max(210, 80) = 210.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]\n<strong>Output:</strong> 220\n<strong>Explanation:</strong> Choosing left = 3, right = 4, we have nums1 = [20,40,20,<u><strong>40,20</strong></u>] and nums2 = [50,20,50,<u><strong>70,30</strong></u>].\nThe score is max(sum(nums1), sum(nums2)) = max(140, 220) = 220.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [7,11,13], nums2 = [1,1,1]\n<strong>Output:</strong> 31\n<strong>Explanation:</strong> We choose not to swap any subarray.\nThe score is max(sum(nums1), sum(nums2)) = max(31, 3) = 31.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == nums1.length == nums2.length</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums1[i], nums2[i] <= 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "2321",
"questionId": "1348",
"questionTitle": "Maximum Score Of Spliced Array",
"questionTitleSlug": "maximum-score-of-spliced-array",
"similarQuestions": "[{\"title\": \"Maximum Subarray\", \"titleSlug\": \"maximum-subarray\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"17.5K\", \"totalSubmission\": \"31.1K\", \"totalAcceptedRaw\": 17461, \"totalSubmissionRaw\": 31052, \"acRate\": \"56.2%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
}
]
}
}
} | 2321 | Hard | [
"You are given two 0-indexed integer arrays nums1 and nums2, both of length n.\n\nYou can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[left...right].\n\n\n\tFor example, if nums1 = [1,2,3,4,5] and nums2 = [11,12,13,14,15] and you c... | [
{
"hash": 5024632279307813000,
"runtime": "680ms",
"solution": "class Solution(object):\n def maximumsSplicedArray(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"\n max1 = 0\n max2 = 0\n fir... | class Solution(object):
def maximumsSplicedArray(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 56.2 | Level 5 | Hi |
unique-length-3-palindromic-subsequences | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code>, return <em>the number of <strong>unique palindromes of length three</strong> that are a <strong>subsequence</strong> of </em><code>s</code>.</p>\n\n<p>Note that even if there are multiple ways to obtain the same subsequence, it is still only counted <strong>once</strong>.</p>\n\n<p>A <strong>palindrome</strong> is a string that reads the same forwards and backwards.</p>\n\n<p>A <strong>subsequence</strong> of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.</p>\n\n<ul>\n\t<li>For example, <code>"ace"</code> is a subsequence of <code>"<u>a</u>b<u>c</u>d<u>e</u>"</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aabca"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The 3 palindromic subsequences of length 3 are:\n- "aba" (subsequence of "<u>a</u>a<u>b</u>c<u>a</u>")\n- "aaa" (subsequence of "<u>aa</u>bc<u>a</u>")\n- "aca" (subsequence of "<u>a</u>ab<u>ca</u>")\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "adc"\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> There are no palindromic subsequences of length 3 in "adc".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "bbcbaba"\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The 4 palindromic subsequences of length 3 are:\n- "bbb" (subsequence of "<u>bb</u>c<u>b</u>aba")\n- "bcb" (subsequence of "<u>b</u>b<u>cb</u>aba")\n- "bab" (subsequence of "<u>b</u>bcb<u>ab</u>a")\n- "aba" (subsequence of "bbcb<u>aba</u>")\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= s.length <= 10<sup>5</sup></code></li>\n\t<li><code>s</code> consists of only lowercase English letters.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1930",
"questionId": "2059",
"questionTitle": "Unique Length-3 Palindromic Subsequences",
"questionTitleSlug": "unique-length-3-palindromic-subsequences",
"similarQuestions": "[{\"title\": \"Count Palindromic Subsequences\", \"titleSlug\": \"count-palindromic-subsequences\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"96.1K\", \"totalSubmission\": \"145.2K\", \"totalAcceptedRaw\": 96052, \"totalSubmissionRaw\": 145205, \"acRate\": \"66.1%\"}",
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
}
]
}
}
} | 1930 | Medium | [
"Given a string s, return the number of unique palindromes of length three that are a subsequence of s.\n\nNote that even if there are multiple ways to obtain the same subsequence, it is still only counted once.\n\nA palindrome is a string that reads the same forwards and backwards.\n\nA subsequence of a string is ... | [
{
"hash": -7504158596422541000,
"runtime": "931ms",
"solution": "class Solution(object):\n def countPalindromicSubsequence(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n \n last_index = [-1] * 26\n for i,l in enumerate(s):\n last... | class Solution(object):
def countPalindromicSubsequence(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 66.1 | Level 2 | Hi |
jump-game-iv | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>arr</code>, you are initially positioned at the first index of the array.</p>\n\n<p>In one step you can jump from index <code>i</code> to index:</p>\n\n<ul>\n\t<li><code>i + 1</code> where: <code>i + 1 < arr.length</code>.</li>\n\t<li><code>i - 1</code> where: <code>i - 1 >= 0</code>.</li>\n\t<li><code>j</code> where: <code>arr[i] == arr[j]</code> and <code>i != j</code>.</li>\n</ul>\n\n<p>Return <em>the minimum number of steps</em> to reach the <strong>last index</strong> of the array.</p>\n\n<p>Notice that you can not jump outside of the array at any time.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [100,-23,-23,404,100,23,23,23,3,404]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> You need three jumps from index 0 --> 4 --> 3 --> 9. Note that index 9 is the last index of the array.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [7]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> Start index is the last index. You do not need to jump.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [7,6,9,6,9,6,9,7]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> You can jump directly from index 0 to index 7 which is last index of the array.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 5 * 10<sup>4</sup></code></li>\n\t<li><code>-10<sup>8</sup> <= arr[i] <= 10<sup>8</sup></code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1345",
"questionId": "1447",
"questionTitle": "Jump Game IV",
"questionTitleSlug": "jump-game-iv",
"similarQuestions": "[{\"title\": \"Jump Game VII\", \"titleSlug\": \"jump-game-vii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Jump Game VIII\", \"titleSlug\": \"jump-game-viii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximum Number of Jumps to Reach the Last Index\", \"titleSlug\": \"maximum-number-of-jumps-to-reach-the-last-index\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"137.9K\", \"totalSubmission\": \"296.7K\", \"totalAcceptedRaw\": 137860, \"totalSubmissionRaw\": 296720, \"acRate\": \"46.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search"
}
]
}
}
} | 1345 | Hard | [
"Given an array of integers arr, you are initially positioned at the first index of the array.\n\nIn one step you can jump from index i to index:\n\n\n\ti + 1 where: i + 1 < arr.length.\n\ti - 1 where: i - 1 >= 0.\n\tj where: arr[i] == arr[j] and i != j.\n\n\nReturn the minimum number of steps to reach the last ind... | [
{
"hash": 3238165310827992600,
"runtime": "1605ms",
"solution": "class Solution(object):\n def minJumps(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n self.hashmap = collections.defaultdict(list)\n for i, num in enumerate(arr):\n ... | class Solution(object):
def minJumps(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 46.5 | Level 5 | Hi |
sum-of-total-strength-of-wizards | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>As the ruler of a kingdom, you have an army of wizards at your command.</p>\n\n<p>You are given a <strong>0-indexed</strong> integer array <code>strength</code>, where <code>strength[i]</code> denotes the strength of the <code>i<sup>th</sup></code> wizard. For a <strong>contiguous</strong> group of wizards (i.e. the wizards' strengths form a <strong>subarray</strong> of <code>strength</code>), the <strong>total strength</strong> is defined as the <strong>product</strong> of the following two values:</p>\n\n<ul>\n\t<li>The strength of the <strong>weakest</strong> wizard in the group.</li>\n\t<li>The <strong>total</strong> of all the individual strengths of the wizards in the group.</li>\n</ul>\n\n<p>Return <em>the <strong>sum</strong> of the total strengths of <strong>all</strong> contiguous groups of wizards</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p>A <strong>subarray</strong> is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> strength = [1,3,1,2]\n<strong>Output:</strong> 44\n<strong>Explanation:</strong> The following are all the contiguous groups of wizards:\n- [1] from [<u><strong>1</strong></u>,3,1,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n- [3] from [1,<u><strong>3</strong></u>,1,2] has a total strength of min([3]) * sum([3]) = 3 * 3 = 9\n- [1] from [1,3,<u><strong>1</strong></u>,2] has a total strength of min([1]) * sum([1]) = 1 * 1 = 1\n- [2] from [1,3,1,<u><strong>2</strong></u>] has a total strength of min([2]) * sum([2]) = 2 * 2 = 4\n- [1,3] from [<u><strong>1,3</strong></u>,1,2] has a total strength of min([1,3]) * sum([1,3]) = 1 * 4 = 4\n- [3,1] from [1,<u><strong>3,1</strong></u>,2] has a total strength of min([3,1]) * sum([3,1]) = 1 * 4 = 4\n- [1,2] from [1,3,<u><strong>1,2</strong></u>] has a total strength of min([1,2]) * sum([1,2]) = 1 * 3 = 3\n- [1,3,1] from [<u><strong>1,3,1</strong></u>,2] has a total strength of min([1,3,1]) * sum([1,3,1]) = 1 * 5 = 5\n- [3,1,2] from [1,<u><strong>3,1,2</strong></u>] has a total strength of min([3,1,2]) * sum([3,1,2]) = 1 * 6 = 6\n- [1,3,1,2] from [<u><strong>1,3,1,2</strong></u>] has a total strength of min([1,3,1,2]) * sum([1,3,1,2]) = 1 * 7 = 7\nThe sum of all the total strengths is 1 + 9 + 1 + 4 + 4 + 4 + 3 + 5 + 6 + 7 = 44.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> strength = [5,4,6]\n<strong>Output:</strong> 213\n<strong>Explanation:</strong> The following are all the contiguous groups of wizards: \n- [5] from [<u><strong>5</strong></u>,4,6] has a total strength of min([5]) * sum([5]) = 5 * 5 = 25\n- [4] from [5,<u><strong>4</strong></u>,6] has a total strength of min([4]) * sum([4]) = 4 * 4 = 16\n- [6] from [5,4,<u><strong>6</strong></u>] has a total strength of min([6]) * sum([6]) = 6 * 6 = 36\n- [5,4] from [<u><strong>5,4</strong></u>,6] has a total strength of min([5,4]) * sum([5,4]) = 4 * 9 = 36\n- [4,6] from [5,<u><strong>4,6</strong></u>] has a total strength of min([4,6]) * sum([4,6]) = 4 * 10 = 40\n- [5,4,6] from [<u><strong>5,4,6</strong></u>] has a total strength of min([5,4,6]) * sum([5,4,6]) = 4 * 15 = 60\nThe sum of all the total strengths is 25 + 16 + 36 + 36 + 40 + 60 = 213.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= strength.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= strength[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "2281",
"questionId": "2368",
"questionTitle": "Sum of Total Strength of Wizards",
"questionTitleSlug": "sum-of-total-strength-of-wizards",
"similarQuestions": "[{\"title\": \"Next Greater Element I\", \"titleSlug\": \"next-greater-element-i\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Sum of Subarray Minimums\", \"titleSlug\": \"sum-of-subarray-minimums\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Number of Visible People in a Queue\", \"titleSlug\": \"number-of-visible-people-in-a-queue\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Sum of Subarray Ranges\", \"titleSlug\": \"sum-of-subarray-ranges\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"16.7K\", \"totalSubmission\": \"60.5K\", \"totalAcceptedRaw\": 16706, \"totalSubmissionRaw\": 60481, \"acRate\": \"27.6%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Stack",
"slug": "stack"
},
{
"name": "Monotonic Stack",
"slug": "monotonic-stack"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
}
]
}
}
} | 2281 | Hard | [
"As the ruler of a kingdom, you have an army of wizards at your command.\n\nYou are given a 0-indexed integer array strength, where strength[i] denotes the strength of the ith wizard. For a contiguous group of wizards (i.e. the wizards' strengths form a subarray of strength), the total strength is defined as the pr... | [
{
"hash": -7339507816159318000,
"runtime": "1192ms",
"solution": "class Solution(object):\n def totalStrength(self, s):\n\n #sol1: brute force n^2\n n = len(s)\n ans = 0\n mod = 1000000007\n \"\"\"\n for i in range(n):\n curSum = 0\n cur... | class Solution(object):
def totalStrength(self, strength):
"""
:type strength: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 27.6 | Level 5 | Hi |
longest-arithmetic-subsequence-of-given-difference | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>arr</code> and an integer <code>difference</code>, return the length of the longest subsequence in <code>arr</code> which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals <code>difference</code>.</p>\n\n<p>A <strong>subsequence</strong> is a sequence that can be derived from <code>arr</code> by deleting some or no elements without changing the order of the remaining elements.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,2,3,4], difference = 1\n<strong>Output:</strong> 4\n<strong>Explanation: </strong>The longest arithmetic subsequence is [1,2,3,4].</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,3,5,7], difference = 1\n<strong>Output:</strong> 1\n<strong>Explanation: </strong>The longest arithmetic subsequence is any single element.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,5,7,8,5,3,4,2,1], difference = -2\n<strong>Output:</strong> 4\n<strong>Explanation: </strong>The longest arithmetic subsequence is [7,5,3,1].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 10<sup>5</sup></code></li>\n\t<li><code>-10<sup>4</sup> <= arr[i], difference <= 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1218",
"questionId": "1330",
"questionTitle": "Longest Arithmetic Subsequence of Given Difference",
"questionTitleSlug": "longest-arithmetic-subsequence-of-given-difference",
"similarQuestions": "[{\"title\": \"Destroy Sequential Targets\", \"titleSlug\": \"destroy-sequential-targets\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"133.7K\", \"totalSubmission\": \"243.1K\", \"totalAcceptedRaw\": 133650, \"totalSubmissionRaw\": 243070, \"acRate\": \"55.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
}
]
}
}
} | 1218 | Medium | [
"Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals difference.\n\nA subsequence is a sequence that can be derived from arr by deleting some or no eleme... | [
{
"hash": 7620576948660370000,
"runtime": "369ms",
"solution": "class Solution(object):\n def longestSubsequence(self, arr, difference):\n \"\"\"\n :type arr: List[int]\n :type difference: int\n :rtype: int\n \"\"\"\n dp = defaultdict(int)\n\n for i in... | class Solution(object):
def longestSubsequence(self, arr, difference):
"""
:type arr: List[int]
:type difference: int
:rtype: int
"""
| None | None | None | None | None | None | 55 | Level 3 | Hi |
check-if-array-is-good | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code>. We consider an array <strong>good </strong>if it is a permutation of an array <code>base[n]</code>.</p>\n\n<p><code>base[n] = [1, 2, ..., n - 1, n, n] </code>(in other words, it is an array of length <code>n + 1</code> which contains <code>1</code> to <code>n - 1 </code>exactly once, plus two occurrences of <code>n</code>). For example, <code>base[1] = [1, 1]</code> and<code> base[3] = [1, 2, 3, 3]</code>.</p>\n\n<p>Return <code>true</code> <em>if the given array is good, otherwise return</em><em> </em><code>false</code>.</p>\n\n<p><strong>Note: </strong>A permutation of integers represents an arrangement of these numbers.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2, 1, 3]\n<strong>Output:</strong> false\n<strong>Explanation:</strong> Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1, 3, 3, 2]\n<strong>Output:</strong> true\n<strong>Explanation:</strong> Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1, 1]\n<strong>Output:</strong> true\n<strong>Explanation:</strong> Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3, 4, 4, 1, 2, 1]\n<strong>Output:</strong> false\n<strong>Explanation:</strong> Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 100</code></li>\n\t<li><code>1 <= num[i] <= 200</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2784",
"questionId": "2892",
"questionTitle": "Check if Array is Good",
"questionTitleSlug": "check-if-array-is-good",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"40.9K\", \"totalSubmission\": \"82.2K\", \"totalAcceptedRaw\": 40865, \"totalSubmissionRaw\": 82152, \"acRate\": \"49.7%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2784 | Easy | [
"You are given an integer array nums. We consider an array good if it is a permutation of an array base[n].\n\nbase[n] = [1, 2, ..., n - 1, n, n] (in other words, it is an array of length n + 1 which contains 1 to n - 1 exactly once, plus two occurrences of n). For example, base[1] = [1, 1] and base[3] = [1, 2, 3, ... | [
{
"hash": 4052827323723603500,
"runtime": "35ms",
"solution": "class Solution(object):\n def isGood(self, nums):\n from collections import Counter\n\n c= Counter(nums)\n max_val = max(nums)\n if c[max_val] != 2:\n return False\n for i in range(1, max_val)... | class Solution(object):
def isGood(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 49.7 | Level 1 | Hi |
validate-ip-address | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>queryIP</code>, return <code>"IPv4"</code> if IP is a valid IPv4 address, <code>"IPv6"</code> if IP is a valid IPv6 address or <code>"Neither"</code> if IP is not a correct IP of any type.</p>\n\n<p><strong>A valid IPv4</strong> address is an IP in the form <code>"x<sub>1</sub>.x<sub>2</sub>.x<sub>3</sub>.x<sub>4</sub>"</code> where <code>0 <= x<sub>i</sub> <= 255</code> and <code>x<sub>i</sub></code> <strong>cannot contain</strong> leading zeros. For example, <code>"192.168.1.1"</code> and <code>"192.168.1.0"</code> are valid IPv4 addresses while <code>"192.168.01.1"</code>, <code>"192.168.1.00"</code>, and <code>"192.168@1.1"</code> are invalid IPv4 addresses.</p>\n\n<p><strong>A valid IPv6</strong> address is an IP in the form <code>"x<sub>1</sub>:x<sub>2</sub>:x<sub>3</sub>:x<sub>4</sub>:x<sub>5</sub>:x<sub>6</sub>:x<sub>7</sub>:x<sub>8</sub>"</code> where:</p>\n\n<ul>\n\t<li><code>1 <= x<sub>i</sub>.length <= 4</code></li>\n\t<li><code>x<sub>i</sub></code> is a <strong>hexadecimal string</strong> which may contain digits, lowercase English letter (<code>'a'</code> to <code>'f'</code>) and upper-case English letters (<code>'A'</code> to <code>'F'</code>).</li>\n\t<li>Leading zeros are allowed in <code>x<sub>i</sub></code>.</li>\n</ul>\n\n<p>For example, "<code>2001:0db8:85a3:0000:0000:8a2e:0370:7334"</code> and "<code>2001:db8:85a3:0:0:8A2E:0370:7334"</code> are valid IPv6 addresses, while "<code>2001:0db8:85a3::8A2E:037j:7334"</code> and "<code>02001:0db8:85a3:0000:0000:8a2e:0370:7334"</code> are invalid IPv6 addresses.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> queryIP = "172.16.254.1"\n<strong>Output:</strong> "IPv4"\n<strong>Explanation:</strong> This is a valid IPv4 address, return "IPv4".\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> queryIP = "2001:0db8:85a3:0:0:8A2E:0370:7334"\n<strong>Output:</strong> "IPv6"\n<strong>Explanation:</strong> This is a valid IPv6 address, return "IPv6".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> queryIP = "256.256.256.256"\n<strong>Output:</strong> "Neither"\n<strong>Explanation:</strong> This is neither a IPv4 address nor a IPv6 address.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>queryIP</code> consists only of English letters, digits and the characters <code>'.'</code> and <code>':'</code>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "468",
"questionId": "468",
"questionTitle": "Validate IP Address",
"questionTitleSlug": "validate-ip-address",
"similarQuestions": "[{\"title\": \"IP to CIDR\", \"titleSlug\": \"ip-to-cidr\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Strong Password Checker II\", \"titleSlug\": \"strong-password-checker-ii\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"150.7K\", \"totalSubmission\": \"562.8K\", \"totalAcceptedRaw\": 150730, \"totalSubmissionRaw\": 562818, \"acRate\": \"26.8%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
}
]
}
}
} | 468 | Medium | [
"Given a string queryIP, return \"IPv4\" if IP is a valid IPv4 address, \"IPv6\" if IP is a valid IPv6 address or \"Neither\" if IP is not a correct IP of any type.\n\nA valid IPv4 address is an IP in the form \"x₁.x₂.x₃.x₄\" where 0 <= xi <= 255 and xi cannot contain leading zeros. For example, \"192.168.1.1\" and... | [
{
"hash": 5221014458760376000,
"runtime": "10ms",
"solution": "class Solution(object):\n def validIPAddress(self, queryIP):\n \"\"\"\n :type queryIP: str\n :rtype: str\n \"\"\"\n\n if '.' in queryIP:\n x = queryIP.split('.')\n if len(x) is not ... | class Solution(object):
def validIPAddress(self, queryIP):
"""
:type queryIP: str
:rtype: str
"""
| None | None | None | None | None | None | 26.8 | Level 4 | Hi |
maximum-product-of-three-numbers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code>, <em>find three numbers whose product is maximum and return the maximum product</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<pre><strong>Input:</strong> nums = [1,2,3]\n<strong>Output:</strong> 6\n</pre><p><strong class=\"example\">Example 2:</strong></p>\n<pre><strong>Input:</strong> nums = [1,2,3,4]\n<strong>Output:</strong> 24\n</pre><p><strong class=\"example\">Example 3:</strong></p>\n<pre><strong>Input:</strong> nums = [-1,-2,-3]\n<strong>Output:</strong> -6\n</pre>\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= nums.length <= 10<sup>4</sup></code></li>\n\t<li><code>-1000 <= nums[i] <= 1000</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "628",
"questionId": "628",
"questionTitle": "Maximum Product of Three Numbers",
"questionTitleSlug": "maximum-product-of-three-numbers",
"similarQuestions": "[{\"title\": \"Maximum Product Subarray\", \"titleSlug\": \"maximum-product-subarray\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"293.7K\", \"totalSubmission\": \"649.1K\", \"totalAcceptedRaw\": 293685, \"totalSubmissionRaw\": 649085, \"acRate\": \"45.2%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 628 | Easy | [
"Given an integer array nums, find three numbers whose product is maximum and return the maximum product.\n\n \nExample 1:\nInput: nums = [1,2,3]\nOutput: 6\nExample 2:\nInput: nums = [1,2,3,4]\nOutput: 24\nExample 3:\nInput: nums = [-1,-2,-3]\nOutput: -6\n\n \nConstraints:\n\n\n\t3 <= nums.length <= 10⁴\n\t-1000 <... | [
{
"hash": -1704724646479045000,
"runtime": "217ms",
"solution": "class Solution(object):\n def maximumProduct(self, nums):\n nums.sort()\n nums.reverse()\n min1=float('inf')\n min2=float('inf')\n \n prod=nums[0]*nums[1]*nums[2]\n \n for i in num... | class Solution(object):
def maximumProduct(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 45.2 | Level 1 | Hi |
non-overlapping-intervals | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of intervals <code>intervals</code> where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, return <em>the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> intervals = [[1,2],[2,3],[3,4],[1,3]]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> [1,3] can be removed and the rest of the intervals are non-overlapping.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> intervals = [[1,2],[1,2],[1,2]]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> You need to remove two [1,2] to make the rest of the intervals non-overlapping.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> intervals = [[1,2],[2,3]]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> You don't need to remove any of the intervals since they're already non-overlapping.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= intervals.length <= 10<sup>5</sup></code></li>\n\t<li><code>intervals[i].length == 2</code></li>\n\t<li><code>-5 * 10<sup>4</sup> <= start<sub>i</sub> < end<sub>i</sub> <= 5 * 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "435",
"questionId": "435",
"questionTitle": "Non-overlapping Intervals",
"questionTitleSlug": "non-overlapping-intervals",
"similarQuestions": "[{\"title\": \"Minimum Number of Arrows to Burst Balloons\", \"titleSlug\": \"minimum-number-of-arrows-to-burst-balloons\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Determine if Two Events Have Conflict\", \"titleSlug\": \"determine-if-two-events-have-conflict\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"494.8K\", \"totalSubmission\": \"941.8K\", \"totalAcceptedRaw\": 494800, \"totalSubmissionRaw\": 941825, \"acRate\": \"52.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 435 | Medium | [
"Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.\n\n \nExample 1:\n\nInput: intervals = [[1,2],[2,3],[3,4],[1,3]]\nOutput: 1\nExplanation: [1,3] can be removed and the rest of the ... | [
{
"hash": -7083936888806813000,
"runtime": "1311ms",
"solution": "class Solution:\n def eraseOverlapIntervals(self, intervals: List[List[int]]) -> int:\n if not intervals: return 0\n intervals.sort(key = lambda x: x[1])\n \n endpoints = collections.defaultdict(list)\n ... | class Solution(object):
def eraseOverlapIntervals(self, intervals):
"""
:type intervals: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 52.5 | Level 3 | Hi |
subtree-of-another-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the roots of two binary trees <code>root</code> and <code>subRoot</code>, return <code>true</code> if there is a subtree of <code>root</code> with the same structure and node values of<code> subRoot</code> and <code>false</code> otherwise.</p>\n\n<p>A subtree of a binary tree <code>tree</code> is a tree that consists of a node in <code>tree</code> and all of this node's descendants. The tree <code>tree</code> could also be considered as a subtree of itself.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/28/subtree1-tree.jpg\" style=\"width: 532px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> root = [3,4,5,1,2], subRoot = [4,1,2]\n<strong>Output:</strong> true\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/28/subtree2-tree.jpg\" style=\"width: 502px; height: 458px;\" />\n<pre>\n<strong>Input:</strong> root = [3,4,5,1,2,null,null,null,null,0], subRoot = [4,1,2]\n<strong>Output:</strong> false\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the <code>root</code> tree is in the range <code>[1, 2000]</code>.</li>\n\t<li>The number of nodes in the <code>subRoot</code> tree is in the range <code>[1, 1000]</code>.</li>\n\t<li><code>-10<sup>4</sup> <= root.val <= 10<sup>4</sup></code></li>\n\t<li><code>-10<sup>4</sup> <= subRoot.val <= 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "572",
"questionId": "572",
"questionTitle": "Subtree of Another Tree",
"questionTitleSlug": "subtree-of-another-tree",
"similarQuestions": "[{\"title\": \"Count Univalue Subtrees\", \"titleSlug\": \"count-univalue-subtrees\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Most Frequent Subtree Sum\", \"titleSlug\": \"most-frequent-subtree-sum\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"761.3K\", \"totalSubmission\": \"1.6M\", \"totalAcceptedRaw\": 761261, \"totalSubmissionRaw\": 1610729, \"acRate\": \"47.3%\"}",
"topicTags": [
{
"name": "Tree",
"slug": "tree"
},
{
"name": "Depth-First Search",
"slug": "depth-first-search"
},
{
"name": "String Matching",
"slug": "string-matching"
},
{
"name": "Binary Tree",
"slug": "binary-tree"
},
{
"name": "Hash Function",
"slug": "hash-function"
}
]
}
}
} | 572 | Easy | [
"Given the roots of two binary trees root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise.\n\nA subtree of a binary tree tree is a tree that consists of a node in tree and all of this node's descendants. The tree tree could also be consid... | [
{
"hash": -8489564135603414000,
"runtime": "120ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def ... | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def isSubtree(self, root, subRoot):
"""
:type root: TreeNode
:type subRoot: TreeNode
:rtype: bool
"""
| None | None | None | None | None | None | 47.3 | Level 1 | Hi |
partition-equal-subset-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code>, return <code>true</code> <em>if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or </em><code>false</code><em> otherwise</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,5,11,5]\n<strong>Output:</strong> true\n<strong>Explanation:</strong> The array can be partitioned as [1, 5, 5] and [11].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3,5]\n<strong>Output:</strong> false\n<strong>Explanation:</strong> The array cannot be partitioned into equal sum subsets.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 200</code></li>\n\t<li><code>1 <= nums[i] <= 100</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "416",
"questionId": "416",
"questionTitle": "Partition Equal Subset Sum",
"questionTitleSlug": "partition-equal-subset-sum",
"similarQuestions": "[{\"title\": \"Partition to K Equal Sum Subsets\", \"titleSlug\": \"partition-to-k-equal-sum-subsets\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Minimize the Difference Between Target and Chosen Elements\", \"titleSlug\": \"minimize-the-difference-between-target-and-chosen-elements\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximum Number of Ways to Partition an Array\", \"titleSlug\": \"maximum-number-of-ways-to-partition-an-array\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Partition Array Into Two Arrays to Minimize Sum Difference\", \"titleSlug\": \"partition-array-into-two-arrays-to-minimize-sum-difference\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Find Subarrays With Equal Sum\", \"titleSlug\": \"find-subarrays-with-equal-sum\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Number of Great Partitions\", \"titleSlug\": \"number-of-great-partitions\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Split With Minimum Sum\", \"titleSlug\": \"split-with-minimum-sum\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"738.3K\", \"totalSubmission\": \"1.6M\", \"totalAcceptedRaw\": 738265, \"totalSubmissionRaw\": 1598393, \"acRate\": \"46.2%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
}
]
}
}
} | 416 | Medium | [
"Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.\n\n \nExample 1:\n\nInput: nums = [1,5,11,5]\nOutput: true\nExplanation: The array can be partitioned as [1, 5, 5] and [11].\n\n\nExample 2:\n\nInp... | [
{
"hash": -487506784344517440,
"runtime": "4863ms",
"solution": "class Solution(object):\n def canPartition(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n # if sum(nums) %2 == 1:\n # return False\n # dp = set()\n # d... | class Solution(object):
def canPartition(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 46.2 | Level 4 | Hi |
maximum-sum-of-an-hourglass | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p>\n\n<p>We define an <strong>hourglass</strong> as a part of the matrix with the following form:</p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/08/21/img.jpg\" style=\"width: 243px; height: 243px;\" />\n<p>Return <em>the <strong>maximum</strong> sum of the elements of an hourglass</em>.</p>\n\n<p><strong>Note</strong> that an hourglass cannot be rotated and must be entirely contained within the matrix.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/08/21/1.jpg\" style=\"width: 323px; height: 323px;\" />\n<pre>\n<strong>Input:</strong> grid = [[6,2,1,3],[4,2,1,5],[9,2,8,7],[4,1,2,9]]\n<strong>Output:</strong> 30\n<strong>Explanation:</strong> The cells shown above represent the hourglass with the maximum sum: 6 + 2 + 1 + 2 + 9 + 2 + 8 = 30.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/08/21/2.jpg\" style=\"width: 243px; height: 243px;\" />\n<pre>\n<strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]\n<strong>Output:</strong> 35\n<strong>Explanation:</strong> There is only one hourglass in the matrix, with the sum: 1 + 2 + 3 + 5 + 7 + 8 + 9 = 35.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>3 <= m, n <= 150</code></li>\n\t<li><code>0 <= grid[i][j] <= 10<sup>6</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2428",
"questionId": "2508",
"questionTitle": "Maximum Sum of an Hourglass",
"questionTitleSlug": "maximum-sum-of-an-hourglass",
"similarQuestions": "[{\"title\": \"Matrix Block Sum\", \"titleSlug\": \"matrix-block-sum\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"33.8K\", \"totalSubmission\": \"45.2K\", \"totalAcceptedRaw\": 33767, \"totalSubmissionRaw\": 45172, \"acRate\": \"74.8%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Matrix",
"slug": "matrix"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
}
]
}
}
} | 2428 | Medium | [
"You are given an m x n integer matrix grid.\n\nWe define an hourglass as a part of the matrix with the following form:\n\nReturn the maximum sum of the elements of an hourglass.\n\nNote that an hourglass cannot be rotated and must be entirely contained within the matrix.\n\n \nExample 1:\n\nInput: grid = [[6,2,1,3... | [
{
"hash": -8323415180883254000,
"runtime": "186ms",
"solution": "class Solution(object):\n def maxSum(self, grid):\n ans = -float('inf')\n for i in xrange(len(grid)-2):\n for j in xrange(len(grid[0])-2):\n val = 0\n for a in xrange(3):\n ... | class Solution(object):
def maxSum(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 74.8 | Level 2 | Hi |
maximal-square | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an <code>m x n</code> binary <code>matrix</code> filled with <code>0</code>'s and <code>1</code>'s, <em>find the largest square containing only</em> <code>1</code>'s <em>and return its area</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/11/26/max1grid.jpg\" style=\"width: 400px; height: 319px;\" />\n<pre>\n<strong>Input:</strong> matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]\n<strong>Output:</strong> 4\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/11/26/max2grid.jpg\" style=\"width: 165px; height: 165px;\" />\n<pre>\n<strong>Input:</strong> matrix = [["0","1"],["1","0"]]\n<strong>Output:</strong> 1\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> matrix = [["0"]]\n<strong>Output:</strong> 0\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == matrix.length</code></li>\n\t<li><code>n == matrix[i].length</code></li>\n\t<li><code>1 <= m, n <= 300</code></li>\n\t<li><code>matrix[i][j]</code> is <code>'0'</code> or <code>'1'</code>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "221",
"questionId": "221",
"questionTitle": "Maximal Square",
"questionTitleSlug": "maximal-square",
"similarQuestions": "[{\"title\": \"Maximal Rectangle\", \"titleSlug\": \"maximal-rectangle\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Largest Plus Sign\", \"titleSlug\": \"largest-plus-sign\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Count Artifacts That Can Be Extracted\", \"titleSlug\": \"count-artifacts-that-can-be-extracted\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Stamping the Grid\", \"titleSlug\": \"stamping-the-grid\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Maximize Area of Square Hole in Grid\", \"titleSlug\": \"maximize-area-of-square-hole-in-grid\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"636.6K\", \"totalSubmission\": \"1.4M\", \"totalAcceptedRaw\": 636642, \"totalSubmissionRaw\": 1385447, \"acRate\": \"46.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 221 | Medium | [
"Given an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.\n\n \nExample 1:\n\nInput: matrix = [[\"1\",\"0\",\"1\",\"0\",\"0\"],[\"1\",\"0\",\"1\",\"1\",\"1\"],[\"1\",\"1\",\"1\",\"1\",\"1\"],[\"1\",\"0\",\"0\",\"1\",\"0\"]]\nOutput: 4\n\n\nExample 2:\n\n... | [
{
"hash": -5784149520173104000,
"runtime": "1778ms",
"solution": "import numpy as np\n\nclass Solution:\n def maximalSquare(self, matrix: List[List[str]]) -> int:\n\n matrix = np.array(matrix, dtype=np.intc)\n n, m = len(matrix), len(matrix[0])\n max = 0\n\n for i in range... | class Solution(object):
def maximalSquare(self, matrix):
"""
:type matrix: List[List[str]]
:rtype: int
"""
| None | None | None | None | None | None | 46 | Level 4 | Hi |
minimum-value-to-get-positive-step-by-step-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>nums</code>, you start with an initial <strong>positive</strong> value <em>startValue</em><em>.</em></p>\n\n<p>In each iteration, you calculate the step by step sum of <em>startValue</em> plus elements in <code>nums</code> (from left to right).</p>\n\n<p>Return the minimum <strong>positive</strong> value of <em>startValue</em> such that the step by step sum is never less than 1.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-3,2,-3,4,2]\n<strong>Output:</strong> 5\n<strong>Explanation: </strong>If you choose startValue = 4, in the third iteration your step by step sum is less than 1.\n<strong>step by step sum</strong>\n<strong>startValue = 4 | startValue = 5 | nums</strong>\n (4 <strong>-3</strong> ) = 1 | (5 <strong>-3</strong> ) = 2 | -3\n (1 <strong>+2</strong> ) = 3 | (2 <strong>+2</strong> ) = 4 | 2\n (3 <strong>-3</strong> ) = 0 | (4 <strong>-3</strong> ) = 1 | -3\n (0 <strong>+4</strong> ) = 4 | (1 <strong>+4</strong> ) = 5 | 4\n (4 <strong>+2</strong> ) = 6 | (5 <strong>+2</strong> ) = 7 | 2\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> Minimum start value should be positive. \n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,-2,-3]\n<strong>Output:</strong> 5\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 100</code></li>\n\t<li><code>-100 <= nums[i] <= 100</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1413",
"questionId": "1514",
"questionTitle": "Minimum Value to Get Positive Step by Step Sum",
"questionTitleSlug": "minimum-value-to-get-positive-step-by-step-sum",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"123.4K\", \"totalSubmission\": \"186.2K\", \"totalAcceptedRaw\": 123373, \"totalSubmissionRaw\": 186180, \"acRate\": \"66.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
}
]
}
}
} | 1413 | Easy | [
"Given an array of integers nums, you start with an initial positive value startValue.\n\nIn each iteration, you calculate the step by step sum of startValue plus elements in nums (from left to right).\n\nReturn the minimum positive value of startValue such that the step by step sum is never less than 1.\n\n \nExam... | [
{
"hash": -7887458738458694000,
"runtime": "19ms",
"solution": "class Solution(object):\n def minStartValue(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n min_val = nums[0]\n for i in range(1, len(nums)):\n nums[i] += nums[i... | class Solution(object):
def minStartValue(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 66.3 | Level 1 | Hi |
video-stitching | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a series of video clips from a sporting event that lasted <code>time</code> seconds. These video clips can be overlapping with each other and have varying lengths.</p>\n\n<p>Each video clip is described by an array <code>clips</code> where <code>clips[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> indicates that the ith clip started at <code>start<sub>i</sub></code> and ended at <code>end<sub>i</sub></code>.</p>\n\n<p>We can cut these clips into segments freely.</p>\n\n<ul>\n\t<li>For example, a clip <code>[0, 7]</code> can be cut into segments <code>[0, 1] + [1, 3] + [3, 7]</code>.</li>\n</ul>\n\n<p>Return <em>the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event</em> <code>[0, time]</code>. If the task is impossible, return <code>-1</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> We take the clips [0,2], [8,10], [1,9]; a total of 3 clips.\nThen, we can reconstruct the sporting event as follows:\nWe cut [1,9] into segments [1,2] + [2,8] + [8,9].\nNow we have segments [0,2] + [2,8] + [8,10] which cover the sporting event [0, 10].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> clips = [[0,1],[1,2]], time = 5\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> We cannot cover [0,5] with only [0,1] and [1,2].\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time = 9\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> We can take clips [0,4], [4,7], and [6,9].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= clips.length <= 100</code></li>\n\t<li><code>0 <= start<sub>i</sub> <= end<sub>i</sub> <= 100</code></li>\n\t<li><code>1 <= time <= 100</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1024",
"questionId": "1081",
"questionTitle": "Video Stitching",
"questionTitleSlug": "video-stitching",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"64.3K\", \"totalSubmission\": \"126K\", \"totalAcceptedRaw\": 64304, \"totalSubmissionRaw\": 126000, \"acRate\": \"51.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Greedy",
"slug": "greedy"
}
]
}
}
} | 1024 | Medium | [
"You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.\n\nEach video clip is described by an array clips where clips[i] = [starti, endi] indicates that the ith clip started at starti and ended at endi.\n\n... | [
{
"hash": -8103712928964960000,
"runtime": "16ms",
"solution": "class Solution(object):\n def videoStitching(self, clips, time):\n \"\"\"\n :type clips: List[List[int]]\n :type time: int\n :rtype: int\n \"\"\"\n clips.sort(key = lambda x: (x[0], -x[1]))\n ... | class Solution(object):
def videoStitching(self, clips, time):
"""
:type clips: List[List[int]]
:type time: int
:rtype: int
"""
| None | None | None | None | None | None | 51 | Level 3 | Hi |
find-the-maximum-divisibility-score | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>divisors</code>.</p>\n\n<p>The <strong>divisibility score</strong> of <code>divisors[i]</code> is the number of indices <code>j</code> such that <code>nums[j]</code> is divisible by <code>divisors[i]</code>.</p>\n\n<p>Return <em>the integer</em> <code>divisors[i]</code> <em>with the maximum divisibility score</em>. If there is more than one integer with the maximum score, return the minimum of them.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [4,7,9,3,9], divisors = [5,2,3]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The divisibility score for every element in divisors is:\nThe divisibility score of divisors[0] is 0 since no number in nums is divisible by 5.\nThe divisibility score of divisors[1] is 1 since nums[0] is divisible by 2.\nThe divisibility score of divisors[2] is 3 since nums[2], nums[3], and nums[4] are divisible by 3.\nSince divisors[2] has the maximum divisibility score, we return it.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [20,14,21,10], divisors = [5,7,5]\n<strong>Output:</strong> 5\n<strong>Explanation:</strong> The divisibility score for every element in divisors is:\nThe divisibility score of divisors[0] is 2 since nums[0] and nums[3] are divisible by 5.\nThe divisibility score of divisors[1] is 2 since nums[1] and nums[2] are divisible by 7.\nThe divisibility score of divisors[2] is 2 since nums[0] and nums[3] are divisible by 5.\nSince divisors[0], divisors[1], and divisors[2] all have the maximum divisibility score, we return the minimum of them (i.e., divisors[2]).\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [12], divisors = [10,16]\n<strong>Output:</strong> 10\n<strong>Explanation:</strong> The divisibility score for every element in divisors is:\nThe divisibility score of divisors[0] is 0 since no number in nums is divisible by 10.\nThe divisibility score of divisors[1] is 0 since no number in nums is divisible by 16.\nSince divisors[0] and divisors[1] both have the maximum divisibility score, we return the minimum of them (i.e., divisors[0]).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length, divisors.length <= 1000</code></li>\n\t<li><code>1 <= nums[i], divisors[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2644",
"questionId": "2694",
"questionTitle": "Find the Maximum Divisibility Score",
"questionTitleSlug": "find-the-maximum-divisibility-score",
"similarQuestions": "[{\"title\": \"Binary Prefix Divisible By 5\", \"titleSlug\": \"binary-prefix-divisible-by-5\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"26.7K\", \"totalSubmission\": \"55.2K\", \"totalAcceptedRaw\": 26716, \"totalSubmissionRaw\": 55159, \"acRate\": \"48.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
}
]
}
}
} | 2644 | Easy | [
"You are given two 0-indexed integer arrays nums and divisors.\n\nThe divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].\n\nReturn the integer divisors[i] with the maximum divisibility score. If there is more than one integer with the maximum score, return th... | [
{
"hash": -3552590116606075400,
"runtime": "3255ms",
"solution": "class Solution(object):\n def maxDivScore(self, nums, divisors):\n \"\"\"\n :type nums: List[int]\n :type divisors: List[int]\n :rtype: int\n \"\"\"\n\n divisors = sorted(divisors)\n\n m... | class Solution(object):
def maxDivScore(self, nums, divisors):
"""
:type nums: List[int]
:type divisors: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 48.4 | Level 1 | Hi |
final-value-of-variable-after-performing-operations | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a programming language with only <strong>four</strong> operations and <strong>one</strong> variable <code>X</code>:</p>\n\n<ul>\n\t<li><code>++X</code> and <code>X++</code> <strong>increments</strong> the value of the variable <code>X</code> by <code>1</code>.</li>\n\t<li><code>--X</code> and <code>X--</code> <strong>decrements</strong> the value of the variable <code>X</code> by <code>1</code>.</li>\n</ul>\n\n<p>Initially, the value of <code>X</code> is <code>0</code>.</p>\n\n<p>Given an array of strings <code>operations</code> containing a list of operations, return <em>the <strong>final </strong>value of </em><code>X</code> <em>after performing all the operations</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> operations = ["--X","X++","X++"]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The operations are performed as follows:\nInitially, X = 0.\n--X: X is decremented by 1, X = 0 - 1 = -1.\nX++: X is incremented by 1, X = -1 + 1 = 0.\nX++: X is incremented by 1, X = 0 + 1 = 1.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> operations = ["++X","++X","X++"]\n<strong>Output:</strong> 3\n<strong>Explanation: </strong>The operations are performed as follows:\nInitially, X = 0.\n++X: X is incremented by 1, X = 0 + 1 = 1.\n++X: X is incremented by 1, X = 1 + 1 = 2.\nX++: X is incremented by 1, X = 2 + 1 = 3.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> operations = ["X++","++X","--X","X--"]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> The operations are performed as follows:\nInitially, X = 0.\nX++: X is incremented by 1, X = 0 + 1 = 1.\n++X: X is incremented by 1, X = 1 + 1 = 2.\n--X: X is decremented by 1, X = 2 - 1 = 1.\nX--: X is decremented by 1, X = 1 - 1 = 0.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= operations.length <= 100</code></li>\n\t<li><code>operations[i]</code> will be either <code>"++X"</code>, <code>"X++"</code>, <code>"--X"</code>, or <code>"X--"</code>.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2011",
"questionId": "2137",
"questionTitle": "Final Value of Variable After Performing Operations",
"questionTitleSlug": "final-value-of-variable-after-performing-operations",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"303.4K\", \"totalSubmission\": \"342.5K\", \"totalAcceptedRaw\": 303390, \"totalSubmissionRaw\": 342510, \"acRate\": \"88.6%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Simulation",
"slug": "simulation"
}
]
}
}
} | 2011 | Easy | [
"There is a programming language with only four operations and one variable X:\n\n\n\t++X and X++ increments the value of the variable X by 1.\n\t--X and X-- decrements the value of the variable X by 1.\n\n\nInitially, the value of X is 0.\n\nGiven an array of strings operations containing a list of operations, ret... | [
{
"hash": 191075733593092400,
"runtime": "36ms",
"solution": "class Solution(object):\n def finalValueAfterOperations(self, operations):\n \"\"\"\n :type operations: List[str]\n :rtype: int\n \"\"\"\n \n num = 0 \n\n operation_dict = {\"--X\": -1,\"X--... | class Solution(object):
def finalValueAfterOperations(self, operations):
"""
:type operations: List[str]
:rtype: int
"""
| None | None | None | None | None | None | 88.6 | Level 1 | Hi |
number-of-pairs-of-interchangeable-rectangles | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given <code>n</code> rectangles represented by a <strong>0-indexed</strong> 2D integer array <code>rectangles</code>, where <code>rectangles[i] = [width<sub>i</sub>, height<sub>i</sub>]</code> denotes the width and height of the <code>i<sup>th</sup></code> rectangle.</p>\n\n<p>Two rectangles <code>i</code> and <code>j</code> (<code>i < j</code>) are considered <strong>interchangeable</strong> if they have the <strong>same</strong> width-to-height ratio. More formally, two rectangles are <strong>interchangeable</strong> if <code>width<sub>i</sub>/height<sub>i</sub> == width<sub>j</sub>/height<sub>j</sub></code> (using decimal division, not integer division).</p>\n\n<p>Return <em>the <strong>number</strong> of pairs of <strong>interchangeable</strong> rectangles in </em><code>rectangles</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> rectangles = [[4,8],[3,6],[10,20],[15,30]]\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> The following are the interchangeable pairs of rectangles by index (0-indexed):\n- Rectangle 0 with rectangle 1: 4/8 == 3/6.\n- Rectangle 0 with rectangle 2: 4/8 == 10/20.\n- Rectangle 0 with rectangle 3: 4/8 == 15/30.\n- Rectangle 1 with rectangle 2: 3/6 == 10/20.\n- Rectangle 1 with rectangle 3: 3/6 == 15/30.\n- Rectangle 2 with rectangle 3: 10/20 == 15/30.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> rectangles = [[4,5],[7,8]]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> There are no interchangeable pairs of rectangles.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == rectangles.length</code></li>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>rectangles[i].length == 2</code></li>\n\t<li><code>1 <= width<sub>i</sub>, height<sub>i</sub> <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2001",
"questionId": "2129",
"questionTitle": "Number of Pairs of Interchangeable Rectangles",
"questionTitleSlug": "number-of-pairs-of-interchangeable-rectangles",
"similarQuestions": "[{\"title\": \"Number of Good Pairs\", \"titleSlug\": \"number-of-good-pairs\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Count Nice Pairs in an Array\", \"titleSlug\": \"count-nice-pairs-in-an-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Replace Non-Coprime Numbers in Array\", \"titleSlug\": \"replace-non-coprime-numbers-in-array\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"33.4K\", \"totalSubmission\": \"69.1K\", \"totalAcceptedRaw\": 33408, \"totalSubmissionRaw\": 69079, \"acRate\": \"48.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Counting",
"slug": "counting"
},
{
"name": "Number Theory",
"slug": "number-theory"
}
]
}
}
} | 2001 | Medium | [
"You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle.\n\nTwo rectangles i and j (i < j) are considered interchangeable if they have the same width-to-height ratio. More formally, two rectangles a... | [
{
"hash": 4464700023722010600,
"runtime": "1307ms",
"solution": "class Solution(object):\n def interchangeableRectangles(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: int\n \"\"\"\n \n ratios = [0 for _ in range(len(rectangles))]\n... | class Solution(object):
def interchangeableRectangles(self, rectangles):
"""
:type rectangles: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 48.4 | Level 3 | Hi |
convert-to-base-2 | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer <code>n</code>, return <em>a binary string representing its representation in base</em> <code>-2</code>.</p>\n\n<p><strong>Note</strong> that the returned string should not have leading zeros unless the string is <code>"0"</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> "110"\n<strong>Explantion:</strong> (-2)<sup>2</sup> + (-2)<sup>1</sup> = 2\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3\n<strong>Output:</strong> "111"\n<strong>Explantion:</strong> (-2)<sup>2</sup> + (-2)<sup>1</sup> + (-2)<sup>0</sup> = 3\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4\n<strong>Output:</strong> "100"\n<strong>Explantion:</strong> (-2)<sup>2</sup> = 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= n <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1017",
"questionId": "1070",
"questionTitle": "Convert to Base -2",
"questionTitleSlug": "convert-to-base-2",
"similarQuestions": "[{\"title\": \"Encode Number\", \"titleSlug\": \"encode-number\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"24.9K\", \"totalSubmission\": \"41.2K\", \"totalAcceptedRaw\": 24908, \"totalSubmissionRaw\": 41155, \"acRate\": \"60.5%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
}
]
}
}
} | 1017 | Medium | [
"Given an integer n, return a binary string representing its representation in base -2.\n\nNote that the returned string should not have leading zeros unless the string is \"0\".\n\n \nExample 1:\n\nInput: n = 2\nOutput: \"110\"\nExplantion: (-2)² + (-2)¹ = 2\n\n\nExample 2:\n\nInput: n = 3\nOutput: \"111\"\nExplan... | [
{
"hash": 1861381066019982800,
"runtime": "4ms",
"solution": "class Solution(object):\n def baseNeg2(self, n):\n \"\"\"\n :type n: int\n :rtype: str\n \"\"\"\n if n==0:\n return \"0\"\n res=\"\"\n\n while n!=0:\n if n%-2 == 0:\n ... | class Solution(object):
def baseNeg2(self, n):
"""
:type n: int
:rtype: str
"""
| None | None | None | None | None | None | 60.5 | Level 2 | Hi |
minimum-time-visiting-all-points | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>On a 2D plane, there are <code>n</code> points with integer coordinates <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. Return <em>the <strong>minimum time</strong> in seconds to visit all the points in the order given by </em><code>points</code>.</p>\n\n<p>You can move according to these rules:</p>\n\n<ul>\n\t<li>In <code>1</code> second, you can either:\n\n\t<ul>\n\t\t<li>move vertically by one unit,</li>\n\t\t<li>move horizontally by one unit, or</li>\n\t\t<li>move diagonally <code>sqrt(2)</code> units (in other words, move one unit vertically then one unit horizontally in <code>1</code> second).</li>\n\t</ul>\n\t</li>\n\t<li>You have to visit the points in the same order as they appear in the array.</li>\n\t<li>You are allowed to pass through points that appear later in the order, but these do not count as visits.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/11/14/1626_example_1.PNG\" style=\"width: 500px; height: 428px;\" />\n<pre>\n<strong>Input:</strong> points = [[1,1],[3,4],[-1,0]]\n<strong>Output:</strong> 7\n<strong>Explanation: </strong>One optimal path is <strong>[1,1]</strong> -> [2,2] -> [3,3] -> <strong>[3,4] </strong>-> [2,3] -> [1,2] -> [0,1] -> <strong>[-1,0]</strong> \nTime from [1,1] to [3,4] = 3 seconds \nTime from [3,4] to [-1,0] = 4 seconds\nTotal time = 7 seconds</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> points = [[3,2],[-2,2]]\n<strong>Output:</strong> 5\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>points.length == n</code></li>\n\t<li><code>1 <= n <= 100</code></li>\n\t<li><code>points[i].length == 2</code></li>\n\t<li><code>-1000 <= points[i][0], points[i][1] <= 1000</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1266",
"questionId": "1395",
"questionTitle": "Minimum Time Visiting All Points",
"questionTitleSlug": "minimum-time-visiting-all-points",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"215.2K\", \"totalSubmission\": \"261K\", \"totalAcceptedRaw\": 215223, \"totalSubmissionRaw\": 260964, \"acRate\": \"82.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Geometry",
"slug": "geometry"
}
]
}
}
} | 1266 | Easy | [
"On a 2D plane, there are n points with integer coordinates points[i] = [xi, yi]. Return the minimum time in seconds to visit all the points in the order given by points.\n\nYou can move according to these rules:\n\n\n\tIn 1 second, you can either:\n\n\t\n\t\tmove vertically by one unit,\n\t\tmove horizontally by o... | [
{
"hash": 6490072391797084000,
"runtime": "29ms",
"solution": "class Solution(object):\n def minTimeToVisitAllPoints(self, points):\n x,y = points.pop(0)\n cnt = 0\n for a,b in points:\n cnt += max(abs(x-a),abs(y-b))\n x,y = a,b\n return cnt"
},
{... | class Solution(object):
def minTimeToVisitAllPoints(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 82.5 | Level 1 | Hi |
minimum-cost-for-tickets | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array <code>days</code>. Each day is an integer from <code>1</code> to <code>365</code>.</p>\n\n<p>Train tickets are sold in <strong>three different ways</strong>:</p>\n\n<ul>\n\t<li>a <strong>1-day</strong> pass is sold for <code>costs[0]</code> dollars,</li>\n\t<li>a <strong>7-day</strong> pass is sold for <code>costs[1]</code> dollars, and</li>\n\t<li>a <strong>30-day</strong> pass is sold for <code>costs[2]</code> dollars.</li>\n</ul>\n\n<p>The passes allow that many days of consecutive travel.</p>\n\n<ul>\n\t<li>For example, if we get a <strong>7-day</strong> pass on day <code>2</code>, then we can travel for <code>7</code> days: <code>2</code>, <code>3</code>, <code>4</code>, <code>5</code>, <code>6</code>, <code>7</code>, and <code>8</code>.</li>\n</ul>\n\n<p>Return <em>the minimum number of dollars you need to travel every day in the given list of days</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> days = [1,4,6,7,8,20], costs = [2,7,15]\n<strong>Output:</strong> 11\n<strong>Explanation:</strong> For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 1-day pass for costs[0] = $2, which covered day 1.\nOn day 3, you bought a 7-day pass for costs[1] = $7, which covered days 3, 4, ..., 9.\nOn day 20, you bought a 1-day pass for costs[0] = $2, which covered day 20.\nIn total, you spent $11 and covered all the days of your travel.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> days = [1,2,3,4,5,6,7,8,9,10,30,31], costs = [2,7,15]\n<strong>Output:</strong> 17\n<strong>Explanation:</strong> For example, here is one way to buy passes that lets you travel your travel plan:\nOn day 1, you bought a 30-day pass for costs[2] = $15 which covered days 1, 2, ..., 30.\nOn day 31, you bought a 1-day pass for costs[0] = $2 which covered day 31.\nIn total, you spent $17 and covered all the days of your travel.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= days.length <= 365</code></li>\n\t<li><code>1 <= days[i] <= 365</code></li>\n\t<li><code>days</code> is in strictly increasing order.</li>\n\t<li><code>costs.length == 3</code></li>\n\t<li><code>1 <= costs[i] <= 1000</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "983",
"questionId": "1025",
"questionTitle": "Minimum Cost For Tickets",
"questionTitleSlug": "minimum-cost-for-tickets",
"similarQuestions": "[{\"title\": \"Coin Change\", \"titleSlug\": \"coin-change\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"270.1K\", \"totalSubmission\": \"412.5K\", \"totalAcceptedRaw\": 270132, \"totalSubmissionRaw\": 412479, \"acRate\": \"65.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
}
]
}
}
} | 983 | Medium | [
"You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365.\n\nTrain tickets are sold in three different ways:\n\n\n\ta 1-day pass is sold for costs[0] dollars,\n\ta 7-day pass is sold for costs[1... | [
{
"hash": 5405927465847063000,
"runtime": "64ms",
"solution": "class Solution:\n def mincostTickets(self, days: List[int], costs: List[int]) -> int:\n # dp function returning min cost for tickets on day \"i\" \n # considering that tickers are paid through \"paid_days\" day\n @ca... | class Solution(object):
def mincostTickets(self, days, costs):
"""
:type days: List[int]
:type costs: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 65.5 | Level 2 | Hi |
reshape-the-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>In MATLAB, there is a handy function called <code>reshape</code> which can reshape an <code>m x n</code> matrix into a new one with a different size <code>r x c</code> keeping its original data.</p>\n\n<p>You are given an <code>m x n</code> matrix <code>mat</code> and two integers <code>r</code> and <code>c</code> representing the number of rows and the number of columns of the wanted reshaped matrix.</p>\n\n<p>The reshaped matrix should be filled with all the elements of the original matrix in the same row-traversing order as they were.</p>\n\n<p>If the <code>reshape</code> operation with given parameters is possible and legal, output the new reshaped matrix; Otherwise, output the original matrix.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/24/reshape1-grid.jpg\" style=\"width: 613px; height: 173px;\" />\n<pre>\n<strong>Input:</strong> mat = [[1,2],[3,4]], r = 1, c = 4\n<strong>Output:</strong> [[1,2,3,4]]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/04/24/reshape2-grid.jpg\" style=\"width: 453px; height: 173px;\" />\n<pre>\n<strong>Input:</strong> mat = [[1,2],[3,4]], r = 2, c = 4\n<strong>Output:</strong> [[1,2],[3,4]]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == mat.length</code></li>\n\t<li><code>n == mat[i].length</code></li>\n\t<li><code>1 <= m, n <= 100</code></li>\n\t<li><code>-1000 <= mat[i][j] <= 1000</code></li>\n\t<li><code>1 <= r, c <= 300</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "566",
"questionId": "566",
"questionTitle": "Reshape the Matrix",
"questionTitleSlug": "reshape-the-matrix",
"similarQuestions": "[{\"title\": \"Convert 1D Array Into 2D Array\", \"titleSlug\": \"convert-1d-array-into-2d-array\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"364.1K\", \"totalSubmission\": \"577.8K\", \"totalAcceptedRaw\": 364084, \"totalSubmissionRaw\": 577786, \"acRate\": \"63.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Matrix",
"slug": "matrix"
},
{
"name": "Simulation",
"slug": "simulation"
}
]
}
}
} | 566 | Easy | [
"In MATLAB, there is a handy function called reshape which can reshape an m x n matrix into a new one with a different size r x c keeping its original data.\n\nYou are given an m x n matrix mat and two integers r and c representing the number of rows and the number of columns of the wanted reshaped matrix.\n\nThe r... | [
{
"hash": -2301617424342662400,
"runtime": "65ms",
"solution": "class Solution:\n def matrixReshape(self, nums, r, c):\n n = len(nums)\n m = len(nums[0])\n \n if r * c != n * m:\n return nums\n \n res = [[0] * c for _ in range(r)]\n \n ... | class Solution(object):
def matrixReshape(self, mat, r, c):
"""
:type mat: List[List[int]]
:type r: int
:type c: int
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 63 | Level 1 | Hi |
longest-nice-subarray | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array <code>nums</code> consisting of <strong>positive</strong> integers.</p>\n\n<p>We call a subarray of <code>nums</code> <strong>nice</strong> if the bitwise <strong>AND</strong> of every pair of elements that are in <strong>different</strong> positions in the subarray is equal to <code>0</code>.</p>\n\n<p>Return <em>the length of the <strong>longest</strong> nice subarray</em>.</p>\n\n<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>\n\n<p><strong>Note</strong> that subarrays of length <code>1</code> are always considered nice.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3,8,48,10]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The longest nice subarray is [3,8,48]. This subarray satisfies the conditions:\n- 3 AND 8 = 0.\n- 3 AND 48 = 0.\n- 8 AND 48 = 0.\nIt can be proven that no longer nice subarray can be obtained, so we return 3.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,1,5,11,13]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The length of the longest nice subarray is 1. Any subarray of length 1 can be chosen.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2401",
"questionId": "2478",
"questionTitle": "Longest Nice Subarray",
"questionTitleSlug": "longest-nice-subarray",
"similarQuestions": "[{\"title\": \"Longest Substring Without Repeating Characters\", \"titleSlug\": \"longest-substring-without-repeating-characters\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Bitwise AND of Numbers Range\", \"titleSlug\": \"bitwise-and-of-numbers-range\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Bitwise ORs of Subarrays\", \"titleSlug\": \"bitwise-ors-of-subarrays\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Fruit Into Baskets\", \"titleSlug\": \"fruit-into-baskets\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Max Consecutive Ones III\", \"titleSlug\": \"max-consecutive-ones-iii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Get Equal Substrings Within Budget\", \"titleSlug\": \"get-equal-substrings-within-budget\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Frequency of the Most Frequent Element\", \"titleSlug\": \"frequency-of-the-most-frequent-element\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Longest Substring Of All Vowels in Order\", \"titleSlug\": \"longest-substring-of-all-vowels-in-order\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximize the Confusion of an Exam\", \"titleSlug\": \"maximize-the-confusion-of-an-exam\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximum Sum of Distinct Subarrays With Length K\", \"titleSlug\": \"maximum-sum-of-distinct-subarrays-with-length-k\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"26.4K\", \"totalSubmission\": \"52.6K\", \"totalAcceptedRaw\": 26376, \"totalSubmissionRaw\": 52554, \"acRate\": \"50.2%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Bit Manipulation",
"slug": "bit-manipulation"
},
{
"name": "Sliding Window",
"slug": "sliding-window"
}
]
}
}
} | 2401 | Medium | [
"You are given an array nums consisting of positive integers.\n\nWe call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0.\n\nReturn the length of the longest nice subarray.\n\nA subarray is a contiguous part of an array.\n\nNote that... | [
{
"hash": -614732005163883500,
"runtime": "2396ms",
"solution": "class Solution(object):\n def check(self, array):\n for i in range(len(array)):\n for j in range(i + 1, len(array)):\n if array[i] & array[j] != 0:\n return False\n return True\... | class Solution(object):
def longestNiceSubarray(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 50.2 | Level 3 | Hi |
decrease-elements-to-make-array-zigzag | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array <code>nums</code> of integers, a <em>move</em> consists of choosing any element and <strong>decreasing it by 1</strong>.</p>\n\n<p>An array <code>A</code> is a <em>zigzag array</em> if either:</p>\n\n<ul>\n\t<li>Every even-indexed element is greater than adjacent elements, ie. <code>A[0] > A[1] < A[2] > A[3] < A[4] > ...</code></li>\n\t<li>OR, every odd-indexed element is greater than adjacent elements, ie. <code>A[0] < A[1] > A[2] < A[3] > A[4] < ...</code></li>\n</ul>\n\n<p>Return the minimum number of moves to transform the given array <code>nums</code> into a zigzag array.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> We can decrease 2 to 0 or 3 to 1.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [9,6,1,6,2]\n<strong>Output:</strong> 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 1000</code></li>\n\t<li><code>1 <= nums[i] <= 1000</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1144",
"questionId": "1247",
"questionTitle": "Decrease Elements To Make Array Zigzag",
"questionTitleSlug": "decrease-elements-to-make-array-zigzag",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"19K\", \"totalSubmission\": \"39.9K\", \"totalAcceptedRaw\": 19046, \"totalSubmissionRaw\": 39927, \"acRate\": \"47.7%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Greedy",
"slug": "greedy"
}
]
}
}
} | 1144 | Medium | [
"Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.\n\nAn array A is a zigzag array if either:\n\n\n\tEvery even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...\n\tOR, every odd-indexed element is greater than adjacent eleme... | [
{
"hash": -5988558129430861000,
"runtime": "8ms",
"solution": "class Solution(object):\n def movesToMakeZigzag(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n length = len(nums)\n \n if length == 1: return 0\n if length ==... | class Solution(object):
def movesToMakeZigzag(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 47.7 | Level 3 | Hi |
minimum-number-of-operations-to-make-array-empty | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>\n\n<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>\n\n<ul>\n\t<li>Choose <strong>two</strong> elements with <strong>equal</strong> values and <strong>delete</strong> them from the array.</li>\n\t<li>Choose <strong>three</strong> elements with <strong>equal</strong> values and <strong>delete</strong> them from the array.</li>\n</ul>\n\n<p>Return <em>the <strong>minimum</strong> number of operations required to make the array empty, or </em><code>-1</code><em> if it is not possible</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,3,3,2,2,4,2,3,4]\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> We can apply the following operations to make the array empty:\n- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].\n- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].\n- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].\n- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].\nIt can be shown that we cannot make the array empty in less than 4 operations.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [2,1,2,2,3,3]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> It is impossible to empty the array.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>6</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2870",
"questionId": "3094",
"questionTitle": "Minimum Number of Operations to Make Array Empty",
"questionTitleSlug": "minimum-number-of-operations-to-make-array-empty",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"24.2K\", \"totalSubmission\": \"50K\", \"totalAcceptedRaw\": 24197, \"totalSubmissionRaw\": 49997, \"acRate\": \"48.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Counting",
"slug": "counting"
}
]
}
}
} | 2870 | Medium | [
"You are given a 0-indexed array nums consisting of positive integers.\n\nThere are two types of operations that you can apply on the array any number of times:\n\n\n\tChoose two elements with equal values and delete them from the array.\n\tChoose three elements with equal values and delete them from the array.\n\n... | [
{
"hash": -6400068516079266000,
"runtime": "649ms",
"solution": "class Solution(object):\n def minOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n ans = 0\n m = Counter(nums)\n print(m)\n for (k,v) in m.items():\... | class Solution(object):
def minOperations(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 48.4 | Level 3 | Hi |
split-linked-list-in-parts | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>head</code> of a singly linked list and an integer <code>k</code>, split the linked list into <code>k</code> consecutive linked list parts.</p>\n\n<p>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.</p>\n\n<p>The parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.</p>\n\n<p>Return <em>an array of the </em><code>k</code><em> parts</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/13/split1-lc.jpg\" style=\"width: 400px; height: 134px;\" />\n<pre>\n<strong>Input:</strong> head = [1,2,3], k = 5\n<strong>Output:</strong> [[1],[2],[3],[],[]]\n<strong>Explanation:</strong>\nThe first element output[0] has output[0].val = 1, output[0].next = null.\nThe last element output[4] is null, but its string representation as a ListNode is [].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/06/13/split2-lc.jpg\" style=\"width: 600px; height: 60px;\" />\n<pre>\n<strong>Input:</strong> head = [1,2,3,4,5,6,7,8,9,10], k = 3\n<strong>Output:</strong> [[1,2,3,4],[5,6,7],[8,9,10]]\n<strong>Explanation:</strong>\nThe input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the list is in the range <code>[0, 1000]</code>.</li>\n\t<li><code>0 <= Node.val <= 1000</code></li>\n\t<li><code>1 <= k <= 50</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "725",
"questionId": "725",
"questionTitle": "Split Linked List in Parts",
"questionTitleSlug": "split-linked-list-in-parts",
"similarQuestions": "[{\"title\": \"Rotate List\", \"titleSlug\": \"rotate-list\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Odd Even Linked List\", \"titleSlug\": \"odd-even-linked-list\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Split a Circular Linked List\", \"titleSlug\": \"split-a-circular-linked-list\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"188.1K\", \"totalSubmission\": \"294.5K\", \"totalAcceptedRaw\": 188054, \"totalSubmissionRaw\": 294546, \"acRate\": \"63.8%\"}",
"topicTags": [
{
"name": "Linked List",
"slug": "linked-list"
}
]
}
}
} | 725 | Medium | [
"Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.\n\nThe 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.\n\nThe parts should be in the order of ... | [
{
"hash": -8559676673913356000,
"runtime": "16ms",
"solution": "# Definition for singly-linked list.\n# class ListNode(object):\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution(object):\n def splitListToParts(self, head, k):\n \... | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def splitListToParts(self, head, k):
"""
:type head: ListNode
:type k: int
:rtype: List[ListNode]
"""
| None | None | None | None | None | None | 63.8 | Level 2 | Hi |
remove-colored-pieces-if-both-neighbors-are-the-same-color | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There are <code>n</code> pieces arranged in a line, and each piece is colored either by <code>'A'</code> or by <code>'B'</code>. You are given a string <code>colors</code> of length <code>n</code> where <code>colors[i]</code> is the color of the <code>i<sup>th</sup></code> piece.</p>\n\n<p>Alice and Bob are playing a game where they take <strong>alternating turns</strong> removing pieces from the line. In this game, Alice moves<strong> first</strong>.</p>\n\n<ul>\n\t<li>Alice is only allowed to remove a piece colored <code>'A'</code> if <strong>both its neighbors</strong> are also colored <code>'A'</code>. She is <strong>not allowed</strong> to remove pieces that are colored <code>'B'</code>.</li>\n\t<li>Bob is only allowed to remove a piece colored <code>'B'</code> if <strong>both its neighbors</strong> are also colored <code>'B'</code>. He is <strong>not allowed</strong> to remove pieces that are colored <code>'A'</code>.</li>\n\t<li>Alice and Bob <strong>cannot</strong> remove pieces from the edge of the line.</li>\n\t<li>If a player cannot make a move on their turn, that player <strong>loses</strong> and the other player <strong>wins</strong>.</li>\n</ul>\n\n<p>Assuming Alice and Bob play optimally, return <code>true</code><em> if Alice wins, or return </em><code>false</code><em> if Bob wins</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> colors = "AAABABB"\n<strong>Output:</strong> true\n<strong>Explanation:</strong>\nA<u>A</u>ABABB -> AABABB\nAlice moves first.\nShe removes the second 'A' from the left since that is the only 'A' whose neighbors are both 'A'.\n\nNow it's Bob's turn.\nBob cannot make a move on his turn since there are no 'B's whose neighbors are both 'B'.\nThus, Alice wins, so return true.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> colors = "AA"\n<strong>Output:</strong> false\n<strong>Explanation:</strong>\nAlice has her turn first.\nThere are only two 'A's and both are on the edge of the line, so she cannot move on her turn.\nThus, Bob wins, so return false.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> colors = "ABBBBBBBAAA"\n<strong>Output:</strong> false\n<strong>Explanation:</strong>\nABBBBBBBA<u>A</u>A -> ABBBBBBBAA\nAlice moves first.\nHer only option is to remove the second to last 'A' from the right.\n\nABBBB<u>B</u>BBAA -> ABBBBBBAA\nNext is Bob's turn.\nHe has many options for which 'B' piece to remove. He can pick any.\n\nOn Alice's second turn, she has no more pieces that she can remove.\nThus, Bob wins, so return false.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= colors.length <= 10<sup>5</sup></code></li>\n\t<li><code>colors</code> consists of only the letters <code>'A'</code> and <code>'B'</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2038",
"questionId": "2149",
"questionTitle": "Remove Colored Pieces if Both Neighbors are the Same Color",
"questionTitleSlug": "remove-colored-pieces-if-both-neighbors-are-the-same-color",
"similarQuestions": "[{\"title\": \"Longest Subarray With Maximum Bitwise AND\", \"titleSlug\": \"longest-subarray-with-maximum-bitwise-and\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"131.3K\", \"totalSubmission\": \"208.9K\", \"totalAcceptedRaw\": 131336, \"totalSubmissionRaw\": 208866, \"acRate\": \"62.9%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Game Theory",
"slug": "game-theory"
}
]
}
}
} | 2038 | Medium | [
"There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece.\n\nAlice and Bob are playing a game where they take alternating turns removing pieces from the line. In this game, Alice moves first.\n\... | [
{
"hash": -3621927787700886000,
"runtime": "119ms",
"solution": "class Solution(object):\n def winnerOfGame(self, colors):\n \"\"\"\n :type colors: str\n :rtype: bool\n \"\"\"\n current_run_start_index = 0\n current_run_letter = colors[0]\n moves = {\n... | class Solution(object):
def winnerOfGame(self, colors):
"""
:type colors: str
:rtype: bool
"""
| None | None | None | None | None | None | 62.9 | Level 2 | Hi |
subtract-the-product-and-sum-of-digits-of-an-integer | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "Given an integer number <code>n</code>, return the difference between the product of its digits and the sum of its digits.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 234\n<strong>Output:</strong> 15 \n<b>Explanation:</b> \nProduct of digits = 2 * 3 * 4 = 24 \nSum of digits = 2 + 3 + 4 = 9 \nResult = 24 - 9 = 15\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4421\n<strong>Output:</strong> 21\n<b>Explanation: \n</b>Product of digits = 4 * 4 * 2 * 1 = 32 \nSum of digits = 4 + 4 + 2 + 1 = 11 \nResult = 32 - 11 = 21\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n <= 10^5</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1281",
"questionId": "1406",
"questionTitle": "Subtract the Product and Sum of Digits of an Integer",
"questionTitleSlug": "subtract-the-product-and-sum-of-digits-of-an-integer",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"443.9K\", \"totalSubmission\": \"514K\", \"totalAcceptedRaw\": 443901, \"totalSubmissionRaw\": 514000, \"acRate\": \"86.4%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
}
]
}
}
} | 1281 | Easy | [
"Given an integer number n, return the difference between the product of its digits and the sum of its digits.\n \nExample 1:\n\nInput: n = 234\nOutput: 15 \nExplanation: \nProduct of digits = 2 * 3 * 4 = 24 \nSum of digits = 2 + 3 + 4 = 9 \nResult = 24 - 9 = 15\n\n\nExample 2:\n\nInput: n = 4421\nOutput: 21\nExpla... | [
{
"hash": 7605082814291683000,
"runtime": "20ms",
"solution": "class Solution(object):\n def subtractProductAndSum(self, n):\n my_list = [int(i) for i in str(n)]\n mn = 1\n for num in range(len(my_list)):\n mn = mn * my_list[num]\n return mn - sum(my_list)\n ... | class Solution(object):
def subtractProductAndSum(self, n):
"""
:type n: int
:rtype: int
"""
| None | None | None | None | None | None | 86.4 | Level 1 | Hi |
strange-printer-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a strange printer with the following two special requirements:</p>\n\n<ul>\n\t<li>On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.</li>\n\t<li>Once the printer has used a color for the above operation, <strong>the same color cannot be used again</strong>.</li>\n</ul>\n\n<p>You are given a <code>m x n</code> matrix <code>targetGrid</code>, where <code>targetGrid[row][col]</code> is the color in the position <code>(row, col)</code> of the grid.</p>\n\n<p>Return <code>true</code><em> if it is possible to print the matrix </em><code>targetGrid</code><em>,</em><em> otherwise, return </em><code>false</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/23/print1.jpg\" style=\"width: 600px; height: 175px;\" />\n<pre>\n<strong>Input:</strong> targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]\n<strong>Output:</strong> true\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/12/23/print2.jpg\" style=\"width: 600px; height: 367px;\" />\n<pre>\n<strong>Input:</strong> targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]\n<strong>Output:</strong> true\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> targetGrid = [[1,2,1],[2,1,2],[1,2,1]]\n<strong>Output:</strong> false\n<strong>Explanation:</strong> It is impossible to form targetGrid because it is not allowed to print the same color in different turns.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == targetGrid.length</code></li>\n\t<li><code>n == targetGrid[i].length</code></li>\n\t<li><code>1 <= m, n <= 60</code></li>\n\t<li><code>1 <= targetGrid[row][col] <= 60</code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1591",
"questionId": "1696",
"questionTitle": "Strange Printer II",
"questionTitleSlug": "strange-printer-ii",
"similarQuestions": "[{\"title\": \"Strange Printer\", \"titleSlug\": \"strange-printer\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Longest Cycle in a Graph\", \"titleSlug\": \"longest-cycle-in-a-graph\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Sort Array by Moving Items to Empty Space\", \"titleSlug\": \"sort-array-by-moving-items-to-empty-space\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"10.1K\", \"totalSubmission\": \"17.2K\", \"totalAcceptedRaw\": 10142, \"totalSubmissionRaw\": 17222, \"acRate\": \"58.9%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Graph",
"slug": "graph"
},
{
"name": "Topological Sort",
"slug": "topological-sort"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 1591 | Hard | [
"There is a strange printer with the following two special requirements:\n\n\n\tOn each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.\n\tOnce the printer has used a color for the above operation, the same color cannot... | [
{
"hash": 3743377942723555000,
"runtime": "446ms",
"solution": "class Solution(object):\n def isPrintable(self, targetGrid):\n \"\"\"\n :type targetGrid: List[List[int]]\n :rtype: bool\n \"\"\"\n m = len(targetGrid)\n n = len(targetGrid[0])\n grid = [[... | class Solution(object):
def isPrintable(self, targetGrid):
"""
:type targetGrid: List[List[int]]
:rtype: bool
"""
| None | None | None | None | None | None | 58.9 | Level 5 | Hi |
divisible-and-non-divisible-sums-difference | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given positive integers <code>n</code> and <code>m</code>.</p>\n\n<p>Define two integers, <code>num1</code> and <code>num2</code>, as follows:</p>\n\n<ul>\n\t<li><code>num1</code>: The sum of all integers in the range <code>[1, n]</code> that are <strong>not divisible</strong> by <code>m</code>.</li>\n\t<li><code>num2</code>: The sum of all integers in the range <code>[1, n]</code> that are <strong>divisible</strong> by <code>m</code>.</li>\n</ul>\n\n<p>Return <em>the integer</em> <code>num1 - num2</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 10, m = 3\n<strong>Output:</strong> 19\n<strong>Explanation:</strong> In the given example:\n- Integers in the range [1, 10] that are not divisible by 3 are [1,2,4,5,7,8,10], num1 is the sum of those integers = 37.\n- Integers in the range [1, 10] that are divisible by 3 are [3,6,9], num2 is the sum of those integers = 18.\nWe return 37 - 18 = 19 as the answer.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 5, m = 6\n<strong>Output:</strong> 15\n<strong>Explanation:</strong> In the given example:\n- Integers in the range [1, 5] that are not divisible by 6 are [1,2,3,4,5], num1 is the sum of those integers = 15.\n- Integers in the range [1, 5] that are divisible by 6 are [], num2 is the sum of those integers = 0.\nWe return 15 - 0 = 15 as the answer.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 5, m = 1\n<strong>Output:</strong> -15\n<strong>Explanation:</strong> In the given example:\n- Integers in the range [1, 5] that are not divisible by 1 are [], num1 is the sum of those integers = 0.\n- Integers in the range [1, 5] that are divisible by 1 are [1,2,3,4,5], num2 is the sum of those integers = 15.\nWe return 0 - 15 = -15 as the answer.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n, m <= 1000</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2894",
"questionId": "3172",
"questionTitle": "Divisible and Non-divisible Sums Difference",
"questionTitleSlug": "divisible-and-non-divisible-sums-difference",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"44.1K\", \"totalSubmission\": \"50.4K\", \"totalAcceptedRaw\": 44101, \"totalSubmissionRaw\": 50444, \"acRate\": \"87.4%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
}
]
}
}
} | 2894 | Easy | [
"You are given positive integers n and m.\n\nDefine two integers, num1 and num2, as follows:\n\n\n\tnum1: The sum of all integers in the range [1, n] that are not divisible by m.\n\tnum2: The sum of all integers in the range [1, n] that are divisible by m.\n\n\nReturn the integer num1 - num2.\n\n \nExample 1:\n\nIn... | [
{
"hash": -6003585008325815000,
"runtime": "3ms",
"solution": "\"Hari 717822I216\"\nclass Solution(object):\n def differenceOfSums(self, n, m):\n \"\"\"\n :type n: int\n :type m: int\n :rtype: int\n \"\"\"\n c=0\n a=0\n for i in range(1,n+1):\n ... | class Solution(object):
def differenceOfSums(self, n, m):
"""
:type n: int
:type m: int
:rtype: int
"""
| None | None | None | None | None | None | 87.4 | Level 1 | Hi |
minimum-moves-to-move-a-box-to-their-target-location | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.</p>\n\n<p>The game is represented by an <code>m x n</code> grid of characters <code>grid</code> where each element is a wall, floor, or box.</p>\n\n<p>Your task is to move the box <code>'B'</code> to the target position <code>'T'</code> under the following rules:</p>\n\n<ul>\n\t<li>The character <code>'S'</code> represents the player. The player can move up, down, left, right in <code>grid</code> if it is a floor (empty cell).</li>\n\t<li>The character <code>'.'</code> represents the floor which means a free cell to walk.</li>\n\t<li>The character<font face=\"monospace\"> </font><code>'#'</code><font face=\"monospace\"> </font>represents the wall which means an obstacle (impossible to walk there).</li>\n\t<li>There is only one box <code>'B'</code> and one target cell <code>'T'</code> in the <code>grid</code>.</li>\n\t<li>The box can be moved to an adjacent free cell by standing next to the box and then moving in the direction of the box. This is a <strong>push</strong>.</li>\n\t<li>The player cannot walk through the box.</li>\n</ul>\n\n<p>Return <em>the minimum number of <strong>pushes</strong> to move the box to the target</em>. If there is no way to reach the target, return <code>-1</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/11/06/sample_1_1620.png\" style=\"width: 500px; height: 335px;\" />\n<pre>\n<strong>Input:</strong> grid = [["#","#","#","#","#","#"],\n ["#","T","#","#","#","#"],\n ["#",".",".","B",".","#"],\n ["#",".","#","#",".","#"],\n ["#",".",".",".","S","#"],\n ["#","#","#","#","#","#"]]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> We return only the number of times the box is pushed.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> grid = [["#","#","#","#","#","#"],\n ["#","T","#","#","#","#"],\n ["#",".",".","B",".","#"],\n ["#","#","#","#",".","#"],\n ["#",".",".",".","S","#"],\n ["#","#","#","#","#","#"]]\n<strong>Output:</strong> -1\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> grid = [["#","#","#","#","#","#"],\n ["#","T",".",".","#","#"],\n ["#",".","#","B",".","#"],\n ["#",".",".",".",".","#"],\n ["#",".",".",".","S","#"],\n ["#","#","#","#","#","#"]]\n<strong>Output:</strong> 5\n<strong>Explanation:</strong> push the box down, left, left, up and up.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == grid.length</code></li>\n\t<li><code>n == grid[i].length</code></li>\n\t<li><code>1 <= m, n <= 20</code></li>\n\t<li><code>grid</code> contains only characters <code>'.'</code>, <code>'#'</code>, <code>'S'</code>, <code>'T'</code>, or <code>'B'</code>.</li>\n\t<li>There is only one character <code>'S'</code>, <code>'B'</code>, and <code>'T'</code> in the <code>grid</code>.</li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1263",
"questionId": "1389",
"questionTitle": "Minimum Moves to Move a Box to Their Target Location",
"questionTitleSlug": "minimum-moves-to-move-a-box-to-their-target-location",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"27.1K\", \"totalSubmission\": \"55.2K\", \"totalAcceptedRaw\": 27081, \"totalSubmissionRaw\": 55189, \"acRate\": \"49.1%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search"
},
{
"name": "Heap (Priority Queue)",
"slug": "heap-priority-queue"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 1263 | Hard | [
"A storekeeper is a game in which the player pushes boxes around in a warehouse trying to get them to target locations.\n\nThe game is represented by an m x n grid of characters grid where each element is a wall, floor, or box.\n\nYour task is to move the box 'B' to the target position 'T' under the following rules... | [
{
"hash": -563467938746074900,
"runtime": "118ms",
"solution": "class Solution(object):\n def minPushBox(self, grid):\n m = len(grid)\n n = len(grid[0])\n\n for i in range(m):\n for j in range(n):\n if grid[i][j] == 'S':\n person = (i,... | class Solution(object):
def minPushBox(self, grid):
"""
:type grid: List[List[str]]
:rtype: int
"""
| None | None | None | None | None | None | 49.1 | Level 5 | Hi |
lexicographically-smallest-palindrome | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code node=\"[object Object]\">s</code> consisting of <strong>lowercase English letters</strong>, and you are allowed to perform operations on it. In one operation, you can <strong>replace</strong> a character in <code node=\"[object Object]\">s</code> with another lowercase English letter.</p>\n\n<p>Your task is to make <code node=\"[object Object]\">s</code> a <strong>palindrome</strong> with the <strong>minimum</strong> <strong>number</strong> <strong>of operations</strong> possible. If there are <strong>multiple palindromes</strong> that can be <meta charset=\"utf-8\" />made using the <strong>minimum</strong> number of operations, <meta charset=\"utf-8\" />make the <strong>lexicographically smallest</strong> one.</p>\n\n<p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>.</p>\n\n<p>Return <em>the resulting palindrome string.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "egcfe"\n<strong>Output:</strong> "efcfe"\n<strong>Explanation:</strong> The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "abcd"\n<strong>Output:</strong> "abba"\n<strong>Explanation:</strong> The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "seven"\n<strong>Output:</strong> "neven"\n<strong>Explanation:</strong> The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 1000</code></li>\n\t<li><code>s</code> consists of only lowercase English letters<b>.</b></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2697",
"questionId": "2816",
"questionTitle": "Lexicographically Smallest Palindrome",
"questionTitleSlug": "lexicographically-smallest-palindrome",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"36.2K\", \"totalSubmission\": \"45K\", \"totalAcceptedRaw\": 36193, \"totalSubmissionRaw\": 44996, \"acRate\": \"80.4%\"}",
"topicTags": [
{
"name": "Two Pointers",
"slug": "two-pointers"
},
{
"name": "String",
"slug": "string"
}
]
}
}
} | 2697 | Easy | [
"You are given a string s consisting of lowercase English letters, and you are allowed to perform operations on it. In one operation, you can replace a character in s with another lowercase English letter.\n\nYour task is to make s a palindrome with the minimum number of operations possible. If there are multiple p... | [
{
"hash": 7603203841238616000,
"runtime": "128ms",
"solution": "class Solution(object):\n def makeSmallestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n\n a = s[:len(s)/2]\n b = s[len(s)/2:]\n c = \"\"\n if (len(s) % 2 == ... | class Solution(object):
def makeSmallestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 80.4 | Level 1 | Hi |
generate-random-point-in-a-circle | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the radius and the position of the center of a circle, implement the function <code>randPoint</code> which generates a uniform random point inside the circle.</p>\n\n<p>Implement the <code>Solution</code> class:</p>\n\n<ul>\n\t<li><code>Solution(double radius, double x_center, double y_center)</code> initializes the object with the radius of the circle <code>radius</code> and the position of the center <code>(x_center, y_center)</code>.</li>\n\t<li><code>randPoint()</code> returns a random point inside the circle. A point on the circumference of the circle is considered to be in the circle. The answer is returned as an array <code>[x, y]</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["Solution", "randPoint", "randPoint", "randPoint"]\n[[1.0, 0.0, 0.0], [], [], []]\n<strong>Output</strong>\n[null, [-0.02493, -0.38077], [0.82314, 0.38945], [0.36572, 0.17248]]\n\n<strong>Explanation</strong>\nSolution solution = new Solution(1.0, 0.0, 0.0);\nsolution.randPoint(); // return [-0.02493, -0.38077]\nsolution.randPoint(); // return [0.82314, 0.38945]\nsolution.randPoint(); // return [0.36572, 0.17248]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 < radius <= 10<sup>8</sup></code></li>\n\t<li><code>-10<sup>7</sup> <= x_center, y_center <= 10<sup>7</sup></code></li>\n\t<li>At most <code>3 * 10<sup>4</sup></code> calls will be made to <code>randPoint</code>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "478",
"questionId": "915",
"questionTitle": "Generate Random Point in a Circle",
"questionTitleSlug": "generate-random-point-in-a-circle",
"similarQuestions": "[{\"title\": \"Random Point in Non-overlapping Rectangles\", \"titleSlug\": \"random-point-in-non-overlapping-rectangles\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"39.1K\", \"totalSubmission\": \"98.7K\", \"totalAcceptedRaw\": 39086, \"totalSubmissionRaw\": 98671, \"acRate\": \"39.6%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "Geometry",
"slug": "geometry"
},
{
"name": "Rejection Sampling",
"slug": "rejection-sampling"
},
{
"name": "Randomized",
"slug": "randomized"
}
]
}
}
} | 478 | Medium | [
"Given the radius and the position of the center of a circle, implement the function randPoint which generates a uniform random point inside the circle.\n\nImplement the Solution class:\n\n\n\tSolution(double radius, double x_center, double y_center) initializes the object with the radius of the circle radius and t... | [
{
"hash": 8128855696793289000,
"runtime": "101ms",
"solution": "class Solution(object):\n\n def __init__(self, radius, x_center, y_center):\n \"\"\"\n :type radius: float\n :type x_center: float\n :type y_center: float\n \"\"\"\n self.radius = radius\n ... | class Solution(object):
def __init__(self, radius, x_center, y_center):
"""
:type radius: float
:type x_center: float
:type y_center: float
"""
def randPoint(self):
"""
:rtype: List[float]
"""
# Your Solution object will be instantiated and called as such:
# obj = Solution(radius, x_center, y_center)
# param_1 = obj.randPoint()
| None | None | None | None | None | None | 39.6 | Level 4 | Hi |
string-without-aaa-or-bbb | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two integers <code>a</code> and <code>b</code>, return <strong>any</strong> string <code>s</code> such that:</p>\n\n<ul>\n\t<li><code>s</code> has length <code>a + b</code> and contains exactly <code>a</code> <code>'a'</code> letters, and exactly <code>b</code> <code>'b'</code> letters,</li>\n\t<li>The substring <code>'aaa'</code> does not occur in <code>s</code>, and</li>\n\t<li>The substring <code>'bbb'</code> does not occur in <code>s</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 1, b = 2\n<strong>Output:</strong> "abb"\n<strong>Explanation:</strong> "abb", "bab" and "bba" are all correct answers.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> a = 4, b = 1\n<strong>Output:</strong> "aabaa"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= a, b <= 100</code></li>\n\t<li>It is guaranteed such an <code>s</code> exists for the given <code>a</code> and <code>b</code>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "984",
"questionId": "1026",
"questionTitle": "String Without AAA or BBB",
"questionTitleSlug": "string-without-aaa-or-bbb",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"44.7K\", \"totalSubmission\": \"102.4K\", \"totalAcceptedRaw\": 44714, \"totalSubmissionRaw\": 102435, \"acRate\": \"43.7%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
},
{
"name": "Greedy",
"slug": "greedy"
}
]
}
}
} | 984 | Medium | [
"Given two integers a and b, return any string s such that:\n\n\n\ts has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,\n\tThe substring 'aaa' does not occur in s, and\n\tThe substring 'bbb' does not occur in s.\n\n\n \nExample 1:\n\nInput: a = 1, b = 2\nOutput: \"abb\"\nExplanation: \"... | [
{
"hash": -3056553914339003000,
"runtime": "19ms",
"solution": "class Solution(object):\n\n def choose_next(self, cnt_a, cnt_b, a, b):\n if a > b:\n if cnt_a < 2:\n return \"a\", cnt_a+1, 0, a-1,b\n if cnt_b < 2 and b > 0:\n return \"b\", 0, ... | class Solution(object):
def strWithout3a3b(self, a, b):
"""
:type a: int
:type b: int
:rtype: str
"""
| None | None | None | None | None | None | 43.7 | Level 4 | Hi |
find-the-difference-of-two-arrays | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, return <em>a list</em> <code>answer</code> <em>of size</em> <code>2</code> <em>where:</em></p>\n\n<ul>\n\t<li><code>answer[0]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums1</code> <em>which are <strong>not</strong> present in</em> <code>nums2</code><em>.</em></li>\n\t<li><code>answer[1]</code> <em>is a list of all <strong>distinct</strong> integers in</em> <code>nums2</code> <em>which are <strong>not</strong> present in</em> <code>nums1</code>.</li>\n</ul>\n\n<p><strong>Note</strong> that the integers in the lists may be returned in <strong>any</strong> order.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [1,2,3], nums2 = [2,4,6]\n<strong>Output:</strong> [[1,3],[4,6]]\n<strong>Explanation:\n</strong>For nums1, nums1[1] = 2 is present at index 0 of nums2, whereas nums1[0] = 1 and nums1[2] = 3 are not present in nums2. Therefore, answer[0] = [1,3].\nFor nums2, nums2[0] = 2 is present at index 1 of nums1, whereas nums2[1] = 4 and nums2[2] = 6 are not present in nums2. Therefore, answer[1] = [4,6].</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums1 = [1,2,3,3], nums2 = [1,1,2,2]\n<strong>Output:</strong> [[3],[]]\n<strong>Explanation:\n</strong>For nums1, nums1[2] and nums1[3] are not present in nums2. Since nums1[2] == nums1[3], their value is only included once and answer[0] = [3].\nEvery integer in nums2 is present in nums1. Therefore, answer[1] = [].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums1.length, nums2.length <= 1000</code></li>\n\t<li><code>-1000 <= nums1[i], nums2[i] <= 1000</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2215",
"questionId": "1392",
"questionTitle": "Find the Difference of Two Arrays",
"questionTitleSlug": "find-the-difference-of-two-arrays",
"similarQuestions": "[{\"title\": \"Intersection of Two Arrays\", \"titleSlug\": \"intersection-of-two-arrays\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Intersection of Two Arrays II\", \"titleSlug\": \"intersection-of-two-arrays-ii\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Intersection of Multiple Arrays\", \"titleSlug\": \"intersection-of-multiple-arrays\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"234K\", \"totalSubmission\": \"298.6K\", \"totalAcceptedRaw\": 234013, \"totalSubmissionRaw\": 298584, \"acRate\": \"78.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
}
]
}
}
} | 2215 | Easy | [
"Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:\n\n\n\tanswer[0] is a list of all distinct integers in nums1 which are not present in nums2.\n\tanswer[1] is a list of all distinct integers in nums2 which are not present in nums1.\n\n\nNote that the integers in the lists ma... | [
{
"hash": 284787851610934000,
"runtime": "231ms",
"solution": "class Solution(object):\n def findDifference(self, nums1, nums2):\n list1 = []\n list2 = []\n listall = list(set(nums1)) + list(set(nums2))\n counted = {}\n\n for value in listall:\n if value ... | class Solution(object):
def findDifference(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 78.4 | Level 1 | Hi |
distant-barcodes | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>In a warehouse, there is a row of barcodes, where the <code>i<sup>th</sup></code> barcode is <code>barcodes[i]</code>.</p>\n\n<p>Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<pre><strong>Input:</strong> barcodes = [1,1,1,2,2,2]\n<strong>Output:</strong> [2,1,2,1,2,1]\n</pre><p><strong class=\"example\">Example 2:</strong></p>\n<pre><strong>Input:</strong> barcodes = [1,1,1,1,2,2,3,3]\n<strong>Output:</strong> [1,3,1,3,1,2,1,2]\n</pre>\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= barcodes.length <= 10000</code></li>\n\t<li><code>1 <= barcodes[i] <= 10000</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1054",
"questionId": "1140",
"questionTitle": "Distant Barcodes",
"questionTitleSlug": "distant-barcodes",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"40.1K\", \"totalSubmission\": \"86.8K\", \"totalAcceptedRaw\": 40056, \"totalSubmissionRaw\": 86803, \"acRate\": \"46.1%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Heap (Priority Queue)",
"slug": "heap-priority-queue"
},
{
"name": "Counting",
"slug": "counting"
}
]
}
}
} | 1054 | Medium | [
"In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].\n\nRearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.\n\n \nExample 1:\nInput: barcodes = [1,1,1,2,2,2]\nOutput: [2,1,2,1,2,1]\nExample 2:\nInput: barc... | [
{
"hash": -878177668950526300,
"runtime": "441ms",
"solution": "class Solution(object):\n def rearrangeBarcodes(self, bar):\n \"\"\"\n :type barcodes: List[int]\n :rtype: List[int]\n \"\"\"\n temp = Counter(bar)\n a=temp.values()\n b=temp.keys()\n ... | class Solution(object):
def rearrangeBarcodes(self, barcodes):
"""
:type barcodes: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 46.1 | Level 4 | Hi |
find-the-peaks | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p>\n\n<p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given array in <strong>any order</strong>.</em></p>\n\n<p><strong>Notes:</strong></p>\n\n<ul>\n\t<li>A <strong>peak</strong> is defined as an element that is <strong>strictly greater</strong> than its neighboring elements.</li>\n\t<li>The first and last elements of the array are <strong>not</strong> a peak.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> mountain = [2,4,4]\n<strong>Output:</strong> []\n<strong>Explanation:</strong> mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.\nmountain[1] also can not be a peak because it is not strictly greater than mountain[2].\nSo the answer is [].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> mountain = [1,4,3,8,5]\n<strong>Output:</strong> [1,3]\n<strong>Explanation:</strong> mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.\nmountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].\nBut mountain [1] and mountain[3] are strictly greater than their neighboring elements.\nSo the answer is [1,3].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>3 <= mountain.length <= 100</code></li>\n\t<li><code>1 <= mountain[i] <= 100</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2951",
"questionId": "3221",
"questionTitle": "Find the Peaks",
"questionTitleSlug": "find-the-peaks",
"similarQuestions": "[{\"title\": \"Find Peak Element\", \"titleSlug\": \"find-peak-element\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Find a Peak Element II\", \"titleSlug\": \"find-a-peak-element-ii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"20.8K\", \"totalSubmission\": \"27.3K\", \"totalAcceptedRaw\": 20807, \"totalSubmissionRaw\": 27281, \"acRate\": \"76.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Enumeration",
"slug": "enumeration"
}
]
}
}
} | 2951 | Easy | [
"You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.\n\nReturn an array that consists of indices of peaks in the given array in any order.\n\nNotes:\n\n\n\tA peak is defined as an element that is strictly greater than its neighboring elements.\n\tThe first and last el... | [
{
"hash": 4441138587038244400,
"runtime": "23ms",
"solution": "class Solution(object):\n def findPeaks(self, mountain):\n \"\"\"\n :type mountain: List[int]\n :rtype: List[int]\n \"\"\"\n n=len(mountain)\n a=[]\n for i in range(1,n-1):\n if ... | class Solution(object):
def findPeaks(self, mountain):
"""
:type mountain: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 76.3 | Level 1 | Hi |
beautiful-arrangement-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two integers <code>n</code> and <code>k</code>, construct a list <code>answer</code> that contains <code>n</code> different positive integers ranging from <code>1</code> to <code>n</code> and obeys the following requirement:</p>\n\n<ul>\n\t<li>Suppose this list is <code>answer = [a<sub>1</sub>, a<sub>2</sub>, a<sub>3</sub>, ... , a<sub>n</sub>]</code>, then the list <code>[|a<sub>1</sub> - a<sub>2</sub>|, |a<sub>2</sub> - a<sub>3</sub>|, |a<sub>3</sub> - a<sub>4</sub>|, ... , |a<sub>n-1</sub> - a<sub>n</sub>|]</code> has exactly <code>k</code> distinct integers.</li>\n</ul>\n\n<p>Return <em>the list</em> <code>answer</code>. If there multiple valid answers, return <strong>any of them</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3, k = 1\n<strong>Output:</strong> [1,2,3]\nExplanation: The [1,2,3] has three different positive integers ranging from 1 to 3, and the [1,1] has exactly 1 distinct integer: 1\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 3, k = 2\n<strong>Output:</strong> [1,3,2]\nExplanation: The [1,3,2] has three different positive integers ranging from 1 to 3, and the [2,1] has exactly 2 distinct integers: 1 and 2.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= k < n <= 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "667",
"questionId": "667",
"questionTitle": "Beautiful Arrangement II",
"questionTitleSlug": "beautiful-arrangement-ii",
"similarQuestions": "[{\"title\": \"Beautiful Arrangement\", \"titleSlug\": \"beautiful-arrangement\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"52.3K\", \"totalSubmission\": \"87.2K\", \"totalAcceptedRaw\": 52340, \"totalSubmissionRaw\": 87159, \"acRate\": \"60.1%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
}
]
}
}
} | 667 | Medium | [
"Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement:\n\n\n\tSuppose this list is answer = [a₁, a₂, a₃, ... , an], then the list [|a₁ - a₂|, |a₂ - a₃|, |a₃ - a₄|, ... , |an-1 - an|] has exactly k distinct integers.\n... | [
{
"hash": 4057577275964400600,
"runtime": "23ms",
"solution": "class Solution(object):\n def constructArray(self, n, k):\n \"\"\"\n :type n: int\n :type k: int\n :rtype: List[int]\n \"\"\"\n result = [1]\n index = 0\n for i in range(k,0,-1):\n ... | class Solution(object):
def constructArray(self, n, k):
"""
:type n: int
:type k: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 60.1 | Level 2 | Hi |
largest-positive-integer-that-exists-with-its-negative | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code> that <strong>does not contain</strong> any zeros, find <strong>the largest positive</strong> integer <code>k</code> such that <code>-k</code> also exists in the array.</p>\n\n<p>Return <em>the positive integer </em><code>k</code>. If there is no such integer, return <code>-1</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-1,2,-3,3]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> 3 is the only valid k we can find in the array.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-1,10,6,7,-7,1]\n<strong>Output:</strong> 7\n<strong>Explanation:</strong> Both 1 and 7 have their corresponding negative values in the array. 7 has a larger value.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-10,8,6,7,-2,-3]\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> There is no a single valid k, we return -1.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 1000</code></li>\n\t<li><code>-1000 <= nums[i] <= 1000</code></li>\n\t<li><code>nums[i] != 0</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2441",
"questionId": "2524",
"questionTitle": "Largest Positive Integer That Exists With Its Negative",
"questionTitleSlug": "largest-positive-integer-that-exists-with-its-negative",
"similarQuestions": "[{\"title\": \"Two Sum\", \"titleSlug\": \"two-sum\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"52.4K\", \"totalSubmission\": \"77.3K\", \"totalAcceptedRaw\": 52376, \"totalSubmissionRaw\": 77260, \"acRate\": \"67.8%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Two Pointers",
"slug": "two-pointers"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2441 | Easy | [
"Given an integer array nums that does not contain any zeros, find the largest positive integer k such that -k also exists in the array.\n\nReturn the positive integer k. If there is no such integer, return -1.\n\n \nExample 1:\n\nInput: nums = [-1,2,-3,3]\nOutput: 3\nExplanation: 3 is the only valid k we can find ... | [
{
"hash": 1288508819248669000,
"runtime": "187ms",
"solution": "class Solution(object):\n def findMaxK(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n maxi = -1\n for i in nums: \n if (0-i) in nums:\n maxi = ma... | class Solution(object):
def findMaxK(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 67.8 | Level 1 | Hi |
convert-bst-to-greater-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.</p>\n\n<p>As a reminder, a <em>binary search tree</em> is a tree that satisfies these constraints:</p>\n\n<ul>\n\t<li>The left subtree of a node contains only nodes with keys <strong>less than</strong> the node's key.</li>\n\t<li>The right subtree of a node contains only nodes with keys <strong>greater than</strong> the node's key.</li>\n\t<li>Both the left and right subtrees must also be binary search trees.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/05/02/tree.png\" style=\"width: 500px; height: 341px;\" />\n<pre>\n<strong>Input:</strong> root = [4,1,6,0,2,5,7,null,null,null,3,null,null,null,8]\n<strong>Output:</strong> [30,36,21,36,35,26,15,null,null,null,33,null,null,null,8]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> root = [0,null,1]\n<strong>Output:</strong> [1,null,1]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the tree is in the range <code>[0, 10<sup>4</sup>]</code>.</li>\n\t<li><code>-10<sup>4</sup> <= Node.val <= 10<sup>4</sup></code></li>\n\t<li>All the values in the tree are <strong>unique</strong>.</li>\n\t<li><code>root</code> is guaranteed to be a valid binary search tree.</li>\n</ul>\n\n<p> </p>\n<p><strong>Note:</strong> This question is the same as 1038: <a href=\"https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/\" target=\"_blank\">https://leetcode.com/problems/binary-search-tree-to-greater-sum-tree/</a></p>\n",
"difficulty": "Medium",
"questionFrontendId": "538",
"questionId": "538",
"questionTitle": "Convert BST to Greater Tree",
"questionTitleSlug": "convert-bst-to-greater-tree",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"283K\", \"totalSubmission\": \"412.5K\", \"totalAcceptedRaw\": 282979, \"totalSubmissionRaw\": 412545, \"acRate\": \"68.6%\"}",
"topicTags": [
{
"name": "Tree",
"slug": "tree"
},
{
"name": "Depth-First Search",
"slug": "depth-first-search"
},
{
"name": "Binary Search Tree",
"slug": "binary-search-tree"
},
{
"name": "Binary Tree",
"slug": "binary-tree"
}
]
}
}
} | 538 | Medium | [
"Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus the sum of all keys greater than the original key in BST.\n\nAs a reminder, a binary search tree is a tree that satisfies these constraints:\n\n\n\tThe left subtree... | [
{
"hash": 3220725035395737600,
"runtime": "85ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def co... | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def convertBST(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
| None | None | None | None | None | None | 68.6 | Level 2 | Hi |
queens-that-can-attack-the-king | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>On a <strong>0-indexed</strong> <code>8 x 8</code> chessboard, there can be multiple black queens ad one white king.</p>\n\n<p>You are given a 2D integer array <code>queens</code> where <code>queens[i] = [xQueen<sub>i</sub>, yQueen<sub>i</sub>]</code> represents the position of the <code>i<sup>th</sup></code> black queen on the chessboard. You are also given an integer array <code>king</code> of length <code>2</code> where <code>king = [xKing, yKing]</code> represents the position of the white king.</p>\n\n<p>Return <em>the coordinates of the black queens that can directly attack the king</em>. You may return the answer in <strong>any order</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/21/chess1.jpg\" style=\"width: 400px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> queens = [[0,1],[1,0],[4,0],[0,4],[3,3],[2,4]], king = [0,0]\n<strong>Output:</strong> [[0,1],[1,0],[3,3]]\n<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/21/chess2.jpg\" style=\"width: 400px; height: 400px;\" />\n<pre>\n<strong>Input:</strong> queens = [[0,0],[1,1],[2,2],[3,4],[3,5],[4,4],[4,5]], king = [3,3]\n<strong>Output:</strong> [[2,2],[3,4],[4,4]]\n<strong>Explanation:</strong> The diagram above shows the three queens that can directly attack the king and the three queens that cannot attack the king (i.e., marked with red dashes).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= queens.length < 64</code></li>\n\t<li><code>queens[i].length == king.length == 2</code></li>\n\t<li><code>0 <= xQueen<sub>i</sub>, yQueen<sub>i</sub>, xKing, yKing < 8</code></li>\n\t<li>All the given positions are <strong>unique</strong>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1222",
"questionId": "1342",
"questionTitle": "Queens That Can Attack the King",
"questionTitleSlug": "queens-that-can-attack-the-king",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"40.4K\", \"totalSubmission\": \"56.3K\", \"totalAcceptedRaw\": 40395, \"totalSubmissionRaw\": 56293, \"acRate\": \"71.8%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Matrix",
"slug": "matrix"
},
{
"name": "Simulation",
"slug": "simulation"
}
]
}
}
} | 1222 | Medium | [
"On a 0-indexed 8 x 8 chessboard, there can be multiple black queens ad one white king.\n\nYou are given a 2D integer array queens where queens[i] = [xQueeni, yQueeni] represents the position of the ith black queen on the chessboard. You are also given an integer array king of length 2 where king = [xKing, yKing] r... | [
{
"hash": -6929733986349925000,
"runtime": "19ms",
"solution": "class Solution(object):\n def queensAttacktheKing(self, queens, king):\n \"\"\"\n :type queens: List[List[int]]\n :type king: List[int]\n :rtype: List[List[int]]\n \"\"\"\n\n size = 8\n di... | class Solution(object):
def queensAttacktheKing(self, queens, king):
"""
:type queens: List[List[int]]
:type king: List[int]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 71.8 | Level 2 | Hi |
vertical-order-traversal-of-a-binary-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a binary tree, calculate the <strong>vertical order traversal</strong> of the binary tree.</p>\n\n<p>For each node at position <code>(row, col)</code>, its left and right children will be at positions <code>(row + 1, col - 1)</code> and <code>(row + 1, col + 1)</code> respectively. The root of the tree is at <code>(0, 0)</code>.</p>\n\n<p>The <strong>vertical order traversal</strong> of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.</p>\n\n<p>Return <em>the <strong>vertical order traversal</strong> of the binary tree</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/29/vtree1.jpg\" style=\"width: 431px; height: 304px;\" />\n<pre>\n<strong>Input:</strong> root = [3,9,20,null,null,15,7]\n<strong>Output:</strong> [[9],[3,15],[20],[7]]\n<strong>Explanation:</strong>\nColumn -1: Only node 9 is in this column.\nColumn 0: Nodes 3 and 15 are in this column in that order from top to bottom.\nColumn 1: Only node 20 is in this column.\nColumn 2: Only node 7 is in this column.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/29/vtree2.jpg\" style=\"width: 512px; height: 304px;\" />\n<pre>\n<strong>Input:</strong> root = [1,2,3,4,5,6,7]\n<strong>Output:</strong> [[4],[2],[1,5,6],[3],[7]]\n<strong>Explanation:</strong>\nColumn -2: Only node 4 is in this column.\nColumn -1: Only node 2 is in this column.\nColumn 0: Nodes 1, 5, and 6 are in this column.\n 1 is at the top, so it comes first.\n 5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.\nColumn 1: Only node 3 is in this column.\nColumn 2: Only node 7 is in this column.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/01/29/vtree3.jpg\" style=\"width: 512px; height: 304px;\" />\n<pre>\n<strong>Input:</strong> root = [1,2,3,4,6,5,7]\n<strong>Output:</strong> [[4],[2],[1,5,6],[3],[7]]\n<strong>Explanation:</strong>\nThis case is the exact same as example 2, but with nodes 5 and 6 swapped.\nNote that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the tree is in the range <code>[1, 1000]</code>.</li>\n\t<li><code>0 <= Node.val <= 1000</code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "987",
"questionId": "1029",
"questionTitle": "Vertical Order Traversal of a Binary Tree",
"questionTitleSlug": "vertical-order-traversal-of-a-binary-tree",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"380K\", \"totalSubmission\": \"816.1K\", \"totalAcceptedRaw\": 380047, \"totalSubmissionRaw\": 816148, \"acRate\": \"46.6%\"}",
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Tree",
"slug": "tree"
},
{
"name": "Depth-First Search",
"slug": "depth-first-search"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search"
},
{
"name": "Binary Tree",
"slug": "binary-tree"
}
]
}
}
} | 987 | Hard | [
"Given the root of a binary tree, calculate the vertical order traversal of the binary tree.\n\nFor each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).\n\nThe vertical order traversal of a binar... | [
{
"hash": -420265368071322000,
"runtime": "20ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def ve... | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def verticalTraversal(self, root):
"""
:type root: TreeNode
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 46.6 | Level 5 | Hi |
online-election | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two integer arrays <code>persons</code> and <code>times</code>. In an election, the <code>i<sup>th</sup></code> vote was cast for <code>persons[i]</code> at time <code>times[i]</code>.</p>\n\n<p>For each query at a time <code>t</code>, find the person that was leading the election at time <code>t</code>. Votes cast at time <code>t</code> will count towards our query. In the case of a tie, the most recent vote (among tied candidates) wins.</p>\n\n<p>Implement the <code>TopVotedCandidate</code> class:</p>\n\n<ul>\n\t<li><code>TopVotedCandidate(int[] persons, int[] times)</code> Initializes the object with the <code>persons</code> and <code>times</code> arrays.</li>\n\t<li><code>int q(int t)</code> Returns the number of the person that was leading the election at time <code>t</code> according to the mentioned rules.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["TopVotedCandidate", "q", "q", "q", "q", "q", "q"]\n[[[0, 1, 1, 0, 0, 1, 0], [0, 5, 10, 15, 20, 25, 30]], [3], [12], [25], [15], [24], [8]]\n<strong>Output</strong>\n[null, 0, 1, 1, 0, 0, 1]\n\n<strong>Explanation</strong>\nTopVotedCandidate topVotedCandidate = new TopVotedCandidate([0, 1, 1, 0, 0, 1, 0], [0, 5, 10, 15, 20, 25, 30]);\ntopVotedCandidate.q(3); // return 0, At time 3, the votes are [0], and 0 is leading.\ntopVotedCandidate.q(12); // return 1, At time 12, the votes are [0,1,1], and 1 is leading.\ntopVotedCandidate.q(25); // return 1, At time 25, the votes are [0,1,1,0,0,1], and 1 is leading (as ties go to the most recent vote.)\ntopVotedCandidate.q(15); // return 0\ntopVotedCandidate.q(24); // return 0\ntopVotedCandidate.q(8); // return 1\n\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= persons.length <= 5000</code></li>\n\t<li><code>times.length == persons.length</code></li>\n\t<li><code>0 <= persons[i] < persons.length</code></li>\n\t<li><code>0 <= times[i] <= 10<sup>9</sup></code></li>\n\t<li><code>times</code> is sorted in a strictly increasing order.</li>\n\t<li><code>times[0] <= t <= 10<sup>9</sup></code></li>\n\t<li>At most <code>10<sup>4</sup></code> calls will be made to <code>q</code>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "911",
"questionId": "947",
"questionTitle": "Online Election",
"questionTitleSlug": "online-election",
"similarQuestions": "[{\"title\": \"Rank Teams by Votes\", \"titleSlug\": \"rank-teams-by-votes\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"53.8K\", \"totalSubmission\": \"103.6K\", \"totalAcceptedRaw\": 53772, \"totalSubmissionRaw\": 103622, \"acRate\": \"51.9%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Binary Search",
"slug": "binary-search"
},
{
"name": "Design",
"slug": "design"
}
]
}
}
} | 911 | Medium | [
"You are given two integer arrays persons and times. In an election, the ith vote was cast for persons[i] at time times[i].\n\nFor each query at a time t, find the person that was leading the election at time t. Votes cast at time t will count towards our query. In the case of a tie, the most recent vote (among tie... | [
{
"hash": -3224153180749166600,
"runtime": "649ms",
"solution": "class TopVotedCandidate(object):\n\n def __init__(self, persons, times):\n \"\"\"\n :type persons: List[int]\n :type times: List[int]\n \"\"\"\n\n self.queue = []\n\n cnt_dict = collections.defa... | class TopVotedCandidate(object):
def __init__(self, persons, times):
"""
:type persons: List[int]
:type times: List[int]
"""
def q(self, t):
"""
:type t: int
:rtype: int
"""
# Your TopVotedCandidate object will be instantiated and called as such:
# obj = TopVotedCandidate(persons, times)
# param_1 = obj.q(t)
| None | None | None | None | None | None | 51.9 | Level 3 | Hi |
reorganize-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code>, rearrange the characters of <code>s</code> so that any two adjacent characters are not the same.</p>\n\n<p>Return <em>any possible rearrangement of</em> <code>s</code> <em>or return</em> <code>""</code> <em>if not possible</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<pre><strong>Input:</strong> s = \"aab\"\n<strong>Output:</strong> \"aba\"\n</pre><p><strong class=\"example\">Example 2:</strong></p>\n<pre><strong>Input:</strong> s = \"aaab\"\n<strong>Output:</strong> \"\"\n</pre>\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 500</code></li>\n\t<li><code>s</code> consists of lowercase English letters.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "767",
"questionId": "778",
"questionTitle": "Reorganize String",
"questionTitleSlug": "reorganize-string",
"similarQuestions": "[{\"title\": \"Rearrange String k Distance Apart\", \"titleSlug\": \"rearrange-string-k-distance-apart\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Task Scheduler\", \"titleSlug\": \"task-scheduler\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Longest Happy String\", \"titleSlug\": \"longest-happy-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"352.3K\", \"totalSubmission\": \"648.2K\", \"totalAcceptedRaw\": 352293, \"totalSubmissionRaw\": 648227, \"acRate\": \"54.3%\"}",
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Heap (Priority Queue)",
"slug": "heap-priority-queue"
},
{
"name": "Counting",
"slug": "counting"
}
]
}
}
} | 767 | Medium | [
"Given a string s, rearrange the characters of s so that any two adjacent characters are not the same.\n\nReturn any possible rearrangement of s or return \"\" if not possible.\n\n \nExample 1:\nInput: s = \"aab\"\nOutput: \"aba\"\nExample 2:\nInput: s = \"aaab\"\nOutput: \"\"\n\n \nConstraints:\n\n\n\t1 <= s.lengt... | [
{
"hash": -3352505553615025700,
"runtime": "26ms",
"solution": "class Solution(object):\n def reorganizeString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n import heapq\n heap = []\n\n for element in set(s):\n count = s.count(e... | class Solution(object):
def reorganizeString(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 54.3 | Level 3 | Hi |
maximum-number-of-balloons | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>text</code>, you want to use the characters of <code>text</code> to form as many instances of the word <strong>"balloon"</strong> as possible.</p>\n\n<p>You can use each character in <code>text</code> <strong>at most once</strong>. Return the maximum number of instances that can be formed.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/09/05/1536_ex1_upd.JPG\" style=\"width: 132px; height: 35px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> text = "nlaebolko"\n<strong>Output:</strong> 1\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/09/05/1536_ex2_upd.JPG\" style=\"width: 267px; height: 35px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> text = "loonbalxballpoon"\n<strong>Output:</strong> 2\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> text = "leetcode"\n<strong>Output:</strong> 0\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= text.length <= 10<sup>4</sup></code></li>\n\t<li><code>text</code> consists of lower case English letters only.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1189",
"questionId": "1297",
"questionTitle": "Maximum Number of Balloons",
"questionTitleSlug": "maximum-number-of-balloons",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"177.2K\", \"totalSubmission\": \"294.6K\", \"totalAcceptedRaw\": 177152, \"totalSubmissionRaw\": 294644, \"acRate\": \"60.1%\"}",
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Counting",
"slug": "counting"
}
]
}
}
} | 1189 | Easy | [
"Given a string text, you want to use the characters of text to form as many instances of the word \"balloon\" as possible.\n\nYou can use each character in text at most once. Return the maximum number of instances that can be formed.\n\n \nExample 1:\n\n\n\nInput: text = \"nlaebolko\"\nOutput: 1\n\n\nExample 2:\n\... | [
{
"hash": -1720271340735556600,
"runtime": "42ms",
"solution": "from collections import defaultdict\n\nclass Solution:\n def maxNumberOfBalloons(self, text: str) -> int:\n \n balloons_count_perm = defaultdict(int)\n \n for c in 'balloon':\n balloons_count_perm[c]+=1... | class Solution(object):
def maxNumberOfBalloons(self, text):
"""
:type text: str
:rtype: int
"""
| None | None | None | None | None | None | 60.1 | Level 1 | Hi |
maximum-length-of-subarray-with-positive-product | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>nums</code>, find the maximum length of a subarray where the product of all its elements is positive.</p>\n\n<p>A subarray of an array is a consecutive sequence of zero or more values taken out of that array.</p>\n\n<p>Return <em>the maximum length of a subarray with positive product</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,-2,-3,4]\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The array nums already has a positive product of 24.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,-2,-3,-4]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The longest subarray with positive product is [1,-2,-3] which has a product of 6.\nNotice that we cannot include 0 in the subarray since that'll make the product 0 which is not positive.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [-1,-2,-3,0,1]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> The longest subarray with positive product is [-1,-2] or [-2,-3].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1567",
"questionId": "1690",
"questionTitle": "Maximum Length of Subarray With Positive Product",
"questionTitleSlug": "maximum-length-of-subarray-with-positive-product",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"89.5K\", \"totalSubmission\": \"202.8K\", \"totalAcceptedRaw\": 89493, \"totalSubmissionRaw\": 202843, \"acRate\": \"44.1%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Greedy",
"slug": "greedy"
}
]
}
}
} | 1567 | Medium | [
"Given an array of integers nums, find the maximum length of a subarray where the product of all its elements is positive.\n\nA subarray of an array is a consecutive sequence of zero or more values taken out of that array.\n\nReturn the maximum length of a subarray with positive product.\n\n \nExample 1:\n\nInput: ... | [
{
"hash": 519021023843520200,
"runtime": "459ms",
"solution": "class Solution:\n def getMaxLen(self, nums):\n #positiveNum紀錄當前正數的最長長度\n #neg 紀錄如果有負數的最長長度\n positiveNum, negativeNum, max_len = 0, 0, 0\n\n for item in nums:\n if item == 0:\n positiv... | class Solution(object):
def getMaxLen(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 44.1 | Level 4 | Hi |
partition-array-into-disjoint-intervals | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code>, partition it into two (contiguous) subarrays <code>left</code> and <code>right</code> so that:</p>\n\n<ul>\n\t<li>Every element in <code>left</code> is less than or equal to every element in <code>right</code>.</li>\n\t<li><code>left</code> and <code>right</code> are non-empty.</li>\n\t<li><code>left</code> has the smallest possible size.</li>\n</ul>\n\n<p>Return <em>the length of </em><code>left</code><em> after such a partitioning</em>.</p>\n\n<p>Test cases are generated such that partitioning exists.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [5,0,3,8,6]\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> left = [5,0,3], right = [8,6]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,1,1,0,6,12]\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> left = [1,1,1,0], right = [6,12]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>\n\t<li>There is at least one valid answer for the given input.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "915",
"questionId": "951",
"questionTitle": "Partition Array into Disjoint Intervals",
"questionTitleSlug": "partition-array-into-disjoint-intervals",
"similarQuestions": "[{\"title\": \"Sum of Beauty in the Array\", \"titleSlug\": \"sum-of-beauty-in-the-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Optimal Partition of String\", \"titleSlug\": \"optimal-partition-of-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Minimum Index of a Valid Split\", \"titleSlug\": \"minimum-index-of-a-valid-split\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"79.6K\", \"totalSubmission\": \"163.4K\", \"totalAcceptedRaw\": 79604, \"totalSubmissionRaw\": 163362, \"acRate\": \"48.7%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
}
]
}
}
} | 915 | Medium | [
"Given an integer array nums, partition it into two (contiguous) subarrays left and right so that:\n\n\n\tEvery element in left is less than or equal to every element in right.\n\tleft and right are non-empty.\n\tleft has the smallest possible size.\n\n\nReturn the length of left after such a partitioning.\n\nTest ... | [
{
"hash": 4281993328260209000,
"runtime": "767ms",
"solution": "class Solution(object):\n def partitionDisjoint(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n n = len(nums)\n\n leftMax = nums[0]\n i = 0\n while i <= n-1:\... | class Solution(object):
def partitionDisjoint(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 48.7 | Level 3 | Hi |
maximum-beauty-of-an-array-after-applying-operation | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> and a <strong>non-negative</strong> integer <code>k</code>.</p>\n\n<p>In one operation, you can do the following:</p>\n\n<ul>\n\t<li>Choose an index <code>i</code> that <strong>hasn't been chosen before</strong> from the range <code>[0, nums.length - 1]</code>.</li>\n\t<li>Replace <code>nums[i]</code> with any integer from the range <code>[nums[i] - k, nums[i] + k]</code>.</li>\n</ul>\n\n<p>The <strong>beauty</strong> of the array is the length of the longest subsequence consisting of equal elements.</p>\n\n<p>Return <em>the <strong>maximum</strong> possible beauty of the array </em><code>nums</code><em> after applying the operation any number of times.</em></p>\n\n<p><strong>Note</strong> that you can apply the operation to each index <strong>only once</strong>.</p>\n\n<p>A <strong>subsequence</strong> of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the order of the remaining elements.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [4,6,1,2], k = 2\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> In this example, we apply the following operations:\n- Choose index 1, replace it with 4 (from range [4,8]), nums = [4,4,1,2].\n- Choose index 3, replace it with 4 (from range [0,4]), nums = [4,4,1,4].\nAfter the applied operations, the beauty of the array nums is 3 (subsequence consisting of indices 0, 1, and 3).\nIt can be proven that 3 is the maximum possible length we can achieve.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,1,1,1], k = 10\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> In this example we don't have to apply any operations.\nThe beauty of the array nums is 4 (whole array).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= nums[i], k <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2779",
"questionId": "2891",
"questionTitle": "Maximum Beauty of an Array After Applying Operation",
"questionTitleSlug": "maximum-beauty-of-an-array-after-applying-operation",
"similarQuestions": "[{\"title\": \"Maximum Size Subarray Sum Equals k\", \"titleSlug\": \"maximum-size-subarray-sum-equals-k\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Partition Array Such That Maximum Difference Is K\", \"titleSlug\": \"partition-array-such-that-maximum-difference-is-k\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"22.5K\", \"totalSubmission\": \"61K\", \"totalAcceptedRaw\": 22476, \"totalSubmissionRaw\": 60984, \"acRate\": \"36.9%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Binary Search",
"slug": "binary-search"
},
{
"name": "Sliding Window",
"slug": "sliding-window"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2779 | Medium | [
"You are given a 0-indexed array nums and a non-negative integer k.\n\nIn one operation, you can do the following:\n\n\n\tChoose an index i that hasn't been chosen before from the range [0, nums.length - 1].\n\tReplace nums[i] with any integer from the range [nums[i] - k, nums[i] + k].\n\n\nThe beauty of the array ... | [
{
"hash": 951538819116589300,
"runtime": "1170ms",
"solution": "class Solution(object):\n def maximumBeauty(self, nums, k):\n '''\n 2 3 4 5 6\n 4 5 6 7 8\n -1 0 1 2 3 \n 0 1 2 3 4\n 1 -1\n 1 -1\n 1 -1\n ... | class Solution(object):
def maximumBeauty(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 36.9 | Level 4 | Hi |
reformat-date | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <code>date</code> string in the form <code>Day Month Year</code>, where:</p>\n\n<ul>\n\t<li><code>Day</code> is in the set <code>{"1st", "2nd", "3rd", "4th", ..., "30th", "31st"}</code>.</li>\n\t<li><code>Month</code> is in the set <code>{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}</code>.</li>\n\t<li><code>Year</code> is in the range <code>[1900, 2100]</code>.</li>\n</ul>\n\n<p>Convert the date string to the format <code>YYYY-MM-DD</code>, where:</p>\n\n<ul>\n\t<li><code>YYYY</code> denotes the 4 digit year.</li>\n\t<li><code>MM</code> denotes the 2 digit month.</li>\n\t<li><code>DD</code> denotes the 2 digit day.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> date = "20th Oct 2052"\n<strong>Output:</strong> "2052-10-20"\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> date = "6th Jun 1933"\n<strong>Output:</strong> "1933-06-06"\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> date = "26th May 1960"\n<strong>Output:</strong> "1960-05-26"\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The given dates are guaranteed to be valid, so no error handling is necessary.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1507",
"questionId": "1283",
"questionTitle": "Reformat Date",
"questionTitleSlug": "reformat-date",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"64K\", \"totalSubmission\": \"99.1K\", \"totalAcceptedRaw\": 64000, \"totalSubmissionRaw\": 99149, \"acRate\": \"64.5%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
}
]
}
}
} | 1507 | Easy | [
"Given a date string in the form Day Month Year, where:\n\n\n\tDay is in the set {\"1st\", \"2nd\", \"3rd\", \"4th\", ..., \"30th\", \"31st\"}.\n\tMonth is in the set {\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"}.\n\tYear is in the range [1900, 2100].\n... | [
{
"hash": 7843043716277049000,
"runtime": "13ms",
"solution": "class Solution(object):\n def reformatDate(self, date):\n \"\"\"\n :type date: str\n :rtype: str\n \"\"\"\n dlist = date.split(' ')\n monthdict = {\"Jan\":'01', \"Feb\":'02', \"Mar\":'03', \"Apr\"... | class Solution(object):
def reformatDate(self, date):
"""
:type date: str
:rtype: str
"""
| None | None | None | None | None | None | 64.5 | Level 1 | Hi |
airplane-seat-assignment-probability | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p><code>n</code> passengers board an airplane with exactly <code>n</code> seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:</p>\n\n<ul>\n\t<li>Take their own seat if it is still available, and</li>\n\t<li>Pick other seats randomly when they find their seat occupied</li>\n</ul>\n\n<p>Return <em>the probability that the </em><code>n<sup>th</sup></code><em> person gets his own seat</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 1\n<strong>Output:</strong> 1.00000\n<strong>Explanation: </strong>The first person can only get the first seat.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 2\n<strong>Output:</strong> 0.50000\n<strong>Explanation: </strong>The second person has a probability of 0.5 to get the second seat (when first person gets the first seat).\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= n <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1227",
"questionId": "1362",
"questionTitle": "Airplane Seat Assignment Probability",
"questionTitleSlug": "airplane-seat-assignment-probability",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"37.8K\", \"totalSubmission\": \"57.3K\", \"totalAcceptedRaw\": 37794, \"totalSubmissionRaw\": 57287, \"acRate\": \"66.0%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Brainteaser",
"slug": "brainteaser"
},
{
"name": "Probability and Statistics",
"slug": "probability-and-statistics"
}
]
}
}
} | 1227 | Medium | [
"n passengers board an airplane with exactly n seats. The first passenger has lost the ticket and picks a seat randomly. But after that, the rest of the passengers will:\n\n\n\tTake their own seat if it is still available, and\n\tPick other seats randomly when they find their seat occupied\n\n\nReturn the probabili... | [
{
"hash": 4834802732781317000,
"runtime": "12ms",
"solution": "class Solution(object):\n def nthPersonGetsNthSeat(self, n):\n \"\"\"\n :type n: int\n :rtype: float\n \"\"\"\n return 1 if n == 1 else .5\n "
},
{
"hash": -5053200184426102000,
"runti... | class Solution(object):
def nthPersonGetsNthSeat(self, n):
"""
:type n: int
:rtype: float
"""
| None | None | None | None | None | None | 66 | Level 2 | Hi |
finding-pairs-with-a-certain-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two integer arrays <code>nums1</code> and <code>nums2</code>. You are tasked to implement a data structure that supports queries of two types:</p>\n\n<ol>\n\t<li><strong>Add</strong> a positive integer to an element of a given index in the array <code>nums2</code>.</li>\n\t<li><strong>Count</strong> the number of pairs <code>(i, j)</code> such that <code>nums1[i] + nums2[j]</code> equals a given value (<code>0 <= i < nums1.length</code> and <code>0 <= j < nums2.length</code>).</li>\n</ol>\n\n<p>Implement the <code>FindSumPairs</code> class:</p>\n\n<ul>\n\t<li><code>FindSumPairs(int[] nums1, int[] nums2)</code> Initializes the <code>FindSumPairs</code> object with two integer arrays <code>nums1</code> and <code>nums2</code>.</li>\n\t<li><code>void add(int index, int val)</code> Adds <code>val</code> to <code>nums2[index]</code>, i.e., apply <code>nums2[index] += val</code>.</li>\n\t<li><code>int count(int tot)</code> Returns the number of pairs <code>(i, j)</code> such that <code>nums1[i] + nums2[j] == tot</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["FindSumPairs", "count", "add", "count", "count", "add", "add", "count"]\n[[[1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]], [7], [3, 2], [8], [4], [0, 1], [1, 1], [7]]\n<strong>Output</strong>\n[null, 8, null, 2, 1, null, null, 11]\n\n<strong>Explanation</strong>\nFindSumPairs findSumPairs = new FindSumPairs([1, 1, 2, 2, 2, 3], [1, 4, 5, 2, 5, 4]);\nfindSumPairs.count(7); // return 8; pairs (2,2), (3,2), (4,2), (2,4), (3,4), (4,4) make 2 + 5 and pairs (5,1), (5,5) make 3 + 4\nfindSumPairs.add(3, 2); // now nums2 = [1,4,5,<strong><u>4</u></strong><code>,5,4</code>]\nfindSumPairs.count(8); // return 2; pairs (5,2), (5,4) make 3 + 5\nfindSumPairs.count(4); // return 1; pair (5,0) makes 3 + 1\nfindSumPairs.add(0, 1); // now nums2 = [<strong><u><code>2</code></u></strong>,4,5,4<code>,5,4</code>]\nfindSumPairs.add(1, 1); // now nums2 = [<code>2</code>,<strong><u>5</u></strong>,5,4<code>,5,4</code>]\nfindSumPairs.count(7); // return 11; pairs (2,1), (2,2), (2,4), (3,1), (3,2), (3,4), (4,1), (4,2), (4,4) make 2 + 5 and pairs (5,3), (5,5) make 3 + 4\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums1.length <= 1000</code></li>\n\t<li><code>1 <= nums2.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums1[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= nums2[i] <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= index < nums2.length</code></li>\n\t<li><code>1 <= val <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= tot <= 10<sup>9</sup></code></li>\n\t<li>At most <code>1000</code> calls are made to <code>add</code> and <code>count</code> <strong>each</strong>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1865",
"questionId": "1995",
"questionTitle": "Finding Pairs With a Certain Sum",
"questionTitleSlug": "finding-pairs-with-a-certain-sum",
"similarQuestions": "[{\"title\": \"Count Number of Pairs With Absolute Difference K\", \"titleSlug\": \"count-number-of-pairs-with-absolute-difference-k\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Number of Distinct Averages\", \"titleSlug\": \"number-of-distinct-averages\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Count the Number of Fair Pairs\", \"titleSlug\": \"count-the-number-of-fair-pairs\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"23K\", \"totalSubmission\": \"45.5K\", \"totalAcceptedRaw\": 23009, \"totalSubmissionRaw\": 45540, \"acRate\": \"50.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Design",
"slug": "design"
}
]
}
}
} | 1865 | Medium | [
"You are given two integer arrays nums1 and nums2. You are tasked to implement a data structure that supports queries of two types:\n\n\n\tAdd a positive integer to an element of a given index in the array nums2.\n\tCount the number of pairs (i, j) such that nums1[i] + nums2[j] equals a given value (0 <= i < nums1.... | [
{
"hash": 3279004291743721000,
"runtime": "1022ms",
"solution": "class FindSumPairs(object):\n\n def __init__(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n \"\"\"\n self.nums1 = nums1\n self.nums2 = nums2\n self.tbl ... | class FindSumPairs(object):
def __init__(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
"""
def add(self, index, val):
"""
:type index: int
:type val: int
:rtype: None
"""
def count(self, tot):
"""
:type tot: int
:rtype: int
"""
# Your FindSumPairs object will be instantiated and called as such:
# obj = FindSumPairs(nums1, nums2)
# obj.add(index,val)
# param_2 = obj.count(tot)
| None | None | None | None | None | None | 50.5 | Level 3 | Hi |
stone-game-iii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Alice and Bob continue their games with piles of stones. There are several stones <strong>arranged in a row</strong>, and each stone has an associated value which is an integer given in the array <code>stoneValue</code>.</p>\n\n<p>Alice and Bob take turns, with Alice starting first. On each player's turn, that player can take <code>1</code>, <code>2</code>, or <code>3</code> stones from the <strong>first</strong> remaining stones in the row.</p>\n\n<p>The score of each player is the sum of the values of the stones taken. The score of each player is <code>0</code> initially.</p>\n\n<p>The objective of the game is to end with the highest score, and the winner is the player with the highest score and there could be a tie. The game continues until all the stones have been taken.</p>\n\n<p>Assume Alice and Bob <strong>play optimally</strong>.</p>\n\n<p>Return <code>"Alice"</code><em> if Alice will win, </em><code>"Bob"</code><em> if Bob will win, or </em><code>"Tie"</code><em> if they will end the game with the same score</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> stoneValue = [1,2,3,7]\n<strong>Output:</strong> "Bob"\n<strong>Explanation:</strong> Alice will always lose. Her best move will be to take three piles and the score become 6. Now the score of Bob is 7 and Bob wins.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> stoneValue = [1,2,3,-9]\n<strong>Output:</strong> "Alice"\n<strong>Explanation:</strong> Alice must choose all the three piles at the first move to win and leave Bob with negative score.\nIf Alice chooses one pile her score will be 1 and the next move Bob's score becomes 5. In the next move, Alice will take the pile with value = -9 and lose.\nIf Alice chooses two piles her score will be 3 and the next move Bob's score becomes 3. In the next move, Alice will take the pile with value = -9 and also lose.\nRemember that both play optimally so here Alice will choose the scenario that makes her win.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> stoneValue = [1,2,3,6]\n<strong>Output:</strong> "Tie"\n<strong>Explanation:</strong> Alice cannot win this game. She can end the game in a draw if she decided to choose all the first three piles, otherwise she will lose.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= stoneValue.length <= 5 * 10<sup>4</sup></code></li>\n\t<li><code>-1000 <= stoneValue[i] <= 1000</code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1406",
"questionId": "1522",
"questionTitle": "Stone Game III",
"questionTitleSlug": "stone-game-iii",
"similarQuestions": "[{\"title\": \"Stone Game V\", \"titleSlug\": \"stone-game-v\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Stone Game VI\", \"titleSlug\": \"stone-game-vi\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Stone Game VII\", \"titleSlug\": \"stone-game-vii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Stone Game VIII\", \"titleSlug\": \"stone-game-viii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Stone Game IX\", \"titleSlug\": \"stone-game-ix\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"84.4K\", \"totalSubmission\": \"130.8K\", \"totalAcceptedRaw\": 84383, \"totalSubmissionRaw\": 130775, \"acRate\": \"64.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Game Theory",
"slug": "game-theory"
}
]
}
}
} | 1406 | Hard | [
"Alice and Bob continue their games with piles of stones. There are several stones arranged in a row, and each stone has an associated value which is an integer given in the array stoneValue.\n\nAlice and Bob take turns, with Alice starting first. On each player's turn, that player can take 1, 2, or 3 stones from t... | [
{
"hash": 2664063244555668000,
"runtime": "1691ms",
"solution": "class Solution(object):\n def stoneGameIII(self, stoneValue):\n \"\"\"\n :type stoneValue: List[int]\n :rtype: str\n \"\"\"\n # the total score the player starting at index i will get \n # from ... | class Solution(object):
def stoneGameIII(self, stoneValue):
"""
:type stoneValue: List[int]
:rtype: str
"""
| None | None | None | None | None | None | 64.5 | Level 5 | Hi |
permutation-in-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two strings <code>s1</code> and <code>s2</code>, return <code>true</code><em> if </em><code>s2</code><em> contains a permutation of </em><code>s1</code><em>, or </em><code>false</code><em> otherwise</em>.</p>\n\n<p>In other words, return <code>true</code> if one of <code>s1</code>'s permutations is the substring of <code>s2</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s1 = "ab", s2 = "eidbaooo"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> s2 contains one permutation of s1 ("ba").\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s1 = "ab", s2 = "eidboaoo"\n<strong>Output:</strong> false\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s1.length, s2.length <= 10<sup>4</sup></code></li>\n\t<li><code>s1</code> and <code>s2</code> consist of lowercase English letters.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "567",
"questionId": "567",
"questionTitle": "Permutation in String",
"questionTitleSlug": "permutation-in-string",
"similarQuestions": "[{\"title\": \"Minimum Window Substring\", \"titleSlug\": \"minimum-window-substring\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Find All Anagrams in a String\", \"titleSlug\": \"find-all-anagrams-in-a-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"763.9K\", \"totalSubmission\": \"1.7M\", \"totalAcceptedRaw\": 763909, \"totalSubmissionRaw\": 1727790, \"acRate\": \"44.2%\"}",
"topicTags": [
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Two Pointers",
"slug": "two-pointers"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Sliding Window",
"slug": "sliding-window"
}
]
}
}
} | 567 | Medium | [
"Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.\n\nIn other words, return true if one of s1's permutations is the substring of s2.\n\n \nExample 1:\n\nInput: s1 = \"ab\", s2 = \"eidbaooo\"\nOutput: true\nExplanation: s2 contains one permutation of s1 (\"ba\").\n\n\n... | [
{
"hash": -306371018665239300,
"runtime": "3498ms",
"solution": "class Solution(object):\n def checkInclusion(self, s1, s2):\n \n if len(s1)>len(s2):\n return False\n\n hashi = dict()\n for i in range(len(s1)): #populates hashmap\n if s1[i] not in ha... | class Solution(object):
def checkInclusion(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
| None | None | None | None | None | None | 44.2 | Level 4 | Hi |
count-number-of-rectangles-containing-each-point | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a 2D integer array <code>rectangles</code> where <code>rectangles[i] = [l<sub>i</sub>, h<sub>i</sub>]</code> indicates that <code>i<sup>th</sup></code> rectangle has a length of <code>l<sub>i</sub></code> and a height of <code>h<sub>i</sub></code>. You are also given a 2D integer array <code>points</code> where <code>points[j] = [x<sub>j</sub>, y<sub>j</sub>]</code> is a point with coordinates <code>(x<sub>j</sub>, y<sub>j</sub>)</code>.</p>\n\n<p>The <code>i<sup>th</sup></code> rectangle has its <strong>bottom-left corner</strong> point at the coordinates <code>(0, 0)</code> and its <strong>top-right corner</strong> point at <code>(l<sub>i</sub>, h<sub>i</sub>)</code>.</p>\n\n<p>Return<em> an integer array </em><code>count</code><em> of length </em><code>points.length</code><em> where </em><code>count[j]</code><em> is the number of rectangles that <strong>contain</strong> the </em><code>j<sup>th</sup></code><em> point.</em></p>\n\n<p>The <code>i<sup>th</sup></code> rectangle <strong>contains</strong> the <code>j<sup>th</sup></code> point if <code>0 <= x<sub>j</sub> <= l<sub>i</sub></code> and <code>0 <= y<sub>j</sub> <= h<sub>i</sub></code>. Note that points that lie on the <strong>edges</strong> of a rectangle are also considered to be contained by that rectangle.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/03/02/example1.png\" style=\"width: 300px; height: 509px;\" />\n<pre>\n<strong>Input:</strong> rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]\n<strong>Output:</strong> [2,1]\n<strong>Explanation:</strong> \nThe first rectangle contains no points.\nThe second rectangle contains only the point (2, 1).\nThe third rectangle contains the points (2, 1) and (1, 4).\nThe number of rectangles that contain the point (2, 1) is 2.\nThe number of rectangles that contain the point (1, 4) is 1.\nTherefore, we return [2, 1].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/03/02/example2.png\" style=\"width: 300px; height: 312px;\" />\n<pre>\n<strong>Input:</strong> rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]\n<strong>Output:</strong> [1,3]\n<strong>Explanation:\n</strong>The first rectangle contains only the point (1, 1).\nThe second rectangle contains only the point (1, 1).\nThe third rectangle contains the points (1, 3) and (1, 1).\nThe number of rectangles that contain the point (1, 3) is 1.\nThe number of rectangles that contain the point (1, 1) is 3.\nTherefore, we return [1, 3].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= rectangles.length, points.length <= 5 * 10<sup>4</sup></code></li>\n\t<li><code>rectangles[i].length == points[j].length == 2</code></li>\n\t<li><code>1 <= l<sub>i</sub>, x<sub>j</sub> <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= h<sub>i</sub>, y<sub>j</sub> <= 100</code></li>\n\t<li>All the <code>rectangles</code> are <strong>unique</strong>.</li>\n\t<li>All the <code>points</code> are <strong>unique</strong>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2250",
"questionId": "2333",
"questionTitle": "Count Number of Rectangles Containing Each Point",
"questionTitleSlug": "count-number-of-rectangles-containing-each-point",
"similarQuestions": "[{\"title\": \"Queries on Number of Points Inside a Circle\", \"titleSlug\": \"queries-on-number-of-points-inside-a-circle\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"14.1K\", \"totalSubmission\": \"41K\", \"totalAcceptedRaw\": 14083, \"totalSubmissionRaw\": 41047, \"acRate\": \"34.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Binary Search",
"slug": "binary-search"
},
{
"name": "Binary Indexed Tree",
"slug": "binary-indexed-tree"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2250 | Medium | [
"You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is a point with coordinates (xj, yj).\n\nThe ith rectangle has its bottom-left corner point at the c... | [
{
"hash": -848439591077243100,
"runtime": "4033ms",
"solution": "class Solution(object):\n def countRectangles(self, rectangles, points):\n \"\"\"\n :type rectangles: List[List[int]]\n :type points: List[List[int]]\n :rtype: List[int]\n \"\"\"\n heights = def... | class Solution(object):
def countRectangles(self, rectangles, points):
"""
:type rectangles: List[List[int]]
:type points: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 34.3 | Level 4 | Hi |
find-xor-sum-of-all-pairs-bitwise-and | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The <strong>XOR sum</strong> of a list is the bitwise <code>XOR</code> of all its elements. If the list only contains one element, then its <strong>XOR sum</strong> will be equal to this element.</p>\n\n<ul>\n\t<li>For example, the <strong>XOR sum</strong> of <code>[1,2,3,4]</code> is equal to <code>1 XOR 2 XOR 3 XOR 4 = 4</code>, and the <strong>XOR sum</strong> of <code>[3]</code> is equal to <code>3</code>.</li>\n</ul>\n\n<p>You are given two <strong>0-indexed</strong> arrays <code>arr1</code> and <code>arr2</code> that consist only of non-negative integers.</p>\n\n<p>Consider the list containing the result of <code>arr1[i] AND arr2[j]</code> (bitwise <code>AND</code>) for every <code>(i, j)</code> pair where <code>0 <= i < arr1.length</code> and <code>0 <= j < arr2.length</code>.</p>\n\n<p>Return <em>the <strong>XOR sum</strong> of the aforementioned list</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr1 = [1,2,3], arr2 = [6,5]\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].\nThe XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr1 = [12], arr2 = [4]\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> The list = [12 AND 4] = [4]. The XOR sum = 4.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr1.length, arr2.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= arr1[i], arr2[j] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1835",
"questionId": "1963",
"questionTitle": "Find XOR Sum of All Pairs Bitwise AND",
"questionTitleSlug": "find-xor-sum-of-all-pairs-bitwise-and",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"17.4K\", \"totalSubmission\": \"28.6K\", \"totalAcceptedRaw\": 17433, \"totalSubmissionRaw\": 28568, \"acRate\": \"61.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Bit Manipulation",
"slug": "bit-manipulation"
}
]
}
}
} | 1835 | Hard | [
"The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.\n\n\n\tFor example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.\n\n\nYou are given two 0-indexed arrays arr1 a... | [
{
"hash": -5741064275464751000,
"runtime": "707ms",
"solution": "class Solution(object):\n def getXORSum(self, arr1, arr2):\n \"\"\"\n :type arr1: List[int]\n :type arr2: List[int]\n :rtype: int\n \"\"\"\n n = len(arr1)\n m = len(arr2)\n xa = 0\... | class Solution(object):
def getXORSum(self, arr1, arr2):
"""
:type arr1: List[int]
:type arr2: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 61 | Level 5 | Hi |
maximum-binary-tree-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A <strong>maximum tree</strong> is a tree where every node has a value greater than any other value in its subtree.</p>\n\n<p>You are given the <code>root</code> of a maximum binary tree and an integer <code>val</code>.</p>\n\n<p>Just as in the <a href=\"https://leetcode.com/problems/maximum-binary-tree/\" target=\"_blank\">previous problem</a>, the given tree was constructed from a list <code>a</code> (<code>root = Construct(a)</code>) recursively with the following <code>Construct(a)</code> routine:</p>\n\n<ul>\n\t<li>If <code>a</code> is empty, return <code>null</code>.</li>\n\t<li>Otherwise, let <code>a[i]</code> be the largest element of <code>a</code>. Create a <code>root</code> node with the value <code>a[i]</code>.</li>\n\t<li>The left child of <code>root</code> will be <code>Construct([a[0], a[1], ..., a[i - 1]])</code>.</li>\n\t<li>The right child of <code>root</code> will be <code>Construct([a[i + 1], a[i + 2], ..., a[a.length - 1]])</code>.</li>\n\t<li>Return <code>root</code>.</li>\n</ul>\n\n<p>Note that we were not given <code>a</code> directly, only a root node <code>root = Construct(a)</code>.</p>\n\n<p>Suppose <code>b</code> is a copy of <code>a</code> with the value <code>val</code> appended to it. It is guaranteed that <code>b</code> has unique values.</p>\n\n<p>Return <code>Construct(b)</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/08/09/maxtree1.JPG\" style=\"width: 376px; height: 235px;\" />\n<pre>\n<strong>Input:</strong> root = [4,1,3,null,null,2], val = 5\n<strong>Output:</strong> [5,4,null,1,3,null,null,2]\n<strong>Explanation:</strong> a = [1,4,2,3], b = [1,4,2,3,5]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/08/09/maxtree21.JPG\" style=\"width: 358px; height: 156px;\" />\n<pre>\n<strong>Input:</strong> root = [5,2,4,null,1], val = 3\n<strong>Output:</strong> [5,2,4,null,1,null,3]\n<strong>Explanation:</strong> a = [2,1,5,4], b = [2,1,5,4,3]\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2021/08/09/maxtree3.JPG\" style=\"width: 404px; height: 180px;\" />\n<pre>\n<strong>Input:</strong> root = [5,2,3,null,1], val = 4\n<strong>Output:</strong> [5,2,4,null,1,3]\n<strong>Explanation:</strong> a = [2,1,5,3], b = [2,1,5,3,4]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the tree is in the range <code>[1, 100]</code>.</li>\n\t<li><code>1 <= Node.val <= 100</code></li>\n\t<li>All the values of the tree are <strong>unique</strong>.</li>\n\t<li><code>1 <= val <= 100</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "998",
"questionId": "1040",
"questionTitle": "Maximum Binary Tree II",
"questionTitleSlug": "maximum-binary-tree-ii",
"similarQuestions": "[{\"title\": \"Maximum Binary Tree\", \"titleSlug\": \"maximum-binary-tree\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"33.9K\", \"totalSubmission\": \"49.6K\", \"totalAcceptedRaw\": 33880, \"totalSubmissionRaw\": 49572, \"acRate\": \"68.3%\"}",
"topicTags": [
{
"name": "Tree",
"slug": "tree"
},
{
"name": "Binary Tree",
"slug": "binary-tree"
}
]
}
}
} | 998 | Medium | [
"A maximum tree is a tree where every node has a value greater than any other value in its subtree.\n\nYou are given the root of a maximum binary tree and an integer val.\n\nJust as in the previous problem, the given tree was constructed from a list a (root = Construct(a)) recursively with the following Construct(a... | [
{
"hash": -7788608775068547000,
"runtime": "14ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def i... | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def insertIntoMaxTree(self, root, val):
"""
:type root: TreeNode
:type val: int
:rtype: TreeNode
"""
| None | None | None | None | None | None | 68.3 | Level 2 | Hi |
longest-harmonious-subsequence | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We define a harmonious array as an array where the difference between its maximum value and its minimum value is <b>exactly</b> <code>1</code>.</p>\r\n\r\n<p>Given an integer array <code>nums</code>, return <em>the length of its longest harmonious subsequence among all its possible subsequences</em>.</p>\r\n\r\n<p>A <strong>subsequence</strong> of array is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.</p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [1,3,2,2,5,2,3,7]\r\n<strong>Output:</strong> 5\r\n<strong>Explanation:</strong> The longest harmonious subsequence is [3,2,2,2,3].\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [1,2,3,4]\r\n<strong>Output:</strong> 2\r\n</pre>\r\n\r\n<p><strong class=\"example\">Example 3:</strong></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> nums = [1,1,1,1]\r\n<strong>Output:</strong> 0\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>\r\n\t<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>\r\n</ul>",
"difficulty": "Easy",
"questionFrontendId": "594",
"questionId": "594",
"questionTitle": "Longest Harmonious Subsequence",
"questionTitleSlug": "longest-harmonious-subsequence",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"145.6K\", \"totalSubmission\": \"269K\", \"totalAcceptedRaw\": 145638, \"totalSubmissionRaw\": 269007, \"acRate\": \"54.1%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 594 | Easy | [
"We define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.\n\nGiven an integer array nums, return the length of its longest harmonious subsequence among all its possible subsequences.\n\nA subsequence of array is a sequence that can be derived from t... | [
{
"hash": 81585909227058480,
"runtime": "269ms",
"solution": "class Solution(object):\n def findLHS(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n freq = Counter(nums)\n max_length = 0\n \n for key in freq:\n i... | class Solution(object):
def findLHS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 54.1 | Level 1 | Hi |
number-of-ways-to-buy-pens-and-pencils | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer <code>total</code> indicating the amount of money you have. You are also given two integers <code>cost1</code> and <code>cost2</code> indicating the price of a pen and pencil respectively. You can spend <strong>part or all</strong> of your money to buy multiple quantities (or none) of each kind of writing utensil.</p>\n\n<p>Return <em>the <strong>number of distinct ways</strong> you can buy some number of pens and pencils.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> total = 20, cost1 = 10, cost2 = 5\n<strong>Output:</strong> 9\n<strong>Explanation:</strong> The price of a pen is 10 and the price of a pencil is 5.\n- If you buy 0 pens, you can buy 0, 1, 2, 3, or 4 pencils.\n- If you buy 1 pen, you can buy 0, 1, or 2 pencils.\n- If you buy 2 pens, you cannot buy any pencils.\nThe total number of ways to buy pens and pencils is 5 + 3 + 1 = 9.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> total = 5, cost1 = 10, cost2 = 10\n<strong>Output:</strong> 1\n<strong>Explanation:</strong> The price of both pens and pencils are 10, which cost more than total, so you cannot buy any writing utensils. Therefore, there is only 1 way: buy 0 pens and 0 pencils.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= total, cost1, cost2 <= 10<sup>6</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2240",
"questionId": "2351",
"questionTitle": "Number of Ways to Buy Pens and Pencils",
"questionTitleSlug": "number-of-ways-to-buy-pens-and-pencils",
"similarQuestions": "[{\"title\": \"Find Three Consecutive Integers That Sum to a Given Number\", \"titleSlug\": \"find-three-consecutive-integers-that-sum-to-a-given-number\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Count Integers With Even Digit Sum\", \"titleSlug\": \"count-integers-with-even-digit-sum\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"24.3K\", \"totalSubmission\": \"42.7K\", \"totalAcceptedRaw\": 24335, \"totalSubmissionRaw\": 42691, \"acRate\": \"57.0%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "Enumeration",
"slug": "enumeration"
}
]
}
}
} | 2240 | Medium | [
"You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to buy multiple quantities (or none) of each kind of writing utensil.\n\nReturn the number of distin... | [
{
"hash": -7086506714479435000,
"runtime": "399ms",
"solution": "class Solution(object):\n def waysToBuyPensPencils(self, total, cost1, cost2):\n \"\"\"\n :type total: int\n :type cost1: int\n :type cost2: int\n :rtype: int\n \"\"\"\n num_ways = 0\n ... | class Solution(object):
def waysToBuyPensPencils(self, total, cost1, cost2):
"""
:type total: int
:type cost1: int
:type cost2: int
:rtype: int
"""
| None | None | None | None | None | None | 57 | Level 3 | Hi |
vowels-of-all-substrings | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>word</code>, return <em>the <strong>sum of the number of vowels</strong> (</em><code>'a'</code>, <code>'e'</code><em>,</em> <code>'i'</code><em>,</em> <code>'o'</code><em>, and</em> <code>'u'</code><em>)</em> <em>in every substring of </em><code>word</code>.</p>\n\n<p>A <strong>substring</strong> is a contiguous (non-empty) sequence of characters within a string.</p>\n\n<p><strong>Note:</strong> Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> word = "aba"\n<strong>Output:</strong> 6\n<strong>Explanation:</strong> \nAll possible substrings are: "a", "ab", "aba", "b", "ba", and "a".\n- "b" has 0 vowels in it\n- "a", "ab", "ba", and "a" have 1 vowel each\n- "aba" has 2 vowels in it\nHence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6. \n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> word = "abc"\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> \nAll possible substrings are: "a", "ab", "abc", "b", "bc", and "c".\n- "a", "ab", and "abc" have 1 vowel each\n- "b", "bc", and "c" have 0 vowels each\nHence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> word = "ltcd"\n<strong>Output:</strong> 0\n<strong>Explanation:</strong> There are no vowels in any substring of "ltcd".\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= word.length <= 10<sup>5</sup></code></li>\n\t<li><code>word</code> consists of lowercase English letters.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2063",
"questionId": "2187",
"questionTitle": "Vowels of All Substrings",
"questionTitleSlug": "vowels-of-all-substrings",
"similarQuestions": "[{\"title\": \"Number of Substrings Containing All Three Characters\", \"titleSlug\": \"number-of-substrings-containing-all-three-characters\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Total Appeal of A String\", \"titleSlug\": \"total-appeal-of-a-string\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"25.6K\", \"totalSubmission\": \"47.1K\", \"totalAcceptedRaw\": 25632, \"totalSubmissionRaw\": 47126, \"acRate\": \"54.4%\"}",
"topicTags": [
{
"name": "Math",
"slug": "math"
},
{
"name": "String",
"slug": "string"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Combinatorics",
"slug": "combinatorics"
}
]
}
}
} | 2063 | Medium | [
"Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.\n\nA substring is a contiguous (non-empty) sequence of characters within a string.\n\nNote: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during... | [
{
"hash": 2413501381660631000,
"runtime": "81ms",
"solution": "class Solution(object):\n def countVowels(self, word):\n count=0\n n=len(word)\n\n for i in range(n):\n if word[i] in \"aeiou\":\n count+=(n-i)*(i+1)\n return count\n\n\n [1,2,1... | class Solution(object):
def countVowels(self, word):
"""
:type word: str
:rtype: int
"""
| None | None | None | None | None | None | 54.4 | Level 3 | Hi |
circular-sentence | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A <strong>sentence</strong> is a list of words that are separated by a<strong> single</strong> space with no leading or trailing spaces.</p>\n\n<ul>\n\t<li>For example, <code>"Hello World"</code>, <code>"HELLO"</code>, <code>"hello world hello world"</code> are all sentences.</li>\n</ul>\n\n<p>Words consist of <strong>only</strong> uppercase and lowercase English letters. Uppercase and lowercase English letters are considered different.</p>\n\n<p>A sentence is <strong>circular </strong>if:</p>\n\n<ul>\n\t<li>The last character of a word is equal to the first character of the next word.</li>\n\t<li>The last character of the last word is equal to the first character of the first word.</li>\n</ul>\n\n<p>For example, <code>"leetcode exercises sound delightful"</code>, <code>"eetcode"</code>, <code>"leetcode eats soul" </code>are all circular sentences. However, <code>"Leetcode is cool"</code>, <code>"happy Leetcode"</code>, <code>"Leetcode"</code> and <code>"I like Leetcode"</code> are <strong>not</strong> circular sentences.</p>\n\n<p>Given a string <code>sentence</code>, return <code>true</code><em> if it is circular</em>. Otherwise, return <code>false</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> sentence = "leetcode exercises sound delightful"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> The words in sentence are ["leetcode", "exercises", "sound", "delightful"].\n- leetcod<u>e</u>'s last character is equal to <u>e</u>xercises's first character.\n- exercise<u>s</u>'s last character is equal to <u>s</u>ound's first character.\n- soun<u>d</u>'s last character is equal to <u>d</u>elightful's first character.\n- delightfu<u>l</u>'s last character is equal to <u>l</u>eetcode's first character.\nThe sentence is circular.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> sentence = "eetcode"\n<strong>Output:</strong> true\n<strong>Explanation:</strong> The words in sentence are ["eetcode"].\n- eetcod<u>e</u>'s last character is equal to <u>e</u>etcode's first character.\nThe sentence is circular.</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> sentence = "Leetcode is cool"\n<strong>Output:</strong> false\n<strong>Explanation:</strong> The words in sentence are ["Leetcode", "is", "cool"].\n- Leetcod<u>e</u>'s last character is <strong>not</strong> equal to <u>i</u>s's first character.\nThe sentence is <strong>not</strong> circular.</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= sentence.length <= 500</code></li>\n\t<li><code>sentence</code> consist of only lowercase and uppercase English letters and spaces.</li>\n\t<li>The words in <code>sentence</code> are separated by a single space.</li>\n\t<li>There are no leading or trailing spaces.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "2490",
"questionId": "2580",
"questionTitle": "Circular Sentence",
"questionTitleSlug": "circular-sentence",
"similarQuestions": "[{\"title\": \"Defuse the Bomb\", \"titleSlug\": \"defuse-the-bomb\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"34.4K\", \"totalSubmission\": \"54.6K\", \"totalAcceptedRaw\": 34419, \"totalSubmissionRaw\": 54634, \"acRate\": \"63.0%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
}
]
}
}
} | 2490 | Easy | [
"A sentence is a list of words that are separated by a single space with no leading or trailing spaces.\n\n\n\tFor example, \"Hello World\", \"HELLO\", \"hello world hello world\" are all sentences.\n\n\nWords consist of only uppercase and lowercase English letters. Uppercase and lowercase English letters are consi... | [
{
"hash": 4034672755015197700,
"runtime": "14ms",
"solution": "class Solution(object):\n def isCircularSentence(self, sentence):\n \"\"\"\n :type sentence: str\n :rtype: bool\n \"\"\"\n sen = sentence.split(' ')\n\n for i in range(len(sen)-1):\n if... | class Solution(object):
def isCircularSentence(self, sentence):
"""
:type sentence: str
:rtype: bool
"""
| None | None | None | None | None | None | 63 | Level 1 | Hi |
minimum-number-of-k-consecutive-bit-flips | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a binary array <code>nums</code> and an integer <code>k</code>.</p>\n\n<p>A <strong>k-bit flip</strong> is choosing a <strong>subarray</strong> of length <code>k</code> from <code>nums</code> and simultaneously changing every <code>0</code> in the subarray to <code>1</code>, and every <code>1</code> in the subarray to <code>0</code>.</p>\n\n<p>Return <em>the minimum number of <strong>k-bit flips</strong> required so that there is no </em><code>0</code><em> in the array</em>. If it is not possible, return <code>-1</code>.</p>\n\n<p>A <strong>subarray</strong> is a <strong>contiguous</strong> part of an array.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,1,0], k = 1\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Flip nums[0], then flip nums[2].\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,1,0], k = 2\n<strong>Output:</strong> -1\n<strong>Explanation:</strong> No matter how we flip subarrays of size 2, we cannot make the array become [1,1,1].\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [0,0,0,1,0,1,1,0], k = 3\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> \nFlip nums[0],nums[1],nums[2]: nums becomes [1,1,1,1,0,1,1,0]\nFlip nums[4],nums[5],nums[6]: nums becomes [1,1,1,1,1,0,0,0]\nFlip nums[5],nums[6],nums[7]: nums becomes [1,1,1,1,1,1,1,1]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= k <= nums.length</code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "995",
"questionId": "1037",
"questionTitle": "Minimum Number of K Consecutive Bit Flips",
"questionTitleSlug": "minimum-number-of-k-consecutive-bit-flips",
"similarQuestions": "[{\"title\": \"Bulb Switcher\", \"titleSlug\": \"bulb-switcher\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Minimum Time to Remove All Cars Containing Illegal Goods\", \"titleSlug\": \"minimum-time-to-remove-all-cars-containing-illegal-goods\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Number of Distinct Binary Strings After Applying Operations\", \"titleSlug\": \"number-of-distinct-binary-strings-after-applying-operations\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"33K\", \"totalSubmission\": \"64.2K\", \"totalAcceptedRaw\": 33016, \"totalSubmissionRaw\": 64181, \"acRate\": \"51.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Bit Manipulation",
"slug": "bit-manipulation"
},
{
"name": "Queue",
"slug": "queue"
},
{
"name": "Sliding Window",
"slug": "sliding-window"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
}
]
}
}
} | 995 | Hard | [
"You are given a binary array nums and an integer k.\n\nA k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.\n\nReturn the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible... | [
{
"hash": -4439214508687801000,
"runtime": "926ms",
"solution": "class Solution(object):\n def minKBitFlips(self, nums, k) :\n flips = 0\n q = deque()\n \n for i,num in enumerate(nums):\n # Number of Items in queue = how many times current index has been flipped... | class Solution(object):
def minKBitFlips(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 51.4 | Level 5 | Hi |
least-number-of-unique-integers-after-k-removals | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>arr</code> and an integer <code>k</code>. Find the <em>least number of unique integers</em> after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p>\r\n\r\n<ol>\r\n</ol>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<pre>\r\n<strong>Input: </strong>arr = [5,5,4], k = 1\r\n<strong>Output: </strong>1\r\n<strong>Explanation</strong>: Remove the single 4, only 5 is left.\r\n</pre>\r\n<strong class=\"example\">Example 2:</strong>\r\n\r\n<pre>\r\n<strong>Input: </strong>arr = [4,3,1,1,3,3,2], k = 3\r\n<strong>Output: </strong>2\r\n<strong>Explanation</strong>: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= arr.length <= 10^5</code></li>\r\n\t<li><code>1 <= arr[i] <= 10^9</code></li>\r\n\t<li><code>0 <= k <= arr.length</code></li>\r\n</ul>",
"difficulty": "Medium",
"questionFrontendId": "1481",
"questionId": "1604",
"questionTitle": "Least Number of Unique Integers after K Removals",
"questionTitleSlug": "least-number-of-unique-integers-after-k-removals",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"108.1K\", \"totalSubmission\": \"192.9K\", \"totalAcceptedRaw\": 108059, \"totalSubmissionRaw\": 192914, \"acRate\": \"56.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Counting",
"slug": "counting"
}
]
}
}
} | 1481 | Medium | [
"Given an array of integers arr and an integer k. Find the least number of unique integers after removing exactly k elements.\n\n\n\n\n \nExample 1:\n\nInput: arr = [5,5,4], k = 1\nOutput: 1\nExplanation: Remove the single 4, only 5 is left.\n\nExample 2:\n\nInput: arr = [4,3,1,1,3,3,2], k = 3\nOutput: 2\nExplanati... | [
{
"hash": 7677825765872450000,
"runtime": "366ms",
"solution": "class Solution(object):\n def findLeastNumOfUniqueInts(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n count = collections.Counter(arr)\n ans = len(c... | class Solution(object):
def findLeastNumOfUniqueInts(self, arr, k):
"""
:type arr: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 56 | Level 3 | Hi |
maximum-number-of-vowels-in-a-substring-of-given-length | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code> and an integer <code>k</code>, return <em>the maximum number of vowel letters in any substring of </em><code>s</code><em> with length </em><code>k</code>.</p>\n\n<p><strong>Vowel letters</strong> in English are <code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, and <code>'u'</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "abciiidef", k = 3\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The substring "iii" contains 3 vowel letters.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "aeiou", k = 2\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> Any substring of length 2 contains 2 vowels.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "leetcode", k = 3\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> "lee", "eet" and "ode" contain 2 vowels.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 10<sup>5</sup></code></li>\n\t<li><code>s</code> consists of lowercase English letters.</li>\n\t<li><code>1 <= k <= s.length</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1456",
"questionId": "1567",
"questionTitle": "Maximum Number of Vowels in a Substring of Given Length",
"questionTitleSlug": "maximum-number-of-vowels-in-a-substring-of-given-length",
"similarQuestions": "[{\"title\": \"Maximum White Tiles Covered by a Carpet\", \"titleSlug\": \"maximum-white-tiles-covered-by-a-carpet\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Minimum Recolors to Get K Consecutive Black Blocks\", \"titleSlug\": \"minimum-recolors-to-get-k-consecutive-black-blocks\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Length of the Longest Alphabetical Continuous Substring\", \"titleSlug\": \"length-of-the-longest-alphabetical-continuous-substring\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"225.7K\", \"totalSubmission\": \"389.3K\", \"totalAcceptedRaw\": 225722, \"totalSubmissionRaw\": 389286, \"acRate\": \"58.0%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
},
{
"name": "Sliding Window",
"slug": "sliding-window"
}
]
}
}
} | 1456 | Medium | [
"Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k.\n\nVowel letters in English are 'a', 'e', 'i', 'o', and 'u'.\n\n \nExample 1:\n\nInput: s = \"abciiidef\", k = 3\nOutput: 3\nExplanation: The substring \"iii\" contains 3 vowel letters.\n\n\nExample 2... | [
{
"hash": -2784764751584251000,
"runtime": "240ms",
"solution": "class Solution(object):\n def maxVowels(self, s, k):\n\n count = 0\n for i in range(0, k):\n if s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u':\n print(\"yes\")\n ... | class Solution(object):
def maxVowels(self, s, k):
"""
:type s: str
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 58 | Level 3 | Hi |
distance-between-bus-stops | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A bus has <code>n</code> stops numbered from <code>0</code> to <code>n - 1</code> that form a circle. We know the distance between all pairs of neighboring stops where <code>distance[i]</code> is the distance between the stops number <code>i</code> and <code>(i + 1) % n</code>.</p>\r\n\r\n<p>The bus goes along both directions i.e. clockwise and counterclockwise.</p>\r\n\r\n<p>Return the shortest distance between the given <code>start</code> and <code>destination</code> stops.</p>\r\n\r\n<p> </p>\r\n<p><strong class=\"example\">Example 1:</strong></p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1.jpg\" style=\"width: 388px; height: 240px;\" /></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 1\r\n<strong>Output:</strong> 1\r\n<strong>Explanation:</strong> Distance between 0 and 1 is 1 or 9, minimum is 1.</pre>\r\n\r\n<p> </p>\r\n\r\n<p><strong class=\"example\">Example 2:</strong></p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1-1.jpg\" style=\"width: 388px; height: 240px;\" /></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 2\r\n<strong>Output:</strong> 3\r\n<strong>Explanation:</strong> Distance between 0 and 2 is 3 or 7, minimum is 3.\r\n</pre>\r\n\r\n<p> </p>\r\n\r\n<p><strong class=\"example\">Example 3:</strong></p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1-2.jpg\" style=\"width: 388px; height: 240px;\" /></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> distance = [1,2,3,4], start = 0, destination = 3\r\n<strong>Output:</strong> 4\r\n<strong>Explanation:</strong> Distance between 0 and 3 is 6 or 4, minimum is 4.\r\n</pre>\r\n\r\n<p> </p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>1 <= n <= 10^4</code></li>\r\n\t<li><code>distance.length == n</code></li>\r\n\t<li><code>0 <= start, destination < n</code></li>\r\n\t<li><code>0 <= distance[i] <= 10^4</code></li>\r\n</ul>",
"difficulty": "Easy",
"questionFrontendId": "1184",
"questionId": "1287",
"questionTitle": "Distance Between Bus Stops",
"questionTitleSlug": "distance-between-bus-stops",
"similarQuestions": "[{\"title\": \"Minimum Costs Using the Train Line\", \"titleSlug\": \"minimum-costs-using-the-train-line\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"55.8K\", \"totalSubmission\": \"103.6K\", \"totalAcceptedRaw\": 55807, \"totalSubmissionRaw\": 103649, \"acRate\": \"53.8%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
}
]
}
}
} | 1184 | Easy | [
"A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.\n\nThe bus goes along both directions i.e. clockwise and counterclockwise.\n\nReturn the shortest distance between... | [
{
"hash": 4889192309464223000,
"runtime": "52ms",
"solution": "class Solution:\n def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:\n clockwiseDistance = 0\n counterclockwiseDistance = 0\n if start == destination:\n return 0\n ... | class Solution(object):
def distanceBetweenBusStops(self, distance, start, destination):
"""
:type distance: List[int]
:type start: int
:type destination: int
:rtype: int
"""
| None | None | None | None | None | None | 53.8 | Level 1 | Hi |
maximum-height-by-stacking-cuboids | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given <code>n</code> <code>cuboids</code> where the dimensions of the <code>i<sup>th</sup></code> cuboid is <code>cuboids[i] = [width<sub>i</sub>, length<sub>i</sub>, height<sub>i</sub>]</code> (<strong>0-indexed</strong>). Choose a <strong>subset</strong> of <code>cuboids</code> and place them on each other.</p>\n\n<p>You can place cuboid <code>i</code> on cuboid <code>j</code> if <code>width<sub>i</sub> <= width<sub>j</sub></code> and <code>length<sub>i</sub> <= length<sub>j</sub></code> and <code>height<sub>i</sub> <= height<sub>j</sub></code>. You can rearrange any cuboid's dimensions by rotating it to put it on another cuboid.</p>\n\n<p>Return <em>the <strong>maximum height</strong> of the stacked</em> <code>cuboids</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<p><strong><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2019/10/21/image.jpg\" style=\"width: 420px; height: 299px;\" /></strong></p>\n\n<pre>\n<strong>Input:</strong> cuboids = [[50,45,20],[95,37,53],[45,23,12]]\n<strong>Output:</strong> 190\n<strong>Explanation:</strong>\nCuboid 1 is placed on the bottom with the 53x37 side facing down with height 95.\nCuboid 0 is placed next with the 45x20 side facing down with height 50.\nCuboid 2 is placed next with the 23x12 side facing down with height 45.\nThe total height is 95 + 50 + 45 = 190.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> cuboids = [[38,25,45],[76,35,3]]\n<strong>Output:</strong> 76\n<strong>Explanation:</strong>\nYou can't place any of the cuboids on the other.\nWe choose cuboid 1 and rotate it so that the 35x3 side is facing down and its height is 76.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]\n<strong>Output:</strong> 102\n<strong>Explanation:</strong>\nAfter rearranging the cuboids, you can see that all cuboids have the same dimension.\nYou can place the 11x7 side down on all cuboids so their heights are 17.\nThe maximum height of stacked cuboids is 6 * 17 = 102.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == cuboids.length</code></li>\n\t<li><code>1 <= n <= 100</code></li>\n\t<li><code>1 <= width<sub>i</sub>, length<sub>i</sub>, height<sub>i</sub> <= 100</code></li>\n</ul>\n",
"difficulty": "Hard",
"questionFrontendId": "1691",
"questionId": "1367",
"questionTitle": "Maximum Height by Stacking Cuboids ",
"questionTitleSlug": "maximum-height-by-stacking-cuboids",
"similarQuestions": "[{\"title\": \"The Number of Weak Characters in the Game\", \"titleSlug\": \"the-number-of-weak-characters-in-the-game\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximum Number of Groups Entering a Competition\", \"titleSlug\": \"maximum-number-of-groups-entering-a-competition\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"23.5K\", \"totalSubmission\": \"41.9K\", \"totalAcceptedRaw\": 23464, \"totalSubmissionRaw\": 41864, \"acRate\": \"56.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 1691 | Hard | [
"Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other.\n\nYou can place cuboid i on cuboid j if widthi <= widthj and lengthi <= lengthj and heighti <= heightj. You can rearrange any cuboid's dimensions ... | [
{
"hash": -8296387676692753000,
"runtime": "57ms",
"solution": "class Solution(object):\n\n def maxHeight(self, cuboids):\n \"\"\"\n :type cuboids: List[List[int]]\n :rtype: int\n \"\"\"\n n = len(cuboids)\n \n LIS = [0]*n\n for c in cuboids:\n ... | class Solution(object):
def maxHeight(self, cuboids):
"""
:type cuboids: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 56 | Level 5 | Hi |
matrix-cells-in-distance-order | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given four integers <code>row</code>, <code>cols</code>, <code>rCenter</code>, and <code>cCenter</code>. There is a <code>rows x cols</code> matrix and you are on the cell with the coordinates <code>(rCenter, cCenter)</code>.</p>\n\n<p>Return <em>the coordinates of all cells in the matrix, sorted by their <strong>distance</strong> from </em><code>(rCenter, cCenter)</code><em> from the smallest distance to the largest distance</em>. You may return the answer in <strong>any order</strong> that satisfies this condition.</p>\n\n<p>The <strong>distance</strong> between two cells <code>(r<sub>1</sub>, c<sub>1</sub>)</code> and <code>(r<sub>2</sub>, c<sub>2</sub>)</code> is <code>|r<sub>1</sub> - r<sub>2</sub>| + |c<sub>1</sub> - c<sub>2</sub>|</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> rows = 1, cols = 2, rCenter = 0, cCenter = 0\n<strong>Output:</strong> [[0,0],[0,1]]\n<strong>Explanation:</strong> The distances from (0, 0) to other cells are: [0,1]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> rows = 2, cols = 2, rCenter = 0, cCenter = 1\n<strong>Output:</strong> [[0,1],[0,0],[1,1],[1,0]]\n<strong>Explanation:</strong> The distances from (0, 1) to other cells are: [0,1,1,2]\nThe answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> rows = 2, cols = 3, rCenter = 1, cCenter = 2\n<strong>Output:</strong> [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]\n<strong>Explanation:</strong> The distances from (1, 2) to other cells are: [0,1,1,2,2,3]\nThere are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= rows, cols <= 100</code></li>\n\t<li><code>0 <= rCenter < rows</code></li>\n\t<li><code>0 <= cCenter < cols</code></li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1030",
"questionId": "1094",
"questionTitle": "Matrix Cells in Distance Order",
"questionTitleSlug": "matrix-cells-in-distance-order",
"similarQuestions": "[{\"title\": \"Cells in a Range on an Excel Sheet\", \"titleSlug\": \"cells-in-a-range-on-an-excel-sheet\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"54.7K\", \"totalSubmission\": \"77.7K\", \"totalAcceptedRaw\": 54702, \"totalSubmissionRaw\": 77738, \"acRate\": \"70.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Geometry",
"slug": "geometry"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 1030 | Easy | [
"You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).\n\nReturn the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance. You ... | [
{
"hash": 4399598729898531300,
"runtime": "163ms",
"solution": "class Solution:\n def allCellsDistOrder(self, rows: int, cols: int, rCenter: int, cCenter: int) -> List[List[int]]:\n ans = []\n #direction = [(0, -1), (0, 1), (-1, 0), (1, 0)]\n q = deque([(rCenter, cCenter)])\n ... | class Solution(object):
def allCellsDistOrder(self, rows, cols, rCenter, cCenter):
"""
:type rows: int
:type cols: int
:type rCenter: int
:type cCenter: int
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 70.4 | Level 1 | Hi |
four-divisors | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code>, return <em>the sum of divisors of the integers in that array that have exactly four divisors</em>. If there is no such integer in the array, return <code>0</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [21,4,7]\n<strong>Output:</strong> 32\n<strong>Explanation:</strong> \n21 has 4 divisors: 1, 3, 7, 21\n4 has 3 divisors: 1, 2, 4\n7 has 2 divisors: 1, 7\nThe answer is the sum of divisors of 21 only.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [21,21]\n<strong>Output:</strong> 64\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3,4,5]\n<strong>Output:</strong> 0\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>4</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1390",
"questionId": "1284",
"questionTitle": "Four Divisors",
"questionTitleSlug": "four-divisors",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"29.8K\", \"totalSubmission\": \"71.3K\", \"totalAcceptedRaw\": 29757, \"totalSubmissionRaw\": 71313, \"acRate\": \"41.7%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
}
]
}
}
} | 1390 | Medium | [
"Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return 0.\n\n \nExample 1:\n\nInput: nums = [21,4,7]\nOutput: 32\nExplanation: \n21 has 4 divisors: 1, 3, 7, 21\n4 has 3 divisors: 1, 2, 4\n7 has 2 diviso... | [
{
"hash": -4161712459746802000,
"runtime": "442ms",
"solution": "class Solution(object):\n def sumFourDivisors(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n my_dict = {}\n sum_total = 0\n \n for num in nums:\n ... | class Solution(object):
def sumFourDivisors(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 41.7 | Level 4 | Hi |
sort-the-matrix-diagonally | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A <strong>matrix diagonal</strong> is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the <strong>matrix diagonal</strong> starting from <code>mat[2][0]</code>, where <code>mat</code> is a <code>6 x 3</code> matrix, includes cells <code>mat[2][0]</code>, <code>mat[3][1]</code>, and <code>mat[4][2]</code>.</p>\n\n<p>Given an <code>m x n</code> matrix <code>mat</code> of integers, sort each <strong>matrix diagonal</strong> in ascending order and return <em>the resulting matrix</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/01/21/1482_example_1_2.png\" style=\"width: 500px; height: 198px;\" />\n<pre>\n<strong>Input:</strong> mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]\n<strong>Output:</strong> [[1,1,1,1],[1,2,2,2],[1,2,3,3]]\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]\n<strong>Output:</strong> [[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>m == mat.length</code></li>\n\t<li><code>n == mat[i].length</code></li>\n\t<li><code>1 <= m, n <= 100</code></li>\n\t<li><code>1 <= mat[i][j] <= 100</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1329",
"questionId": "1253",
"questionTitle": "Sort the Matrix Diagonally",
"questionTitleSlug": "sort-the-matrix-diagonally",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"155.5K\", \"totalSubmission\": \"187.3K\", \"totalAcceptedRaw\": 155476, \"totalSubmissionRaw\": 187341, \"acRate\": \"83.0%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Matrix",
"slug": "matrix"
}
]
}
}
} | 1329 | Medium | [
"A matrix diagonal is a diagonal line of cells starting from some cell in either the topmost row or leftmost column and going in the bottom-right direction until reaching the matrix's end. For example, the matrix diagonal starting from mat[2][0], where mat is a 6 x 3 matrix, includes cells mat[2][0], mat[3][1], and... | [
{
"hash": -408545904057070700,
"runtime": "71ms",
"solution": "class Solution(object):\n def diagonalSort(self, mat):\n m, n = len(mat), len(mat[0])\n def sort(i, j):\n ij = zip(range(i,m), range(j,n))\n print(ij[0])\n sorted_diagonal = sorted(mat[i][j] ... | class Solution(object):
def diagonalSort(self, mat):
"""
:type mat: List[List[int]]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 83 | Level 2 | Hi |
sum-of-subarray-minimums | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers arr, find the sum of <code>min(b)</code>, where <code>b</code> ranges over every (contiguous) subarray of <code>arr</code>. Since the answer may be large, return the answer <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [3,1,2,4]\n<strong>Output:</strong> 17\n<strong>Explanation:</strong> \nSubarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,2,4], [3,1,2,4]. \nMinimums are 3, 1, 2, 4, 1, 1, 2, 1, 1, 1.\nSum is 17.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [11,81,94,43,3]\n<strong>Output:</strong> 444\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= arr.length <= 3 * 10<sup>4</sup></code></li>\n\t<li><code>1 <= arr[i] <= 3 * 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "907",
"questionId": "943",
"questionTitle": "Sum of Subarray Minimums",
"questionTitleSlug": "sum-of-subarray-minimums",
"similarQuestions": "[{\"title\": \"Sum of Subarray Ranges\", \"titleSlug\": \"sum-of-subarray-ranges\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Sum of Total Strength of Wizards\", \"titleSlug\": \"sum-of-total-strength-of-wizards\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"162.6K\", \"totalSubmission\": \"462.4K\", \"totalAcceptedRaw\": 162605, \"totalSubmissionRaw\": 462435, \"acRate\": \"35.2%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Stack",
"slug": "stack"
},
{
"name": "Monotonic Stack",
"slug": "monotonic-stack"
}
]
}
}
} | 907 | Medium | [
"Given an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 10⁹ + 7.\n\n \nExample 1:\n\nInput: arr = [3,1,2,4]\nOutput: 17\nExplanation: \nSubarrays are [3], [1], [2], [4], [3,1], [1,2], [2,4], [3,1,2], [1,... | [
{
"hash": -6352935830137404000,
"runtime": "457ms",
"solution": "class Solution(object):\n def sumSubarrayMins(self, nums):\n\n n = len(nums)\n R = [n-1]*n\n L = [0]*n\n stack = []\n\n for i in range(n):\n if not stack or nums[stack[-1]] <= nums[i]:\n ... | class Solution(object):
def sumSubarrayMins(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 35.2 | Level 4 | Hi |
closest-dessert-cost | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You would like to make dessert and are preparing to buy the ingredients. You have <code>n</code> ice cream base flavors and <code>m</code> types of toppings to choose from. You must follow these rules when making your dessert:</p>\n\n<ul>\n\t<li>There must be <strong>exactly one</strong> ice cream base.</li>\n\t<li>You can add <strong>one or more</strong> types of topping or have no toppings at all.</li>\n\t<li>There are <strong>at most two</strong> of <strong>each type</strong> of topping.</li>\n</ul>\n\n<p>You are given three inputs:</p>\n\n<ul>\n\t<li><code>baseCosts</code>, an integer array of length <code>n</code>, where each <code>baseCosts[i]</code> represents the price of the <code>i<sup>th</sup></code> ice cream base flavor.</li>\n\t<li><code>toppingCosts</code>, an integer array of length <code>m</code>, where each <code>toppingCosts[i]</code> is the price of <strong>one</strong> of the <code>i<sup>th</sup></code> topping.</li>\n\t<li><code>target</code>, an integer representing your target price for dessert.</li>\n</ul>\n\n<p>You want to make a dessert with a total cost as close to <code>target</code> as possible.</p>\n\n<p>Return <em>the closest possible cost of the dessert to </em><code>target</code>. If there are multiple, return <em>the <strong>lower</strong> one.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> baseCosts = [1,7], toppingCosts = [3,4], target = 10\n<strong>Output:</strong> 10\n<strong>Explanation:</strong> Consider the following combination (all 0-indexed):\n- Choose base 1: cost 7\n- Take 1 of topping 0: cost 1 x 3 = 3\n- Take 0 of topping 1: cost 0 x 4 = 0\nTotal: 7 + 3 + 0 = 10.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> baseCosts = [2,3], toppingCosts = [4,5,100], target = 18\n<strong>Output:</strong> 17\n<strong>Explanation:</strong> Consider the following combination (all 0-indexed):\n- Choose base 1: cost 3\n- Take 1 of topping 0: cost 1 x 4 = 4\n- Take 2 of topping 1: cost 2 x 5 = 10\n- Take 0 of topping 2: cost 0 x 100 = 0\nTotal: 3 + 4 + 10 + 0 = 17. You cannot make a dessert with a total cost of 18.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> baseCosts = [3,10], toppingCosts = [2,5], target = 9\n<strong>Output:</strong> 8\n<strong>Explanation:</strong> It is possible to make desserts with cost 8 and 10. Return 8 as it is the lower cost.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>n == baseCosts.length</code></li>\n\t<li><code>m == toppingCosts.length</code></li>\n\t<li><code>1 <= n, m <= 10</code></li>\n\t<li><code>1 <= baseCosts[i], toppingCosts[i] <= 10<sup>4</sup></code></li>\n\t<li><code>1 <= target <= 10<sup>4</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1774",
"questionId": "1900",
"questionTitle": "Closest Dessert Cost",
"questionTitleSlug": "closest-dessert-cost",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"28.1K\", \"totalSubmission\": \"59.3K\", \"totalAcceptedRaw\": 28135, \"totalSubmissionRaw\": 59332, \"acRate\": \"47.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Backtracking",
"slug": "backtracking"
}
]
}
}
} | 1774 | Medium | [
"You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:\n\n\n\tThere must be exactly one ice cream base.\n\tYou can add one or more types of topping or have no toppings a... | [
{
"hash": -5975379313230519000,
"runtime": "1027ms",
"solution": "class Solution(object):\n def closestCost(self, baseCosts, toppingCosts, target):\n \"\"\"\n :type baseCosts: List[int]\n :type toppingCosts: List[int]\n :type target: int\n :rtype: int\n \"\"\... | class Solution(object):
def closestCost(self, baseCosts, toppingCosts, target):
"""
:type baseCosts: List[int]
:type toppingCosts: List[int]
:type target: int
:rtype: int
"""
| None | None | None | None | None | None | 47.4 | Level 3 | Hi |
furthest-building-you-can-reach | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>heights</code> representing the heights of buildings, some <code>bricks</code>, and some <code>ladders</code>.</p>\n\n<p>You start your journey from building <code>0</code> and move to the next building by possibly using bricks or ladders.</p>\n\n<p>While moving from building <code>i</code> to building <code>i+1</code> (<strong>0-indexed</strong>),</p>\n\n<ul>\n\t<li>If the current building's height is <strong>greater than or equal</strong> to the next building's height, you do <strong>not</strong> need a ladder or bricks.</li>\n\t<li>If the current building's height is <b>less than</b> the next building's height, you can either use <strong>one ladder</strong> or <code>(h[i+1] - h[i])</code> <strong>bricks</strong>.</li>\n</ul>\n\n<p><em>Return the furthest building index (0-indexed) you can reach if you use the given ladders and bricks optimally.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/27/q4.gif\" style=\"width: 562px; height: 561px;\" />\n<pre>\n<strong>Input:</strong> heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1\n<strong>Output:</strong> 4\n<strong>Explanation:</strong> Starting at building 0, you can follow these steps:\n- Go to building 1 without using ladders nor bricks since 4 >= 2.\n- Go to building 2 using 5 bricks. You must use either bricks or ladders because 2 < 7.\n- Go to building 3 without using ladders nor bricks since 7 >= 6.\n- Go to building 4 using your only ladder. You must use either bricks or ladders because 6 < 9.\nIt is impossible to go beyond building 4 because you do not have any more bricks or ladders.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2\n<strong>Output:</strong> 7\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> heights = [14,3,19,3], bricks = 17, ladders = 0\n<strong>Output:</strong> 3\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= heights.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= heights[i] <= 10<sup>6</sup></code></li>\n\t<li><code>0 <= bricks <= 10<sup>9</sup></code></li>\n\t<li><code>0 <= ladders <= heights.length</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1642",
"questionId": "1762",
"questionTitle": "Furthest Building You Can Reach",
"questionTitleSlug": "furthest-building-you-can-reach",
"similarQuestions": "[{\"title\": \"Make the Prefix Sum Non-negative\", \"titleSlug\": \"make-the-prefix-sum-non-negative\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Find Building Where Alice and Bob Can Meet\", \"titleSlug\": \"find-building-where-alice-and-bob-can-meet\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"122.2K\", \"totalSubmission\": \"252.4K\", \"totalAcceptedRaw\": 122198, \"totalSubmissionRaw\": 252413, \"acRate\": \"48.4%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Heap (Priority Queue)",
"slug": "heap-priority-queue"
}
]
}
}
} | 1642 | Medium | [
"You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.\n\nYou start your journey from building 0 and move to the next building by possibly using bricks or ladders.\n\nWhile moving from building i to building i+1 (0-indexed),\n\n\n\tIf the current building's hei... | [
{
"hash": -2176467611281908500,
"runtime": "574ms",
"solution": "import heapq\nclass Solution(object):\n def furthestBuilding(self, heights, bricks, ladders):\n \"\"\"\n :type heights: List[int]\n :type bricks: int\n :type ladders: int\n :rtype: int\n \"\"\"\... | class Solution(object):
def furthestBuilding(self, heights, bricks, ladders):
"""
:type heights: List[int]
:type bricks: int
:type ladders: int
:rtype: int
"""
| None | None | None | None | None | None | 48.4 | Level 3 | Hi |
statistics-from-a-large-sample | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a large sample of integers in the range <code>[0, 255]</code>. Since the sample is so large, it is represented by an array <code>count</code> where <code>count[k]</code> is the <strong>number of times</strong> that <code>k</code> appears in the sample.</p>\n\n<p>Calculate the following statistics:</p>\n\n<ul>\n\t<li><code>minimum</code>: The minimum element in the sample.</li>\n\t<li><code>maximum</code>: The maximum element in the sample.</li>\n\t<li><code>mean</code>: The average of the sample, calculated as the total sum of all elements divided by the total number of elements.</li>\n\t<li><code>median</code>:\n\t<ul>\n\t\t<li>If the sample has an odd number of elements, then the <code>median</code> is the middle element once the sample is sorted.</li>\n\t\t<li>If the sample has an even number of elements, then the <code>median</code> is the average of the two middle elements once the sample is sorted.</li>\n\t</ul>\n\t</li>\n\t<li><code>mode</code>: The number that appears the most in the sample. It is guaranteed to be <strong>unique</strong>.</li>\n</ul>\n\n<p>Return <em>the statistics of the sample as an array of floating-point numbers </em><code>[minimum, maximum, mean, median, mode]</code><em>. Answers within </em><code>10<sup>-5</sup></code><em> of the actual answer will be accepted.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> count = [0,1,3,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n<strong>Output:</strong> [1.00000,3.00000,2.37500,2.50000,3.00000]\n<strong>Explanation:</strong> The sample represented by count is [1,2,2,2,3,3,3,3].\nThe minimum and maximum are 1 and 3 respectively.\nThe mean is (1+2+2+2+3+3+3+3) / 8 = 19 / 8 = 2.375.\nSince the size of the sample is even, the median is the average of the two middle elements 2 and 3, which is 2.5.\nThe mode is 3 as it appears the most in the sample.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> count = [0,4,3,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n<strong>Output:</strong> [1.00000,4.00000,2.18182,2.00000,1.00000]\n<strong>Explanation:</strong> The sample represented by count is [1,1,1,1,2,2,2,3,3,4,4].\nThe minimum and maximum are 1 and 4 respectively.\nThe mean is (1+1+1+1+2+2+2+3+3+4+4) / 11 = 24 / 11 = 2.18181818... (for display purposes, the output shows the rounded number 2.18182).\nSince the size of the sample is odd, the median is the middle element 2.\nThe mode is 1 as it appears the most in the sample.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>count.length == 256</code></li>\n\t<li><code>0 <= count[i] <= 10<sup>9</sup></code></li>\n\t<li><code>1 <= sum(count) <= 10<sup>9</sup></code></li>\n\t<li>The mode of the sample that <code>count</code> represents is <strong>unique</strong>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1093",
"questionId": "1183",
"questionTitle": "Statistics from a Large Sample",
"questionTitleSlug": "statistics-from-a-large-sample",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"18K\", \"totalSubmission\": \"42.5K\", \"totalAcceptedRaw\": 18044, \"totalSubmissionRaw\": 42457, \"acRate\": \"42.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Probability and Statistics",
"slug": "probability-and-statistics"
}
]
}
}
} | 1093 | Medium | [
"You are given a large sample of integers in the range [0, 255]. Since the sample is so large, it is represented by an array count where count[k] is the number of times that k appears in the sample.\n\nCalculate the following statistics:\n\n\n\tminimum: The minimum element in the sample.\n\tmaximum: The maximum ele... | [
{
"hash": -2355910439818156500,
"runtime": "27ms",
"solution": "class Solution(object):\n def sampleStats(self, count):\n #min, max, mean, mode\n minimum, maximum, mean, mode = -1, -1, 0, -1\n mode_help = 0\n how_many = 0\n\n for i, v in enumerate(count):\n ... | class Solution(object):
def sampleStats(self, count):
"""
:type count: List[int]
:rtype: List[float]
"""
| None | None | None | None | None | None | 42.5 | Level 4 | Hi |
frequency-of-the-most-frequent-element | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The <strong>frequency</strong> of an element is the number of times it occurs in an array.</p>\n\n<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. In one operation, you can choose an index of <code>nums</code> and increment the element at that index by <code>1</code>.</p>\n\n<p>Return <em>the <strong>maximum possible frequency</strong> of an element after performing <strong>at most</strong> </em><code>k</code><em> operations</em>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,4], k = 5\n<strong>Output:</strong> 3<strong>\nExplanation:</strong> Increment the first element three times and the second element two times to make nums = [4,4,4].\n4 has a frequency of 3.</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,4,8,13], k = 5\n<strong>Output:</strong> 2\n<strong>Explanation:</strong> There are multiple optimal solutions:\n- Increment the first element three times to make nums = [4,4,8,13]. 4 has a frequency of 2.\n- Increment the second element four times to make nums = [1,8,8,13]. 8 has a frequency of 2.\n- Increment the third element five times to make nums = [1,4,13,13]. 13 has a frequency of 2.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [3,9,6], k = 2\n<strong>Output:</strong> 1\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= k <= 10<sup>5</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "1838",
"questionId": "1966",
"questionTitle": "Frequency of the Most Frequent Element",
"questionTitleSlug": "frequency-of-the-most-frequent-element",
"similarQuestions": "[{\"title\": \"Find All Lonely Numbers in the Array\", \"titleSlug\": \"find-all-lonely-numbers-in-the-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Longest Nice Subarray\", \"titleSlug\": \"longest-nice-subarray\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"118.3K\", \"totalSubmission\": \"253.6K\", \"totalAcceptedRaw\": 118251, \"totalSubmissionRaw\": 253647, \"acRate\": \"46.6%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Binary Search",
"slug": "binary-search"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Sliding Window",
"slug": "sliding-window"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Prefix Sum",
"slug": "prefix-sum"
}
]
}
}
} | 1838 | Medium | [
"The frequency of an element is the number of times it occurs in an array.\n\nYou are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1.\n\nReturn the maximum possible frequency of an element after performing at most k operat... | [
{
"hash": -3151006346759881000,
"runtime": "1345ms",
"solution": "class Solution(object):\n def maxFrequency(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n def curr_window_len(end):\n i, j = 0, end\n ... | class Solution(object):
def maxFrequency(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 46.6 | Level 4 | Hi |
check-if-binary-string-has-at-most-one-segment-of-ones | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a binary string <code>s</code> <strong>without leading zeros</strong>, return <code>true</code> <em>if </em><code>s</code><em> contains <strong>at most one contiguous segment of ones</strong></em>. Otherwise, return <code>false</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "1001"\n<strong>Output:</strong> false\n<strong>Explanation: </strong>The ones do not form a contiguous segment.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> s = "110"\n<strong>Output:</strong> true</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= s.length <= 100</code></li>\n\t<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>\n\t<li><code>s[0]</code> is <code>'1'</code>.</li>\n</ul>\n",
"difficulty": "Easy",
"questionFrontendId": "1784",
"questionId": "1910",
"questionTitle": "Check if Binary String Has at Most One Segment of Ones",
"questionTitleSlug": "check-if-binary-string-has-at-most-one-segment-of-ones",
"similarQuestions": "[{\"title\": \"Longer Contiguous Segments of Ones than Zeros\", \"titleSlug\": \"longer-contiguous-segments-of-ones-than-zeros\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"38.3K\", \"totalSubmission\": \"97K\", \"totalAcceptedRaw\": 38295, \"totalSubmissionRaw\": 97038, \"acRate\": \"39.5%\"}",
"topicTags": [
{
"name": "String",
"slug": "string"
}
]
}
}
} | 1784 | Easy | [
"Given a binary string s without leading zeros, return true if s contains at most one contiguous segment of ones. Otherwise, return false.\n\n \nExample 1:\n\nInput: s = \"1001\"\nOutput: false\nExplanation: The ones do not form a contiguous segment.\n\n\nExample 2:\n\nInput: s = \"110\"\nOutput: true\n\n \... | [
{
"hash": -3318028922387258000,
"runtime": "14ms",
"solution": "class Solution(object):\n def checkOnesSegment(self, s):\n \"\"\"\n :type s: str\n :rtype: bool\n \"\"\"\n i = 0\n while s[i] == \"1\":\n i +=1\n if i == len(s):\n ... | class Solution(object):
def checkOnesSegment(self, s):
"""
:type s: str
:rtype: bool
"""
| None | None | None | None | None | None | 39.5 | Level 1 | Hi |
largest-divisible-subset | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a set of <strong>distinct</strong> positive integers <code>nums</code>, return the largest subset <code>answer</code> such that every pair <code>(answer[i], answer[j])</code> of elements in this subset satisfies:</p>\n\n<ul>\n\t<li><code>answer[i] % answer[j] == 0</code>, or</li>\n\t<li><code>answer[j] % answer[i] == 0</code></li>\n</ul>\n\n<p>If there are multiple solutions, return any of them.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,3]\n<strong>Output:</strong> [1,2]\n<strong>Explanation:</strong> [1,3] is also accepted.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,2,4,8]\n<strong>Output:</strong> [1,2,4,8]\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 1000</code></li>\n\t<li><code>1 <= nums[i] <= 2 * 10<sup>9</sup></code></li>\n\t<li>All the integers in <code>nums</code> are <strong>unique</strong>.</li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "368",
"questionId": "368",
"questionTitle": "Largest Divisible Subset",
"questionTitleSlug": "largest-divisible-subset",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"199.1K\", \"totalSubmission\": \"471.2K\", \"totalAcceptedRaw\": 199124, \"totalSubmissionRaw\": 471221, \"acRate\": \"42.3%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Math",
"slug": "math"
},
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 368 | Medium | [
"Given a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:\n\n\n\tanswer[i] % answer[j] == 0, or\n\tanswer[j] % answer[i] == 0\n\n\nIf there are multiple solutions, return any of them.\n\n \nExample 1:\n\nInput:... | [
{
"hash": -8485533071875812000,
"runtime": "389ms",
"solution": "class Solution(object):\n def largestDivisibleSubset(self, nums):\n nums.sort()\n dp = [{nums[i]} for i in range(len(nums))]\n \n for i in range(len(nums)):\n for j in range(i):\n if... | class Solution(object):
def largestDivisibleSubset(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 42.3 | Level 4 | Hi |
number-of-people-aware-of-a-secret | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>On day <code>1</code>, one person discovers a secret.</p>\n\n<p>You are given an integer <code>delay</code>, which means that each person will <strong>share</strong> the secret with a new person <strong>every day</strong>, starting from <code>delay</code> days after discovering the secret. You are also given an integer <code>forget</code>, which means that each person will <strong>forget</strong> the secret <code>forget</code> days after discovering it. A person <strong>cannot</strong> share the secret on the same day they forgot it, or on any day afterwards.</p>\n\n<p>Given an integer <code>n</code>, return<em> the number of people who know the secret at the end of day </em><code>n</code>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 6, delay = 2, forget = 4\n<strong>Output:</strong> 5\n<strong>Explanation:</strong>\nDay 1: Suppose the first person is named A. (1 person)\nDay 2: A is the only person who knows the secret. (1 person)\nDay 3: A shares the secret with a new person, B. (2 people)\nDay 4: A shares the secret with a new person, C. (3 people)\nDay 5: A forgets the secret, and B shares the secret with a new person, D. (3 people)\nDay 6: B shares the secret with E, and C shares the secret with F. (5 people)\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> n = 4, delay = 1, forget = 3\n<strong>Output:</strong> 6\n<strong>Explanation:</strong>\nDay 1: The first person is named A. (1 person)\nDay 2: A shares the secret with B. (2 people)\nDay 3: A and B share the secret with 2 new people, C and D. (4 people)\nDay 4: A forgets the secret. B, C, and D share the secret with 3 new people. (6 people)\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>2 <= n <= 1000</code></li>\n\t<li><code>1 <= delay < forget <= n</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2327",
"questionId": "2408",
"questionTitle": "Number of People Aware of a Secret",
"questionTitleSlug": "number-of-people-aware-of-a-secret",
"similarQuestions": "[]",
"stats": "{\"totalAccepted\": \"20K\", \"totalSubmission\": \"44.4K\", \"totalAcceptedRaw\": 19953, \"totalSubmissionRaw\": 44410, \"acRate\": \"44.9%\"}",
"topicTags": [
{
"name": "Dynamic Programming",
"slug": "dynamic-programming"
},
{
"name": "Queue",
"slug": "queue"
},
{
"name": "Simulation",
"slug": "simulation"
}
]
}
}
} | 2327 | Medium | [
"On day 1, one person discovers a secret.\n\nYou are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are also given an integer forget, which means that each person will forget the secret forget days af... | [
{
"hash": -1604165085863802000,
"runtime": "19ms",
"solution": "class Solution(object):\n def peopleAwareOfSecret(self, n, delay, forget):\n dp = [1] + [0] * (n - 1)\n mod = 10 ** 9 + 7\n share = 0\n for i in range(1, n):\n dp[i] = share = (share + dp[i - delay]... | class Solution(object):
def peopleAwareOfSecret(self, n, delay, forget):
"""
:type n: int
:type delay: int
:type forget: int
:rtype: int
"""
| None | None | None | None | None | None | 44.9 | Level 4 | Hi |
find-all-lonely-numbers-in-the-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code>. A number <code>x</code> is <strong>lonely</strong> when it appears only <strong>once</strong>, and no <strong>adjacent</strong> numbers (i.e. <code>x + 1</code> and <code>x - 1)</code> appear in the array.</p>\n\n<p>Return <em><strong>all</strong> lonely numbers in </em><code>nums</code>. You may return the answer in <strong>any order</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [10,6,5,8]\n<strong>Output:</strong> [10,8]\n<strong>Explanation:</strong> \n- 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.\n- 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.\n- 5 is not a lonely number since 6 appears in nums and vice versa.\nHence, the lonely numbers in nums are [10, 8].\nNote that [8, 10] may also be returned.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> nums = [1,3,5,3]\n<strong>Output:</strong> [1,5]\n<strong>Explanation:</strong> \n- 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.\n- 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.\n- 3 is not a lonely number since it appears twice.\nHence, the lonely numbers in nums are [1, 5].\nNote that [5, 1] may also be returned.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>\n\t<li><code>0 <= nums[i] <= 10<sup>6</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2150",
"questionId": "2270",
"questionTitle": "Find All Lonely Numbers in the Array",
"questionTitleSlug": "find-all-lonely-numbers-in-the-array",
"similarQuestions": "[{\"title\": \"Frequency of the Most Frequent Element\", \"titleSlug\": \"frequency-of-the-most-frequent-element\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"42.2K\", \"totalSubmission\": \"69.7K\", \"totalAcceptedRaw\": 42191, \"totalSubmissionRaw\": 69706, \"acRate\": \"60.5%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Hash Table",
"slug": "hash-table"
},
{
"name": "Counting",
"slug": "counting"
}
]
}
}
} | 2150 | Medium | [
"You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.\n\nReturn all lonely numbers in nums. You may return the answer in any order.\n\n \nExample 1:\n\nInput: nums = [10,6,5,8]\nOutput: [10,8]\nExplanation: \n- 10 is... | [
{
"hash": -6980090810856578000,
"runtime": "1255ms",
"solution": "from collections import Counter\nclass Solution(object):\n def findLonely(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n\n # O(nlogn)\n # if len(nums) == 1:\n ... | class Solution(object):
def findLonely(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 60.5 | Level 2 | Hi |
kth-largest-sum-in-a-binary-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given the <code>root</code> of a binary tree and a positive integer <code>k</code>.</p>\n\n<p>The <strong>level sum</strong> in the tree is the sum of the values of the nodes that are on the <strong>same</strong> level.</p>\n\n<p>Return<em> the </em><code>k<sup>th</sup></code><em> <strong>largest</strong> level sum in the tree (not necessarily distinct)</em>. If there are fewer than <code>k</code> levels in the tree, return <code>-1</code>.</p>\n\n<p><strong>Note</strong> that two nodes are on the same level if they have the same distance from the root.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/14/binaryytreeedrawio-2.png\" style=\"width: 301px; height: 284px;\" />\n<pre>\n<strong>Input:</strong> root = [5,8,9,2,1,3,7,4,6], k = 2\n<strong>Output:</strong> 13\n<strong>Explanation:</strong> The level sums are the following:\n- Level 1: 5.\n- Level 2: 8 + 9 = 17.\n- Level 3: 2 + 1 + 3 + 7 = 13.\n- Level 4: 4 + 6 = 10.\nThe 2<sup>nd</sup> largest level sum is 13.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2022/12/14/treedrawio-3.png\" style=\"width: 181px; height: 181px;\" />\n<pre>\n<strong>Input:</strong> root = [1,2,null,3], k = 1\n<strong>Output:</strong> 3\n<strong>Explanation:</strong> The largest level sum is 3.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li>The number of nodes in the tree is <code>n</code>.</li>\n\t<li><code>2 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= Node.val <= 10<sup>6</sup></code></li>\n\t<li><code>1 <= k <= n</code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2583",
"questionId": "2646",
"questionTitle": "Kth Largest Sum in a Binary Tree",
"questionTitleSlug": "kth-largest-sum-in-a-binary-tree",
"similarQuestions": "[{\"title\": \"Binary Tree Preorder Traversal\", \"titleSlug\": \"binary-tree-preorder-traversal\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Maximum Level Sum of a Binary Tree\", \"titleSlug\": \"maximum-level-sum-of-a-binary-tree\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"30.7K\", \"totalSubmission\": \"65.5K\", \"totalAcceptedRaw\": 30695, \"totalSubmissionRaw\": 65496, \"acRate\": \"46.9%\"}",
"topicTags": [
{
"name": "Tree",
"slug": "tree"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search"
},
{
"name": "Sorting",
"slug": "sorting"
},
{
"name": "Binary Tree",
"slug": "binary-tree"
}
]
}
}
} | 2583 | Medium | [
"You are given the root of a binary tree and a positive integer k.\n\nThe level sum in the tree is the sum of the values of the nodes that are on the same level.\n\nReturn the kth largest level sum in the tree (not necessarily distinct). If there are fewer than k levels in the tree, return -1.\n\nNote that two node... | [
{
"hash": 1374110908500243500,
"runtime": "722ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode(object):\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution(object):\n def k... | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def kthLargestLevelSum(self, root, k):
"""
:type root: Optional[TreeNode]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 46.9 | Level 4 | Hi |
maximum-matching-of-players-with-trainers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>players</code>, where <code>players[i]</code> represents the <strong>ability</strong> of the <code>i<sup>th</sup></code> player. You are also given a <strong>0-indexed</strong> integer array <code>trainers</code>, where <code>trainers[j]</code> represents the <strong>training capacity </strong>of the <code>j<sup>th</sup></code> trainer.</p>\n\n<p>The <code>i<sup>th</sup></code> player can <strong>match</strong> with the <code>j<sup>th</sup></code> trainer if the player's ability is <strong>less than or equal to</strong> the trainer's training capacity. Additionally, the <code>i<sup>th</sup></code> player can be matched with at most one trainer, and the <code>j<sup>th</sup></code> trainer can be matched with at most one player.</p>\n\n<p>Return <em>the <strong>maximum</strong> number of matchings between </em><code>players</code><em> and </em><code>trainers</code><em> that satisfy these conditions.</em></p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> players = [4,7,9], trainers = [8,2,5,8]\n<strong>Output:</strong> 2\n<strong>Explanation:</strong>\nOne of the ways we can form two matchings is as follows:\n- players[0] can be matched with trainers[0] since 4 <= 8.\n- players[1] can be matched with trainers[3] since 7 <= 8.\nIt can be proven that 2 is the maximum number of matchings that can be formed.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> players = [1,1,1], trainers = [10]\n<strong>Output:</strong> 1\n<strong>Explanation:</strong>\nThe trainer can be matched with any of the 3 players.\nEach player can only be matched with one trainer, so the maximum answer is 1.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= players.length, trainers.length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= players[i], trainers[j] <= 10<sup>9</sup></code></li>\n</ul>\n",
"difficulty": "Medium",
"questionFrontendId": "2410",
"questionId": "2497",
"questionTitle": "Maximum Matching of Players With Trainers",
"questionTitleSlug": "maximum-matching-of-players-with-trainers",
"similarQuestions": "[{\"title\": \"Most Profit Assigning Work\", \"titleSlug\": \"most-profit-assigning-work\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Long Pressed Name\", \"titleSlug\": \"long-pressed-name\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Interval List Intersections\", \"titleSlug\": \"interval-list-intersections\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Largest Merge Of Two Strings\", \"titleSlug\": \"largest-merge-of-two-strings\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximum Number of Tasks You Can Assign\", \"titleSlug\": \"maximum-number-of-tasks-you-can-assign\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Successful Pairs of Spells and Potions\", \"titleSlug\": \"successful-pairs-of-spells-and-potions\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"The Latest Time to Catch a Bus\", \"titleSlug\": \"the-latest-time-to-catch-a-bus\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Maximize Greatness of an Array\", \"titleSlug\": \"maximize-greatness-of-an-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"stats": "{\"totalAccepted\": \"29.6K\", \"totalSubmission\": \"48K\", \"totalAcceptedRaw\": 29627, \"totalSubmissionRaw\": 47961, \"acRate\": \"61.8%\"}",
"topicTags": [
{
"name": "Array",
"slug": "array"
},
{
"name": "Two Pointers",
"slug": "two-pointers"
},
{
"name": "Greedy",
"slug": "greedy"
},
{
"name": "Sorting",
"slug": "sorting"
}
]
}
}
} | 2410 | Medium | [
"You are given a 0-indexed integer array players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of the jth trainer.\n\nThe ith player can match with the jth trainer if the player's ability is less ... | [
{
"hash": -7561474539317036000,
"runtime": "625ms",
"solution": "class Solution:\n def matchPlayersAndTrainers(self, players, trainers):\n players.sort()\n trainers.sort()\n i, j = len(players) - 1, len(trainers) - 1\n matchings = 0\n while i >= 0 and j >= 0:\n ... | class Solution(object):
def matchPlayersAndTrainers(self, players, trainers):
"""
:type players: List[int]
:type trainers: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 61.8 | Level 2 | Hi |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.