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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-number-of-points-with-cost | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> integer matrix <code>points</code> (<strong>0-indexed</strong>). Starting with <code>0</code> points, you want to <strong>maximize</strong> the number of points you can get from the matrix.</p>\... | 1937 | Medium | [
"You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix.\n\nTo gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add points[r][c] to your score.\n\nHowever, you will lose point... | [
{
"hash": -4801405427222853000,
"runtime": "1486ms",
"solution": "class Solution(object):\n def maxPoints(self, points):\n \"\"\"\n :type points: List[List[int]]\n :rtype: int\n \"\"\"\n m, n = len(points), len(points[0])\n for i in range(m - 1):\n ... | class Solution(object):
def maxPoints(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 35.8 | Level 4 | Hi |
number-of-increasing-paths-in-a-grid | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code>, where you can move from a cell to any adjacent cell in all <code>4</code> directions.</p>\n\n<p>Return <em>the number of <strong>strictly</strong> <strong>incre... | 2328 | Hard | [
"You are given an m x n integer matrix grid, where you can move from a cell to any adjacent cell in all 4 directions.\n\nReturn the number of strictly increasing paths in the grid such that you can start from any cell and end at any cell. Since the answer may be very large, return it modulo 10⁹ + 7.\n\nTwo paths ar... | [
{
"hash": -8908210234587058000,
"runtime": "1905ms",
"solution": "import heapq \nclass Solution(object):\n def countPaths(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n\n # This method is memory efficient without recurssion\n sel... | class Solution(object):
def countPaths(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 58.9 | Level 5 | Hi |
reverse-string-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code> and an integer <code>k</code>, reverse the first <code>k</code> characters for every <code>2k</code> characters counting from the start of the string.</p>\n\n<p>If there are fewer than <code>k</code> ... | 541 | Easy | [
"Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.\n\nIf there are fewer than k characters left, reverse all of them. If there are less than 2k but greater than or equal to k characters, then reverse the first k characters and leave the ... | [
{
"hash": -5477435433618438000,
"runtime": "3ms",
"solution": "class Solution(object):\n def reverseStr(self, s, k):\n a = list(s)\n for i in range(0, len(a), 2*k):\n a[i:i+k] = a[i:i+k][::-1]\n return \"\".join(a)"
},
{
"hash": -9018013106878685000,
"runti... | class Solution(object):
def reverseStr(self, s, k):
"""
:type s: str
:type k: int
:rtype: str
"""
| None | None | None | None | None | None | 50.5 | Level 1 | Hi |
find-the-array-concatenation-value | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p>\n\n<p>The <strong>concatenation</strong> of two numbers is the number formed by concatenating their numerals.</p>\n\n<ul>\n\t<li>For example, the conc... | 2562 | Easy | [
"You are given a 0-indexed integer array nums.\n\nThe concatenation of two numbers is the number formed by concatenating their numerals.\n\n\n\tFor example, the concatenation of 15, 49 is 1549.\n\n\nThe concatenation value of nums is initially equal to 0. Perform this operation until nums becomes empty:\n\n\n\tIf t... | [
{
"hash": 1022735238686497900,
"runtime": "31ms",
"solution": "class Solution(object):\n def findTheArrayConcVal(self, nums):\n concat_value = 0\n while len(nums) > 0:\n if len(nums) > 1:\n concat_value += int(str(nums[0]) + str(nums[-1]))\n nums... | class Solution(object):
def findTheArrayConcVal(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 69.2 | Level 1 | Hi |
find-all-k-distant-indices-in-an-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and two integers <code>key</code> and <code>k</code>. A <strong>k-distant index</strong> is an index <code>i</code> of <code>nums</code> for which there ex... | 2200 | Easy | [
"You are given a 0-indexed integer array nums and two integers key and k. A k-distant index is an index i of nums for which there exists at least one index j such that |i - j| <= k and nums[j] == key.\n\nReturn a list of all k-distant indices sorted in increasing order.\n\n \nExample 1:\n\nInput: nums = [3,4,9,1,3,... | [
{
"hash": -3058539654544898000,
"runtime": "240ms",
"solution": "class Solution(object):\n def findKDistantIndices(self, nums, key, k):\n \"\"\"\n :type nums: List[int]\n :type key: int\n :type k: int\n :rtype: List[int]\n \"\"\"\n #===================... | class Solution(object):
def findKDistantIndices(self, nums, key, k):
"""
:type nums: List[int]
:type key: int
:type k: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 65.2 | Level 1 | Hi |
remove-max-number-of-edges-to-keep-graph-fully-traversable | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Alice and Bob have an undirected graph of <code>n</code> nodes and three types of edges:</p>\n\n<ul>\n\t<li>Type 1: Can be traversed by Alice only.</li>\n\t<li>Type 2: Can be traversed by Bob only.</li>\n\t<li>Type 3: Can be trave... | 1579 | Hard | [
"Alice and Bob have an undirected graph of n nodes and three types of edges:\n\n\n\tType 1: Can be traversed by Alice only.\n\tType 2: Can be traversed by Bob only.\n\tType 3: Can be traversed by both Alice and Bob.\n\n\nGiven an array edges where edges[i] = [typei, ui, vi] represents a bidirectional edge of type t... | [
{
"hash": 1947936835259957800,
"runtime": "1638ms",
"solution": "class Solution(object):\n def maxNumEdgesToRemove(self, n, edges):\n \"\"\"\n :type n: int\n :type edges: List[List[int]]\n :rtype: int\n \"\"\"\n parents_bob = [_ for _ in range(n)]\n pa... | class Solution(object):
def maxNumEdgesToRemove(self, n, edges):
"""
:type n: int
:type edges: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 64.5 | Level 5 | Hi |
minimum-increment-to-make-array-unique | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code>. In one move, you can pick an index <code>i</code> where <code>0 <= i < nums.length</code> and increment <code>nums[i]</code> by <code>1</code>.</p>\n\n<p>Return <em>the minim... | 945 | Medium | [
"You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1.\n\nReturn the minimum number of moves to make every value in nums unique.\n\nThe test cases are generated so that the answer fits in a 32-bit integer.\n\n \nExample 1:\n\nInput: nums = [... | [
{
"hash": -4055355724754540500,
"runtime": "691ms",
"solution": "class Solution(object):\n def minIncrementForUnique(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n count = 0\n nums.sort()\n lowest = nums[0]\n for i in ran... | class Solution(object):
def minIncrementForUnique(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 52.1 | Level 3 | Hi |
house-robber-iii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The thief has found himself a new place for his thievery again. There is only one entrance to this area, called <code>root</code>.</p>\n\n<p>Besides the <code>root</code>, each house has one and only one parent house. After a tour... | 337 | Medium | [
"The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root.\n\nBesides the root, each house has one and only one parent house. After a tour, the smart thief realized that all houses in this place form a binary tree. It will automatically contact the police ... | [
{
"hash": 7683361806749950000,
"runtime": "41ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def rob(self, root: Op... | # 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 rob(self, root):
"""
:type root: TreeNode
:rtype: int
""... | None | None | None | None | None | None | 54.1 | Level 3 | Hi |
graph-connectivity-with-threshold | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We have <code>n</code> cities labeled from <code>1</code> to <code>n</code>. Two different cities with labels <code>x</code> and <code>y</code> are directly connected by a bidirectional road if and only if <code>x</code> and <code... | 1627 | Hard | [
"We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More formally, cities with labels x and y have a road between them if there exists an integer z such that... | [
{
"hash": -6097982017144552000,
"runtime": "692ms",
"solution": "class Solution(object):\n def areConnected(self, n, threshold, queries):\n def find(parent, x):\n if parent[x] != x:\n parent[x] = find(parent, parent[x])\n return parent[x]\n\n def uni... | class Solution(object):
def areConnected(self, n, threshold, queries):
"""
:type n: int
:type threshold: int
:type queries: List[List[int]]
:rtype: List[bool]
"""
| None | None | None | None | None | None | 46.7 | Level 5 | Hi |
tallest-billboard | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.</p>\n\n<p>You are given a collection of <code>rods</c... | 956 | Hard | [
"You are installing a billboard and want it to have the largest height. The billboard will have two steel supports, one on each side. Each steel support must be an equal height.\n\nYou are given a collection of rods that can be welded together. For example, if you have rods of lengths 1, 2, and 3, you can weld them... | [
{
"hash": -8495728015246054000,
"runtime": "331ms",
"solution": "class Solution(object):\n def tallestBillboard(self, rods):\n \"\"\"\n :type rods: List[int]\n :rtype: int\n \"\"\"\n # Hashtable with differences between two rods as keys and value being the \n ... | class Solution(object):
def tallestBillboard(self, rods):
"""
:type rods: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 52.5 | Level 5 | Hi |
hand-of-straights | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size <code>groupSize</code>, and consists of <code>groupSize</code> consecutive cards.</p>\n\n<p>Given an integer array <code... | 846 | Medium | [
"Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards.\n\nGiven an integer array hand where hand[i] is the value written on the ith card and an integer groupSize, return true if she can rearrange the card... | [
{
"hash": -9168369263896307000,
"runtime": "283ms",
"solution": "class Solution(object):\n def isNStraightHand(self, hand, groupSize):\n \"\"\"\n :type hand: List[int]\n :type groupSize: int\n :rtype: bool\n \"\"\"\n count = 0\n heapq.heapify(hand)\n ... | class Solution(object):
def isNStraightHand(self, hand, groupSize):
"""
:type hand: List[int]
:type groupSize: int
:rtype: bool
"""
| None | None | None | None | None | None | 55.9 | Level 3 | Hi |
longest-arithmetic-subsequence | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array <code>nums</code> of integers, return <em>the length of the longest arithmetic subsequence in</em> <code>nums</code>.</p>\n\n<p><strong>Note</strong> that:</p>\n\n<ul>\n\t<li>A <strong>subsequence</strong> is an arr... | 1027 | Medium | [
"Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.\n\nNote that:\n\n\n\tA subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.\n\tA sequence seq is arithmetic if seq[i + 1]... | [
{
"hash": -163614221637620100,
"runtime": "757ms",
"solution": "class Solution:\n def longestArithSeqLength(self, nums: List[int]) -> int:\n \"\"\"\n bc nums[i] is bounded, for each possible num check if \n num, diff is in seen\n \"\"\"\n seen = defaultdict(Counter)... | class Solution(object):
def longestArithSeqLength(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 49 | Level 3 | Hi |
minimum-fuel-cost-to-report-to-the-capital | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> roads. The capita... | 2477 | Medium | [
"There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connect... | [
{
"hash": -3670538406546559500,
"runtime": "1598ms",
"solution": "class Solution(object):\n def minimumFuelCost(self, roads, seats):\n \"\"\"\n :type roads: List[List[int]]\n :type seats: int\n :rtype: int\n \"\"\"\n if not roads:\n return 0\n ... | class Solution(object):
def minimumFuelCost(self, roads, seats):
"""
:type roads: List[List[int]]
:type seats: int
:rtype: int
"""
| None | None | None | None | None | None | 65.5 | Level 2 | Hi |
range-sum-of-sorted-subarray-sums | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given the array <code>nums</code> consisting of <code>n</code> positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array... | 1508 | Medium | [
"You are given the array nums consisting of n positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of n * (n + 1) / 2 numbers.\n\nReturn the sum of the numbers from index left to index right (indexed from 1), ... | [
{
"hash": 5108483759193960000,
"runtime": "396ms",
"solution": "class Solution(object):\n def rangeSum(self, nums, n, left, right):\n MOD = 10**9 + 7\n subarray_sums = []\n \n for i in range(n):\n subarray_sum = 0\n for j in range(i, n):\n ... | class Solution(object):
def rangeSum(self, nums, n, left, right):
"""
:type nums: List[int]
:type n: int
:type left: int
:type right: int
:rtype: int
"""
| None | None | None | None | None | None | 58.5 | Level 3 | Hi |
all-elements-in-two-binary-search-trees | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two binary search trees <code>root1</code> and <code>root2</code>, return <em>a list containing all the integers from both trees sorted in <strong>ascending</strong> order</em>.</p>\n\n<p> </p>\n<p><strong class=\"examp... | 1305 | Medium | [
"Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.\n\n \nExample 1:\n\nInput: root1 = [2,1,4], root2 = [1,0,3]\nOutput: [0,1,1,2,3,4]\n\n\nExample 2:\n\nInput: root1 = [1,null,8], root2 = [8,1]\nOutput: [1,1,8,8]\n\n\n \nConstraints:\... | [
{
"hash": -4291048467563785700,
"runtime": "334ms",
"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 getAllElements(self, root1, root2):
"""
:type root1: TreeNode
:t... | None | None | None | None | None | None | 79.8 | Level 2 | Hi |
apply-operations-to-an-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of size <code>n</code> consisting of <strong>non-negative</strong> integers.</p>\n\n<p>You need to apply <code>n - 1</code> operations to this array where, in the ... | 2460 | Easy | [
"You are given a 0-indexed array nums of size n consisting of non-negative integers.\n\nYou need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith element of nums:\n\n\n\tIf nums[i] == nums[i + 1], then multiply nums[i] by 2 and set nums[i + 1] ... | [
{
"hash": -3271774623829584400,
"runtime": "47ms",
"solution": "class Solution(object):\n def applyOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n\n for i in range(len(nums)-1):\n if nums[i] == nums[i+1]:\n ... | class Solution(object):
def applyOperations(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 67.2 | Level 1 | Hi |
calculate-digit-sum-of-a-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code> consisting of digits and an integer <code>k</code>.</p>\n\n<p>A <strong>round</strong> can be completed if the length of <code>s</code> is greater than <code>k</code>. In one round, do the fol... | 2243 | Easy | [
"You are given a string s consisting of digits and an integer k.\n\nA round can be completed if the length of s is greater than k. In one round, do the following:\n\n\n\tDivide s into consecutive groups of size k such that the first k characters are in the first group, the next k characters are in the second group,... | [
{
"hash": -7886671783064324000,
"runtime": "4ms",
"solution": "class Solution(object):\n def digitSum(self, s, k):\n s = list(map(int, s))\n while len(s) > k:\n temp = []\n for i in range(0, len(s), k):\n x = sum(s[i:i+k])\n for j in str(x):\n... | class Solution(object):
def digitSum(self, s, k):
"""
:type s: str
:type k: int
:rtype: str
"""
| None | None | None | None | None | None | 65.9 | Level 1 | Hi |
number-of-common-factors | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two positive integers <code>a</code> and <code>b</code>, return <em>the number of <strong>common</strong> factors of </em><code>a</code><em> and </em><code>b</code>.</p>\n\n<p>An integer <code>x</code> is a <strong>common fa... | 2427 | Easy | [
"Given two positive integers a and b, return the number of common factors of a and b.\n\nAn integer x is a common factor of a and b if x divides both a and b.\n\n \nExample 1:\n\nInput: a = 12, b = 6\nOutput: 4\nExplanation: The common factors of 12 and 6 are 1, 2, 3, 6.\n\n\nExample 2:\n\nInput: a = 25, b = 30\nOu... | [
{
"hash": -4819974779562262000,
"runtime": "6ms",
"solution": "class Solution(object):\n def commonFactors(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"\n c=min(a,b)\n ci=0\n for i in range(1,c+1):\n if(a%... | class Solution(object):
def commonFactors(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
| None | None | None | None | None | None | 78.9 | Level 1 | Hi |
maximize-the-confusion-of-an-exam | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A teacher is writing a test with <code>n</code> true/false questions, with <code>'T'</code> denoting true and <code>'F'</code> denoting false. He wants to confuse the students by <strong>maximizing</strong> the num... | 2024 | Medium | [
"A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a row).\n\nYou are given a string answerKey, where answerKey[i] is th... | [
{
"hash": 902770295098128600,
"runtime": "174ms",
"solution": "class Solution(object):\n def maxConsecutiveAnswers(self, answerKey, k):\n \"\"\"\n :type answerKey: str\n :type k: int\n :rtype: int\n\n try sliding with T, then try sliding with F\n \"\"\"\n\n ... | class Solution(object):
def maxConsecutiveAnswers(self, answerKey, k):
"""
:type answerKey: str
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 67.1 | Level 2 | Hi |
counting-words-with-a-given-prefix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array of strings <code>words</code> and a string <code>pref</code>.</p>\n\n<p>Return <em>the number of strings in </em><code>words</code><em> that contain </em><code>pref</code><em> as a <strong>prefix</strong></e... | 2185 | Easy | [
"You are given an array of strings words and a string pref.\n\nReturn the number of strings in words that contain pref as a prefix.\n\nA prefix of a string s is any leading contiguous substring of s.\n\n \nExample 1:\n\nInput: words = [\"pay\",\"attention\",\"practice\",\"attend\"], pref = \"at\"\nOutput: 2\nExplan... | [
{
"hash": -9131851563562465000,
"runtime": "21ms",
"solution": "class Solution(object):\n def prefixCount(self, words, pref):\n n = len(pref)\n i = 0\n c = 0\n while i < len(words):\n m = words[i]\n r = m[0:n]\n if r == pref :\n ... | class Solution(object):
def prefixCount(self, words, pref):
"""
:type words: List[str]
:type pref: str
:rtype: int
"""
| None | None | None | None | None | None | 77.5 | Level 1 | Hi |
longest-ideal-subsequence | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code> consisting of lowercase letters and an integer <code>k</code>. We call a string <code>t</code> <strong>ideal</strong> if the following conditions are satisfied:</p>\n\n<ul>\n\t<li><code>t</cod... | 2370 | Medium | [
"You are given a string s consisting of lowercase letters and an integer k. We call a string t ideal if the following conditions are satisfied:\n\n\n\tt is a subsequence of the string s.\n\tThe absolute difference in the alphabet order of every two adjacent letters in t is less than or equal to k.\n\n\nReturn the l... | [
{
"hash": -6996700873372365000,
"runtime": "904ms",
"solution": "class Solution:\n def longestIdealString(self, s, k):\n n = len(s)\n dp = [0] * 26\n for i in range(n):\n max_dp = max(dp[j] for j in range(max(0, ord(s[i]) - ord('a') - k), min(26, ord(s[i]) - ord('a') +... | class Solution(object):
def longestIdealString(self, s, k):
"""
:type s: str
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 37.5 | Level 4 | Hi |
the-employee-that-worked-on-the-longest-task | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There are <code>n</code> employees, each with a unique id from <code>0</code> to <code>n - 1</code>.</p>\n\n<p>You are given a 2D integer array <code>logs</code> where <code>logs[i] = [id<sub>i</sub>, leaveTime<sub>i</sub>]</code>... | 2432 | Easy | [
"There are n employees, each with a unique id from 0 to n - 1.\n\nYou are given a 2D integer array logs where logs[i] = [idi, leaveTimei] where:\n\n\n\tidi is the id of the employee that worked on the ith task, and\n\tleaveTimei is the time at which the employee finished the ith task. All the values leaveTimei are ... | [
{
"hash": 8730565184072005000,
"runtime": "259ms",
"solution": "class Solution(object):\n def hardestWorker(self, n, logs):\n \"\"\"\n :type n: int\n :type logs: List[List[int]]\n :rtype: int\n \"\"\"\n\n maxx = logs[0][1]\n maxx_idx = logs[0][0]\n\n ... | class Solution(object):
def hardestWorker(self, n, logs):
"""
:type n: int
:type logs: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 49.4 | Level 1 | Hi |
check-if-matrix-is-x-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A square matrix is said to be an <strong>X-Matrix</strong> if <strong>both</strong> of the following conditions hold:</p>\n\n<ol>\n\t<li>All the elements in the diagonals of the matrix are <strong>non-zero</strong>.</li>\n\t<li>Al... | 2319 | Easy | [
"A square matrix is said to be an X-Matrix if both of the following conditions hold:\n\n\n\tAll the elements in the diagonals of the matrix are non-zero.\n\tAll other elements are 0.\n\n\nGiven a 2D integer array grid of size n x n representing a square matrix, return true if grid is an X-Matrix. Otherwise, return ... | [
{
"hash": -3107569129555312000,
"runtime": "217ms",
"solution": "class Solution(object):\n def checkXMatrix(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: bool\n \"\"\"\n for i in range(len(grid)):\n for j in range(len(grid[0])):\n ... | class Solution(object):
def checkXMatrix(self, grid):
"""
:type grid: List[List[int]]
:rtype: bool
"""
| None | None | None | None | None | None | 65.5 | Level 1 | Hi |
largest-number-after-mutating-substring | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>num</code>, which represents a large integer. You are also given a <strong>0-indexed</strong> integer array <code>change</code> of length <code>10</code> that maps each digit <code>0-9</code> to anothe... | 1946 | Medium | [
"You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d].\n\nYou may choose to mutate a single substring of num. To mutate a substring, replace each digit ... | [
{
"hash": -7116868076090135000,
"runtime": "612ms",
"solution": "class Solution(object):\n def maximumNumber(self, num, change):\n \"\"\"\n :type num: str\n :type change: List[int]\n :rtype: str\n \"\"\"\n out = \"\"\n\n flow = 0\n for i in rang... | class Solution(object):
def maximumNumber(self, num, change):
"""
:type num: str
:type change: List[int]
:rtype: str
"""
| None | None | None | None | None | None | 35.3 | Level 4 | Hi |
keys-and-rooms | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There are <code>n</code> rooms labeled from <code>0</code> to <code>n - 1</code> and all the rooms are locked except for room <code>0</code>. Your goal is to visit all the rooms. However, you cannot enter a locked room withou... | 841 | Medium | [
"There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.\n\nWhen you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unl... | [
{
"hash": -4692598747852772000,
"runtime": "75ms",
"solution": "class Solution:\n def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:\n q = collections.deque()\n r = [0] * len(rooms)\n r[0] = 1\n for k in rooms[0]:\n q.append(k)\n while q:\n ... | class Solution(object):
def canVisitAllRooms(self, rooms):
"""
:type rooms: List[List[int]]
:rtype: bool
"""
| None | None | None | None | None | None | 72.4 | Level 2 | Hi |
smallest-string-with-a-given-numeric-value | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The <strong>numeric value</strong> of a <strong>lowercase character</strong> is defined as its position <code>(1-indexed)</code> in the alphabet, so the numeric value of <code>a</code> is <code>1</code>, the numeric value of <code... | 1663 | Medium | [
"The numeric value of a lowercase character is defined as its position (1-indexed) in the alphabet, so the numeric value of a is 1, the numeric value of b is 2, the numeric value of c is 3, and so on.\n\nThe numeric value of a string consisting of lowercase characters is defined as the sum of its characters' numeri... | [
{
"hash": -5152617193406920000,
"runtime": "27ms",
"solution": "class Solution(object):\n def getSmallestString(self, n, k):\n '''\n :type n: int\n :type k: int\n :rtype: str\n '''\n if n == k: return n * 'a'\n a = (26 * n - k) // 25\n c = k - 2... | class Solution(object):
def getSmallestString(self, n, k):
"""
:type n: int
:type k: int
:rtype: str
"""
| None | None | None | None | None | None | 66.8 | Level 2 | Hi |
custom-sort-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two strings order and s. All the characters of <code>order</code> are <strong>unique</strong> and were sorted in some custom order previously.</p>\n\n<p>Permute the characters of <code>s</code> so that they match the... | 791 | Medium | [
"You are given two strings order and s. All the characters of order are unique and were sorted in some custom order previously.\n\nPermute the characters of s so that they match the order that order was sorted. More specifically, if a character x occurs before a character y in order, then x should occur before y in... | [
{
"hash": -4608522218546153000,
"runtime": "40ms",
"solution": "class Solution:\n def customSortString(self, order: str, s: str) -> str:\n \n # add all chars of s to a set\n\n # from the set remove all the chars that are in order, add them to a string out\n\n # combine out... | class Solution(object):
def customSortString(self, order, s):
"""
:type order: str
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 69.3 | Level 2 | Hi |
height-checker | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in <strong>non-decreasing order</strong> by height. Let this ordering be represented by the integer array <code>... | 1051 | Easy | [
"A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line.\n\nYou are given an integer ar... | [
{
"hash": 4191039473389830000,
"runtime": "49ms",
"solution": "class Solution:\n def heightChecker(self, heights: List[int]) -> int:\n expected = sorted(heights)\n c = 0\n for i in range(0, len(heights)):\n if heights[i] != expected[i]:\n c += 1\n ... | class Solution(object):
def heightChecker(self, heights):
"""
:type heights: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 76.2 | Level 1 | Hi |
sum-of-distances | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. There exists an array <code>arr</code> of length <code>nums.length</code>, where <code>arr[i]</code> is the sum of <code>|i - j|</code> over all <code>j</... | 2615 | Medium | [
"You are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] to be 0.\n\nReturn the array arr.\n\n \nExample 1:\n\nInput: nums = [1,3,1,1,2]\nOutput: [5,0,3,4,0... | [
{
"hash": 8505040815976867000,
"runtime": "640ms",
"solution": "class Solution(object):\n def distance(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n groups = collections.defaultdict(list)\n for i, num in enumerate(nums):\n ... | class Solution(object):
def distance(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 29.8 | Level 4 | Hi |
merge-two-2d-arrays-by-summing-values | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two <strong>2D</strong> integer arrays <code>nums1</code> and <code>nums2.</code></p>\n\n<ul>\n\t<li><code>nums1[i] = [id<sub>i</sub>, val<sub>i</sub>]</code> indicate that the number with the id <code>id<sub>i<... | 2570 | Easy | [
"You are given two 2D integer arrays nums1 and nums2.\n\n\n\tnums1[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.\n\tnums2[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.\n\n\nEach array contains unique ids and is sorted in ascending order b... | [
{
"hash": -7624574866203324000,
"runtime": "46ms",
"solution": "class Solution(object):\n def mergeArrays(self, nums1, nums2):\n i=0\n j=0\n l=[]\n while i<len(nums1) and j<len(nums2):\n if nums1[i][0]==nums2[j][0]:\n l=l+[[nums1[i][0],nums1[i][1]... | class Solution(object):
def mergeArrays(self, nums1, nums2):
"""
:type nums1: List[List[int]]
:type nums2: List[List[int]]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 73 | Level 1 | Hi |
optimal-partition-of-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code>, partition the string into one or more <strong>substrings</strong> such that the characters in each substring are <strong>unique</strong>. That is, no letter appears in a single substring more than <s... | 2405 | Medium | [
"Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once.\n\nReturn the minimum number of substrings in such a partition.\n\nNote that each character should belong to exactly one substri... | [
{
"hash": -3678626122970023400,
"runtime": "140ms",
"solution": "class Solution(object):\n def partitionString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n ans = 0\n i = 0\n while i < len(s):\n dic = set()\n while i ... | class Solution(object):
def partitionString(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 78.7 | Level 2 | Hi |
number-of-arithmetic-triplets | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong>, <strong>strictly increasing</strong> integer array <code>nums</code> and a positive integer <code>diff</code>. A triplet <code>(i, j, k)</code> is an <strong>arithmetic triplet</strong> ... | 2367 | Easy | [
"You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met:\n\n\n\ti < j < k,\n\tnums[j] - nums[i] == diff, and\n\tnums[k] - nums[j] == diff.\n\n\nReturn the number of unique arithmetic triplets.\n\... | [
{
"hash": 6010627531979971000,
"runtime": "1205ms",
"solution": "class Solution(object):\n def arithmeticTriplets(self, nums, diff):\n counter = 0\n for i in combinations(nums,3):\n if i[1] - i[0] == diff and i[2] - i[1] == diff:\n counter += 1\n return ... | class Solution(object):
def arithmeticTriplets(self, nums, diff):
"""
:type nums: List[int]
:type diff: int
:rtype: int
"""
| None | None | None | None | None | None | 83.5 | Level 1 | Hi |
find-good-days-to-rob-the-bank | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You and a gang of thieves are planning on robbing a bank. You are given a <strong>0-indexed</strong> integer array <code>security</code>, where <code>security[i]</code> is the number of guards on duty on the <code>i<sup>th</sup></... | 2100 | Medium | [
"You and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards on duty on the ith day. The days are numbered starting from 0. You are also given an integer time.\n\nThe ith day is a good day to rob the bank if:\n\n\n\tThere are ... | [
{
"hash": -5068802101688084000,
"runtime": "770ms",
"solution": "class Solution(object):\n def goodDaysToRobBank(self, security, time):\n \"\"\"\n :type security: List[int]\n :type time: int\n :rtype: List[int]\n \"\"\"\n N = len(security)\n dpLeft = [... | class Solution(object):
def goodDaysToRobBank(self, security, time):
"""
:type security: List[int]
:type time: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 49.3 | Level 3 | Hi |
max-increase-to-keep-city-skyline | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a city composed of <code>n x n</code> blocks, where each block contains a single building shaped like a vertical square prism. You are given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code>... | 807 | Medium | [
"There is a city composed of n x n blocks, where each block contains a single building shaped like a vertical square prism. You are given a 0-indexed n x n integer matrix grid where grid[r][c] represents the height of the building located in the block at row r and column c.\n\nA city's skyline is the outer contour ... | [
{
"hash": -556587919007975230,
"runtime": "37ms",
"solution": "class Solution(object):\n def maxIncreaseKeepingSkyline(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n #Take max of each row.\n row = [0]*len(grid)\n col = []\... | class Solution(object):
def maxIncreaseKeepingSkyline(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 86 | Level 2 | Hi |
jewels-and-stones | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You're given strings <code>jewels</code> representing the types of stones that are jewels, and <code>stones</code> representing the stones you have. Each character in <code>stones</code> is a type of stone you have. You want t... | 771 | Easy | [
"You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.\n\nLetters are case sensitive, so \"a\" is considered a different type o... | [
{
"hash": 291228165218092300,
"runtime": "46ms",
"solution": "class Solution:\n def numJewelsInStones(self, jewels: str, stones: str) -> int:\n count = 0\n\n jwel = list(jewels)\n ston = list(stones)\n\n for i in jwel:\n for j in ston:\n if i in j... | class Solution(object):
def numJewelsInStones(self, jewels, stones):
"""
:type jewels: str
:type stones: str
:rtype: int
"""
| None | None | None | None | None | None | 88.4 | Level 1 | Hi |
last-stone-weight-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array of integers <code>stones</code> where <code>stones[i]</code> is the weight of the <code>i<sup>th</sup></code> stone.</p>\n\n<p>We are playing a game with the stones. On each turn, we choose any two stones an... | 1049 | Medium | [
"You are given an array of integers stones where stones[i] is the weight of the ith stone.\n\nWe are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:\n\n\n\tIf x == y, both stones are des... | [
{
"hash": 5003798447643561000,
"runtime": "19ms",
"solution": "class Solution(object):\n# 难点:如何从题目抽出dp!!!! 懂得拆分!!!!\n# 有些情况nums=values:dp[i] = dp[i] or dp[i-stone]\n def lastStoneWeightII(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"\n tot... | class Solution(object):
def lastStoneWeightII(self, stones):
"""
:type stones: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 54.7 | Level 3 | Hi |
merge-strings-alternately | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two strings <code>word1</code> and <code>word2</code>. Merge the strings by adding letters in alternating order, starting with <code>word1</code>. If a string is longer than the other, append the additional letters o... | 1768 | Easy | [
"You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.\n\nReturn the merged string.\n\n \nExample 1:\n\nInput: word1 = \"abc\", word2 = \"pqr\"\n... | [
{
"hash": 8955289463961070000,
"runtime": "15ms",
"solution": "class Solution(object):\n def mergeAlternately(self, word1, word2):\n answ = \"\"\n i = 0\n while i <len(word1) and i<len(word2):\n answ += word1[i:i+1] + word2[i:i+1]\n i+=1\n return answ... | class Solution(object):
def mergeAlternately(self, word1, word2):
"""
:type word1: str
:type word2: str
:rtype: str
"""
| None | None | None | None | None | None | 79.1 | Level 1 | Hi |
find-players-with-zero-or-one-losses | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> i... | 2225 | Medium | [
"You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match.\n\nReturn a list answer of size 2 where:\n\n\n\tanswer[0] is a list of all players that have not lost any matches.\n\tanswer[1] is a list of all players that have lost ex... | [
{
"hash": 793191578916052900,
"runtime": "1379ms",
"solution": "class Solution(object):\n def findWinners(self, matches):\n \"\"\"\n :type matches: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"\n score = defaultdict(int)\n for m in matches:\n ... | class Solution(object):
def findWinners(self, matches):
"""
:type matches: List[List[int]]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 71 | Level 2 | Hi |
longest-common-subsequence | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p>\n\n<p>A <... | 1143 | Medium | [
"Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0.\n\nA subsequence 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 char... | [
{
"hash": 3014949898518936600,
"runtime": "1640ms",
"solution": "class Solution:\n def longestCommonSubsequence(self, text1: str, text2: str) -> int:\n m = len(text1)\n n = len(text2)\n\n # lcs[i][j] is the lcs of the string that ends at i and ends at j\n lcs = [[0] * n fo... | class Solution(object):
def longestCommonSubsequence(self, text1, text2):
"""
:type text1: str
:type text2: str
:rtype: int
"""
| None | None | None | None | None | None | 57.6 | Level 3 | Hi |
check-distances-between-same-letters | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> string <code>s</code> consisting of only lowercase English letters, where each letter in <code>s</code> appears <strong>exactly</strong> <strong>twice</strong>. You are also given a <stro... | 2399 | Easy | [
"You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.\n\nEach letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).\n\nIn a we... | [
{
"hash": -7995560060843313000,
"runtime": "29ms",
"solution": "class Solution(object):\n def checkDistances(self, s, distance):\n \"\"\"\n :type s: str\n :type distance: List[int]\n :rtype: bool\n \"\"\"\n flag=1\n alph=\"abcdefghijklmnopqrstuvwxyz\"\... | class Solution(object):
def checkDistances(self, s, distance):
"""
:type s: str
:type distance: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 70 | Level 1 | Hi |
car-pooling | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a car with <code>capacity</code> empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).</p>\n\n<p>You are given the integer <code>capacity</code> and an array <code>trips</code> where <cod... | 1094 | Medium | [
"There is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west).\n\nYou are given the integer capacity and an array trips where trips[i] = [numPassengersi, fromi, toi] indicates that the ith trip has numPassengersi passengers and the locations to pick them up and... | [
{
"hash": -8296697628597899000,
"runtime": "181ms",
"solution": "class Solution(object):\n def carPooling(self, trips, capacity):\n \"\"\"\n :type trips: List[List[int]]\n :type capacity: int\n :rtype: bool\n \"\"\"\n\n # find max trip\n the_max = 0\n ... | class Solution(object):
def carPooling(self, trips, capacity):
"""
:type trips: List[List[int]]
:type capacity: int
:rtype: bool
"""
| None | None | None | None | None | None | 56.2 | Level 3 | Hi |
matrix-block-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <code>m x n</code> matrix <code>mat</code> and an integer <code>k</code>, return <em>a matrix</em> <code>answer</code> <em>where each</em> <code>answer[i][j]</code> <em>is the sum of all elements</em> <code>mat[r][c]</code... | 1314 | Medium | [
"Given a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for:\n\n\n\ti - k <= r <= i + k,\n\tj - k <= c <= j + k, and\n\t(r, c) is a valid position in the matrix.\n\n\n \nExample 1:\n\nInput: mat = [[1,2,3],[4,5,6],[7,8,9]], k = 1\nOutput: [[12,... | [
{
"hash": -5840311446564682000,
"runtime": "4082ms",
"solution": "class Solution(object):\n def matrixBlockSum(self, mat, k):\n \"\"\"\n :type mat: List[List[int]]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"\n m=len(mat)\n n=len(mat[0])\n ... | class Solution(object):
def matrixBlockSum(self, mat, k):
"""
:type mat: List[List[int]]
:type k: int
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 75.5 | Level 2 | Hi |
linked-list-components | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given the <code>head</code> of a linked list containing unique integer values and an integer array <code>nums</code> that is a subset of the linked list values.</p>\n\n<p>Return <em>the number of connected components in </... | 817 | Medium | [
"You are given the head of a linked list containing unique integer values and an integer array nums that is a subset of the linked list values.\n\nReturn the number of connected components in nums where two values are connected if they appear consecutively in the linked list.\n\n \nExample 1:\n\nInput: head = [0,1,... | [
{
"hash": -9001997995519630000,
"runtime": "1461ms",
"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 numComponents(self, head, nums):\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 numComponents(self, head, nums):
"""
:type head: ListNode
:type nums: List[int]
:rtype: int
... | None | None | None | None | None | None | 57.1 | Level 3 | Hi |
make-array-zero-by-subtracting-equal-amounts | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a non-negative integer array <code>nums</code>. In one operation, you must:</p>\n\n<ul>\n\t<li>Choose a positive integer <code>x</code> such that <code>x</code> is less than or equal to the <strong>smallest non-zero<... | 2357 | Easy | [
"You are given a non-negative integer array nums. In one operation, you must:\n\n\n\tChoose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.\n\tSubtract x from every positive element in nums.\n\n\nReturn the minimum number of operations to make every element in nums e... | [
{
"hash": 7069182247215031000,
"runtime": "47ms",
"solution": "class Solution(object):\n def minimumOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n if sum(nums) == 0:\n return 0\n ops = 0\n while sum(nums) !... | class Solution(object):
def minimumOperations(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 72 | Level 1 | Hi |
increasing-order-search-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a binary search tree, rearrange the tree in <strong>in-order</strong> so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.</p>... | 897 | Easy | [
"Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child.\n\n \nExample 1:\n\nInput: root = [5,3,6,2,4,null,8,1,null,null,null,7,9]\nOutput: [1,null,2,null,3,null,4,null,5,null... | [
{
"hash": 5082592022310286000,
"runtime": "44ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# self.val = val\n# self.left = left\n# self.right = right\nclass Solution:\n def increasingBST(self... | # 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 increasingBST(self, root):
"""
:type root: TreeNode
:rtype: Tree... | None | None | None | None | None | None | 78.3 | Level 1 | Hi |
egg-drop-with-2-eggs-and-n-floors | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given <strong>two identical</strong> eggs and you have access to a building with <code>n</code> floors labeled from <code>1</code> to <code>n</code>.</p>\n\n<p>You know that there exists a floor <code>f</code> where <code>... | 1884 | Medium | [
"You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.\n\nYou know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.\n\nIn each move, you may take an unb... | [
{
"hash": 29041080326147264,
"runtime": "10ms",
"solution": "class Solution(object):\n def twoEggDrop(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n k=0.5*((8*n+1)**0.5-1)\n if int(k)!=k:\n k=int(k)+1\n else:\n k=int(k... | class Solution(object):
def twoEggDrop(self, n):
"""
:type n: int
:rtype: int
"""
| None | None | None | None | None | None | 72.3 | Level 2 | Hi |
find-the-most-competitive-subsequence | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code> and a positive integer <code>k</code>, return <em>the most<strong> competitive</strong> subsequence of </em><code>nums</code> <em>of size </em><code>k</code>.</p>\n\n<p>An array's subse... | 1673 | Medium | [
"Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.\n\nAn array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.\n\nWe define that a subsequence a is more competitive than a subsequence b (of the sam... | [
{
"hash": -7153054442849407000,
"runtime": "1010ms",
"solution": "class Solution(object):\n def mostCompetitive(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"\n res = []\n for i in range(len(nums)):\n ... | class Solution(object):
def mostCompetitive(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 49.8 | Level 3 | Hi |
defuse-the-bomb | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You have a bomb to defuse, and your time is running out! Your informer will provide you with a <strong>circular</strong> array <code>code</code> of length of <code>n</code> and a key <code>k</code>.</p>\n\n<p>To decrypt ... | 1652 | Easy | [
"You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k.\n\nTo decrypt the code, you must replace every number. All the numbers are replaced simultaneously.\n\n\n\tIf k > 0, replace the ith number with the sum of the next k numbe... | [
{
"hash": 188146654796517220,
"runtime": "18ms",
"solution": "class Solution(object):\n def decrypt(self, code, k):\n \"\"\"\n :type code: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"\n ans, sum, isNegative = [0] * len(code), 0, k < 0\n if isN... | class Solution(object):
def decrypt(self, code, k):
"""
:type code: List[int]
:type k: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 63.7 | Level 1 | Hi |
restore-the-array-from-adjacent-pairs | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is an integer array <code>nums</code> that consists of <code>n</code> <strong>unique </strong>elements, but you have forgotten it. However, you do remember every pair of adjacent elements in <code>nums</code>.</p>\n\n<p>You ... | 1743 | Medium | [
"There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.\n\nYou are given a 2D integer array adjacentPairs of size n - 1 where each adjacentPairs[i] = [ui, vi] indicates that the elements ui and vi are adjacent i... | [
{
"hash": 8000936493298006000,
"runtime": "793ms",
"solution": "class Solution(object):\n def restoreArray(self, adjacentPairs):\n \"\"\"\n :type adjacentPairs: List[List[int]]\n :rtype: List[int]\n \"\"\"\n pairs = defaultdict(list)\n\n for val in adjacentPa... | class Solution(object):
def restoreArray(self, adjacentPairs):
"""
:type adjacentPairs: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 75.2 | Level 2 | Hi |
add-two-integers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "Given two integers <code>num1</code> and <code>num2</code>, return <em>the <strong>sum</strong> of the two integers</em>.\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> num1 = 1... | 2235 | Easy | [
"Given two integers num1 and num2, return the sum of the two integers.\n \nExample 1:\n\nInput: num1 = 12, num2 = 5\nOutput: 17\nExplanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.\n\n\nExample 2:\n\nInput: num1 = -10, num2 = 4\nOutput: -6\nExplanation: num1 + num2 = -6, so -6 is re... | [
{
"hash": 865541501504515200,
"runtime": "10ms",
"solution": "class Solution(object):\n def sum(self, num1, num2):\n return num1+num2\n "
},
{
"hash": -8763117323288306000,
"runtime": "6ms",
"solution": "class Solution(object):\n def sum(self, num1, num2):\n re... | class Solution(object):
def sum(self, num1, num2):
"""
:type num1: int
:type num2: int
:rtype: int
"""
| None | None | None | None | None | None | 87.2 | Level 1 | Hi |
distribute-candies | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Alice has <code>n</code> candies, where the <code>i<sup>th</sup></code> candy is of type <code>candyType[i]</code>. Alice noticed that she started to gain weight, so she visited a doctor.</p>\n\n<p>The doctor advised Alice to only... | 575 | Easy | [
"Alice has n candies, where the ith candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor.\n\nThe doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different ... | [
{
"hash": 4378270589156863000,
"runtime": "590ms",
"solution": "class Solution(object):\n def distributeCandies(self, candyType):\n number_of_allowed_candies = len(candyType) / 2\n unique_types = set(candyType)\n if len(unique_types) <= number_of_allowed_candies:\n ret... | class Solution(object):
def distributeCandies(self, candyType):
"""
:type candyType: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 67.1 | Level 1 | Hi |
number-of-ways-to-earn-points | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a test that has <code>n</code> types of questions. You are given an integer <code>target</code> and a <strong>0-indexed</strong> 2D integer array <code>types</code> where <code>types[i] = [count<sub>i</sub>, marks<sub>i</... | 2585 | Hard | [
"There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the ith type, and each one of them is worth marksi points.\n\n\n\n\nReturn the number of ways you can earn exactly tar... | [
{
"hash": 4801346697563389000,
"runtime": "1171ms",
"solution": "class Solution(object):\n def waysToReachTarget(self, target, types):\n \"\"\"\n :type target: int\n :type types: List[List[int]]\n :rtype: int\n \"\"\"\n dp = [0 for _ in range(target+1)]\n ... | class Solution(object):
def waysToReachTarget(self, target, types):
"""
:type target: int
:type types: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 57.2 | Level 5 | Hi |
maximum-number-of-achievable-transfer-requests | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We have <code>n</code> buildings numbered from <code>0</code> to <code>n - 1</code>. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.</p>\n\n<p>You a... | 1601 | Hard | [
"We have n buildings numbered from 0 to n - 1. Each building has a number of employees. It's transfer season, and some employees want to change the building they reside in.\n\nYou are given an array requests where requests[i] = [fromi, toi] represents an employee's request to transfer from building fromi to buildin... | [
{
"hash": -6941437217382128000,
"runtime": "2038ms",
"solution": "class Solution(object):\n def maximumRequests(self, n, requests):\n path = []\n res = []\n max_request = [-float('inf')]\n self.help(path, res, requests, 0, max_request)\n return max_request[0] if max... | class Solution(object):
def maximumRequests(self, n, requests):
"""
:type n: int
:type requests: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 64.7 | Level 5 | Hi |
replace-elements-in-an-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> that consists of <code>n</code> <strong>distinct</strong> positive integers. Apply <code>m</code> operations to this array, where in the <code>i<sup>th</sup></code... | 2295 | Medium | [
"You are given a 0-indexed array nums that consists of n distinct positive integers. Apply m operations to this array, where in the ith operation you replace the number operations[i][0] with operations[i][1].\n\nIt is guaranteed that in the ith operation:\n\n\n\toperations[i][0] exists in nums.\n\toperations[i][1] ... | [
{
"hash": -44930763259984056,
"runtime": "1000ms",
"solution": "class Solution(object):\n def arrayChange(self, nums, operations):\n replacements = {}\n for x, y in reversed(operations):\n replacements[x] = replacements.get(y, y)\n for idx, val in enumerate(nums):\n ... | class Solution(object):
def arrayChange(self, nums, operations):
"""
:type nums: List[int]
:type operations: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 57.8 | Level 3 | Hi |
minimum-seconds-to-equalize-a-circular-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> containing <code>n</code> integers.</p>\n\n<p>At each second, you perform the following operation on the array:</p>\n\n<ul>\n\t<li>For every index <code>i</code> i... | 2808 | Medium | [
"You are given a 0-indexed array nums containing n integers.\n\nAt each second, you perform the following operation on the array:\n\n\n\tFor every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].\n\n\nNote that all the elements get replaced simultane... | [
{
"hash": -8404265322990259000,
"runtime": "744ms",
"solution": "class Solution(object):\n def minimumSeconds(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n # nums = []\n nums = nums + nums\n d = {}\n dp = {}\n for... | class Solution(object):
def minimumSeconds(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 25.8 | Level 4 | Hi |
remove-one-element-to-make-the-array-strictly-increasing | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, return <code>true</code> <em>if it can be made <strong>strictly increasing</strong> after removing <strong>exactly one</strong> element, or </em><code>false</code... | 1909 | Easy | [
"Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true.\n\nThe array nums is strictly increasing if nums[i - 1] < nums[i] for each index (1 <= i < nums.length).\n\n \nEx... | [
{
"hash": -5729256607790937000,
"runtime": "33ms",
"solution": "class Solution(object):\n def canBeIncreasing(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n len_nums = len(nums)\n\n n_probs = 0\n for i in range(1, len_nums):\n ... | class Solution(object):
def canBeIncreasing(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 26.9 | Level 1 | Hi |
separate-black-and-white-balls | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There are <code>n</code> balls on a table, each ball has a color black or white.</p>\n\n<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code>, where <code>1</code> and <code>0</code> r... | 2938 | Medium | [
"There are n balls on a table, each ball has a color black or white.\n\nYou are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.\n\nIn each step, you can choose two adjacent balls and swap them.\n\nReturn the minimum number of steps to group all the black b... | [
{
"hash": -972501022684514400,
"runtime": "140ms",
"solution": "class Solution(object):\n def minimumSteps(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n zero = 0\n \n total = 0\n for c in s:\n if c == '0':\n ... | class Solution(object):
def minimumSteps(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 51.6 | Level 3 | Hi |
split-strings-by-separator | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of strings <code>words</code> and a character <code>separator</code>, <strong>split</strong> each string in <code>words</code> by <code>separator</code>.</p>\n\n<p>Return <em>an array of strings containing the new s... | 2788 | Easy | [
"Given an array of strings words and a character separator, split each string in words by separator.\n\nReturn an array of strings containing the new strings formed after the splits, excluding empty strings.\n\nNotes\n\n\n\tseparator is used to determine where the split should occur, but it is not included as part ... | [
{
"hash": -6014376072540842000,
"runtime": "55ms",
"solution": "class Solution(object):\n def splitWordsBySeparator(self, words, separator):\n \"\"\"\n :type words: List[str]\n :type separator: str\n :rtype: List[str]\n \"\"\"\n result = []\n for word ... | class Solution(object):
def splitWordsBySeparator(self, words, separator):
"""
:type words: List[str]
:type separator: str
:rtype: List[str]
"""
| None | None | None | None | None | None | 72 | Level 1 | Hi |
best-time-to-buy-and-sell-stock-with-transaction-fee | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array <code>prices</code> where <code>prices[i]</code> is the price of a given stock on the <code>i<sup>th</sup></code> day, and an integer <code>fee</code> representing a transaction fee.</p>\n\n<p>Find the maxim... | 714 | Medium | [
"You are given an array prices where prices[i] is the price of a given stock on the ith day, and an integer fee representing a transaction fee.\n\nFind the maximum profit you can achieve. You may complete as many transactions as you like, but you need to pay the transaction fee for each transaction.\n\nNote:\n\n\n\... | [
{
"hash": 1806327318793220600,
"runtime": "560ms",
"solution": "class Solution:\n def maxProfit(self, prices: List[int], fee: int) -> int:\n buy = -math.inf\n sell = 0\n for price in prices:\n buy = max(buy, sell-price)\n sell = max(sell, buy+price-fee)\n\n ... | class Solution(object):
def maxProfit(self, prices, fee):
"""
:type prices: List[int]
:type fee: int
:rtype: int
"""
| None | None | None | None | None | None | 68.2 | Level 2 | Hi |
longest-nice-substring | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A string <code>s</code> is <strong>nice</strong> if, for every letter of the alphabet that <code>s</code> contains, it appears <strong>both</strong> in uppercase and lowercase. For example, <code>"abABB"</code> is nice b... | 1763 | Easy | [
"A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, \"abABB\" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, \"abA\" is not because 'b' appears, but 'B' does not.\n\nGiven a string s, return the longest substring of... | [
{
"hash": -2835238909225906700,
"runtime": "382ms",
"solution": "class Solution(object):\n def longestNiceSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n hash = {}\n longest = \"\"\n for i in range(len(s)):\n hash[s[i]] ... | class Solution(object):
def longestNiceSubstring(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 60.6 | Level 1 | Hi |
minimum-time-to-type-word-using-special-typewriter | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a special typewriter with lowercase English letters <code>'a'</code> to <code>'z'</code> arranged in a <strong>circle</strong> with a <strong>pointer</strong>. A character can <strong>only</strong> be type... | 1974 | Easy | [
"There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'.\n\nEach second, you may perform one of the following operations:\n\n\n\tMo... | [
{
"hash": -3947170291768427000,
"runtime": "18ms",
"solution": "class Solution(object):\n def minTimeToType(self, w):\n \"\"\"\n :type word: str\n :rtype: int\n \"\"\"\n res = min(ord(w[0]) - ord('a'), 26 - (ord(w[0]) - ord('a')))\n for i in range(1, len(w)):... | class Solution(object):
def minTimeToType(self, word):
"""
:type word: str
:rtype: int
"""
| None | None | None | None | None | None | 74.1 | Level 1 | Hi |
maximum-number-of-events-that-can-be-attended-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array of <code>events</code> where <code>events[i] = [startDay<sub>i</sub>, endDay<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startDay<sub>i</sub></code><sub> </s... | 1751 | Hard | [
"You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an integer k which represents the maximum number of events you can attend.\n\nYou can only att... | [
{
"hash": -2707960128863457300,
"runtime": "1658ms",
"solution": "class Solution(object):\n def search(self,i,arr):\n lo=i\n hi=len(arr)-1\n ans=-1\n while lo<=hi:\n m=lo+(hi-lo)//2\n if arr[m][0]>arr[i-1][1]:\n ans=m\n h... | class Solution(object):
def maxValue(self, events, k):
"""
:type events: List[List[int]]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 62.6 | Level 5 | Hi |
minimum-array-length-after-pair-removals | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> <strong>sorted</strong> array of integers <code>nums</code>.</p>\n\n<p>You can perform the following operation any number of times:</p>\n\n<ul>\n\t<li>Choose <strong>two</strong> indices,... | 2856 | Medium | [
"You are given a 0-indexed sorted array of integers nums.\n\nYou can perform the following operation any number of times:\n\n\n\tChoose two indices, i and j, where i < j, such that nums[i] < nums[j].\n\tThen, remove the elements at indices i and j from nums. The remaining elements retain their original order, and t... | [
{
"hash": 4285571597456275500,
"runtime": "1043ms",
"solution": "class Solution(object):\n def minLengthAfterRemovals(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n\n dictNums = {}\n\n for i in nums:\n if i in dictNums:\n ... | class Solution(object):
def minLengthAfterRemovals(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 20.6 | Level 4 | Hi |
champagne-tower | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We stack glasses in a pyramid, where the <strong>first</strong> row has <code>1</code> glass, the <strong>second</strong> row has <code>2</code> glasses, and so on until the 100<sup>th</sup> row. Each glass holds one cup&nbs... | 799 | Medium | [
"We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup of champagne.\n\nThen, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to the ... | [
{
"hash": 1206367592797626000,
"runtime": "65ms",
"solution": "class Solution(object):\n def champagneTower(self, poured, query_row, query_glass):\n A = [[0] * k for k in xrange(1, 102)]\n A[0][0] = poured\n for r in xrange(query_row + 1):\n for c in xrange(r+1):\n ... | class Solution(object):
def champagneTower(self, poured, query_row, query_glass):
"""
:type poured: int
:type query_row: int
:type query_glass: int
:rtype: float
"""
| None | None | None | None | None | None | 58 | Level 3 | Hi |
different-ways-to-add-parentheses | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>expression</code> of numbers and operators, return <em>all possible results from computing all the different possible ways to group numbers and operators</em>. You may return the answer in <strong>any order</s... | 241 | Medium | [
"Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.\n\nThe test cases are generated such that the output values fit in a 32-bit integer and the number of different resu... | [
{
"hash": 4692693033531120000,
"runtime": "38ms",
"solution": "class Solution(object):\n def diffWaysToCompute(self, input):\n m = {}\n return self.dfs(input, m)\n \n def dfs(self, input, m):\n if input in m:\n return m[input]\n if input.isdigit():\n ... | class Solution(object):
def diffWaysToCompute(self, expression):
"""
:type expression: str
:rtype: List[int]
"""
| None | None | None | None | None | None | 64.9 | Level 2 | Hi |
maximum-depth-of-n-ary-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a n-ary tree, find its maximum depth.</p>\n\n<p>The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.</p>\n\n<p><em>Nary-Tree input serialization is represented in... | 559 | Easy | [
"Given a n-ary tree, find its maximum depth.\n\nThe maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.\n\nNary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples).\n\n... | [
{
"hash": -7133938687870402000,
"runtime": "34ms",
"solution": "\"\"\"\n# Definition for a Node.\nclass Node:\n def __init__(self, val=None, children=None):\n self.val = val\n self.children = children\n\"\"\"\n\nclass Solution:\n def maxDepth(self, root: 'Node') -> int:\n if n... | """
# Definition for a Node.
class Node(object):
def __init__(self, val=None, children=None):
self.val = val
self.children = children
"""
class Solution(object):
def maxDepth(self, root):
"""
:type root: Node
:rtype: int
"""
| None | None | None | None | None | None | 71.9 | Level 1 | Hi |
minimum-cost-to-make-all-characters-equal | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> binary string <code>s</code> of length <code>n</code> on which you can apply two types of operations:</p>\n\n<ul>\n\t<li>Choose an index <code>i</code> and invert all characters from ... | 2712 | Medium | [
"You are given a 0-indexed binary string s of length n on which you can apply two types of operations:\n\n\n\tChoose an index i and invert all characters from index 0 to index i (both inclusive), with a cost of i + 1\n\tChoose an index i and invert all characters from index i to index n - 1 (both inclusive), with a... | [
{
"hash": -5950273766902277000,
"runtime": "132ms",
"solution": "class Solution(object):\n def minimumCost(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n return sum(min(i, len(s)-i) for i in range(1, len(s)) if s[i]!=s[i-1])"
},
{
"hash": 2562991... | class Solution(object):
def minimumCost(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 53.5 | Level 3 | Hi |
maximum-total-importance-of-roads | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer <code>n</code> denoting the number of cities in a country. The cities are numbered from <code>0</code> to <code>n - 1</code>.</p>\n\n<p>You are also given a 2D integer array <code>roads</code> where <code>... | 2285 | Medium | [
"You are given an integer n denoting the number of cities in a country. The cities are numbered from 0 to n - 1.\n\nYou are also given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.\n\nYou need to assign each city with an integer value ... | [
{
"hash": 5771947635767775000,
"runtime": "1120ms",
"solution": "class Solution(object):\n def maximumImportance(self, n, roads):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :rtype: int\n \"\"\"\n Arr = [0] * n # i-th city has Arr[i] roads\n ... | class Solution(object):
def maximumImportance(self, n, roads):
"""
:type n: int
:type roads: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 60.9 | Level 2 | Hi |
detect-pattern-of-length-m-repeated-k-or-more-times | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of positive integers <code>arr</code>, find a pattern of length <code>m</code> that is repeated <code>k</code> or more times.</p>\n\n<p>A <strong>pattern</strong> is a subarray (consecutive sub-sequence) that consis... | 1566 | Easy | [
"Given an array of positive integers arr, find a pattern of length m that is repeated k or more times.\n\nA pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times consecutively without overlapping. A pattern is defined by its length and the number of repetition... | [
{
"hash": -1420915289375668700,
"runtime": "19ms",
"solution": "class Solution(object):\n def containsPattern(self, arr, m, k) :\n streak = 0\n for i in range(len(arr)-m):\n streak = streak + 1 if arr[i] == arr[i+m] else 0\n if streak == (k-1)*m: return True\n ... | class Solution(object):
def containsPattern(self, arr, m, k):
"""
:type arr: List[int]
:type m: int
:type k: int
:rtype: bool
"""
| None | None | None | None | None | None | 43.2 | Level 1 | Hi |
insert-greatest-common-divisors-in-linked-list | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the head of a linked list <code>head</code>, in which each node contains an integer value.</p>\n\n<p>Between every pair of adjacent nodes, insert a new node with a value equal to the <strong>greatest common divisor</strong> ... | 2807 | Medium | [
"Given the head of a linked list head, in which each node contains an integer value.\n\nBetween every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.\n\nReturn the linked list after insertion.\n\nThe greatest common divisor of two numbers is the largest positive ... | [
{
"hash": 8392360063369017000,
"runtime": "250ms",
"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 insertGreatestCommonDivisors(self, head):\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 insertGreatestCommonDivisors(self, head):
"""
:type head: Optional[ListNode]
:rtype: Optional[ListNode]
... | None | None | None | None | None | None | 88.4 | Level 2 | Hi |
points-that-intersect-with-cars | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> 2D integer array <code>nums</code> representing the coordinates of the cars parking on a number line. For any index <code>i</code>, <code>nums[i] = [start<sub>i</sub>, end<sub>i</sub>]</c... | 2848 | Easy | [
"You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi is the ending point of the ith car.\n\nReturn the number of integer points on the line that are cov... | [
{
"hash": 3557017141291623000,
"runtime": "84ms",
"solution": "class Solution(object):\n def numberOfPoints(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: int\n \"\"\"\n ans = []\n cnt = 0\n for i in nums:\n st = i[0]\n ... | class Solution(object):
def numberOfPoints(self, nums):
"""
:type nums: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 74.5 | Level 1 | Hi |
toeplitz-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an <code>m x n</code> <code>matrix</code>, return <em><code>true</code> if the matrix is Toeplitz. Otherwise, return <code>false</code>.</em></p>\n\n<p>A matrix is <strong>Toeplitz</strong> if every diagonal from t... | 766 | Easy | [
"Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.\n\nA matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.\n\n \nExample 1:\n\nInput: matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]\nOutput: true\nExplanation:\nIn the above grid, the diagonals are... | [
{
"hash": -8659556776090270000,
"runtime": "52ms",
"solution": "class Solution(object):\n def isToeplitzMatrix(self, matrix):\n # Iterate through each element in the matrix starting from the second row and second column\n for i in range(1, len(matrix)):\n for j in range(1, le... | class Solution(object):
def isToeplitzMatrix(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: bool
"""
| None | None | None | None | None | None | 68.6 | Level 1 | Hi |
number-of-strings-which-can-be-rearranged-to-contain-substring | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer <code>n</code>.</p>\n\n<p>A string <code>s</code> is called <strong>good </strong>if it contains only lowercase English characters <strong>and</strong> it is possible to rearrange the characters of <code>s... | 2930 | Medium | [
"You are given an integer n.\n\nA string s is called good if it contains only lowercase English characters and it is possible to rearrange the characters of s such that the new string contains \"leet\" as a substring.\n\nFor example:\n\n\n\tThe string \"lteer\" is good because we can rearrange it to form \"leetr\" ... | [
{
"hash": -3722111212917174300,
"runtime": "1006ms",
"solution": "\nclass Solution(object):\n def stringCount(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n M = 10**9 + 7\n dp = [[0 for _ in range(12)] for _ in range(n+1)]\n dp[-1][0] = 1\n... | class Solution(object):
def stringCount(self, n):
"""
:type n: int
:rtype: int
"""
| None | None | None | None | None | None | 54.2 | Level 3 | Hi |
find-k-closest-elements | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <strong>sorted</strong> integer array <code>arr</code>, two integers <code>k</code> and <code>x</code>, return the <code>k</code> closest integers to <code>x</code> in the array. The result should also be sorted in ascendi... | 658 | Medium | [
"Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order.\n\nAn integer a is closer to x than an integer b if:\n\n\n\t|a - x| < |b - x|, or\n\t|a - x| == |b - x| and a < b\n\n\n \nExample 1:\nInput: arr = [1,2,3,4,5... | [
{
"hash": 1209826262627298800,
"runtime": "299ms",
"solution": "import heapq \n\nclass Solution(object):\n def findClosestElements(self, arr, k, x):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :type x: int\n :rtype: List[int]\n \"\"\"\n arr = [ [ ... | class Solution(object):
def findClosestElements(self, arr, k, x):
"""
:type arr: List[int]
:type k: int
:type x: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 47 | Level 3 | Hi |
delete-node-in-a-linked-list | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a singly-linked list <code>head</code> and we want to delete a node <code>node</code> in it.</p>\n\n<p>You are given the node to be deleted <code>node</code>. You will <strong>not be given access</strong> to the first nod... | 237 | Medium | [
"There is a singly-linked list head and we want to delete a node node in it.\n\nYou are given the node to be deleted node. You will not be given access to the first node of head.\n\nAll the values of the linked list are unique, and it is guaranteed that the given node node is not the last node in the linked list.\n... | [
{
"hash": 5329725181367876000,
"runtime": "42ms",
"solution": "# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, x):\n# self.val = x\n# self.next = None\n\nclass Solution:\n def deleteNode(self, node):\n \"\"\"\n :type node: ListNode\n ... | # Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def deleteNode(self, node):
"""
:type node: ListNode
:rtype: void Do not return anything, modify node in-place instead.
... | None | None | None | None | None | None | 77.6 | Level 2 | Hi |
find-largest-value-in-each-tree-row | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a binary tree, return <em>an array of the largest value in each row</em> of the tree <strong>(0-indexed)</strong>.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n<img alt... | 515 | Medium | [
"Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed).\n\n \nExample 1:\n\nInput: root = [1,3,2,5,3,null,9]\nOutput: [1,3,9]\n\n\nExample 2:\n\nInput: root = [1,2,3]\nOutput: [1,3]\n\n\n \nConstraints:\n\n\n\tThe number of nodes in the tree will be in the range [... | [
{
"hash": -4255469853386005500,
"runtime": "26ms",
"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 l... | # 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 largestValues(self, root):
"""
:type root: TreeNode
:rtype: List... | None | None | None | None | None | None | 65.6 | Level 2 | Hi |
cells-in-a-range-on-an-excel-sheet | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A cell <code>(r, c)</code> of an excel sheet is represented as a string <code>"<col><row>"</code> where:</p>\n\n<ul>\n\t<li><code><col></code> denotes the column number <code>c</code> of the cell. It is... | 2194 | Easy | [
"A cell (r, c) of an excel sheet is represented as a string \"<col><row>\" where:\n\n\n\t<col> denotes the column number c of the cell. It is represented by alphabetical letters.\n\n\t\n\t\tFor example, the 1st column is denoted by 'A', the 2nd by 'B', the 3rd by 'C', and so on.\n\t\n\t\n\t<row> is the row number r... | [
{
"hash": -30313813545421530,
"runtime": "15ms",
"solution": "class Solution(object):\n def cellsInRange(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"\n rList = []\n \n for i in range(ord(s[0]), ord(s[3])+1):\n for j in range(... | class Solution(object):
def cellsInRange(self, s):
"""
:type s: str
:rtype: List[str]
"""
| None | None | None | None | None | None | 83.9 | Level 1 | Hi |
divide-intervals-into-minimum-number-of-groups | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a 2D integer array <code>intervals</code> where <code>intervals[i] = [left<sub>i</sub>, right<sub>i</sub>]</code> represents the <strong>inclusive</strong> interval <code>[left<sub>i</sub>, right<sub>i</sub>]</code>.... | 2406 | Medium | [
"You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].\n\nYou have to divide the intervals into one or more groups such that each interval is in exactly one group, and no two intervals that are in the same group intersect each other.\n\nRe... | [
{
"hash": -2481002464639786500,
"runtime": "1279ms",
"solution": "import heapq\n\nclass Solution(object):\n def minGroups(self, intervals):\n \"\"\"\n :type intervals: List[List[int]]\n :rtype: int\n \"\"\"\n start_times = [item[0] for item in intervals]\n en... | class Solution(object):
def minGroups(self, intervals):
"""
:type intervals: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 46.5 | Level 4 | Hi |
print-binary-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a binary tree, construct a <strong>0-indexed</strong> <code>m x n</code> string matrix <code>res</code> that represents a <strong>formatted layout</strong> of the tree. The formatted layout matrix sh... | 655 | Medium | [
"Given the root of a binary tree, construct a 0-indexed m x n string matrix res that represents a formatted layout of the tree. The formatted layout matrix should be constructed using the following rules:\n\n\n\tThe height of the tree is height and the number of rows m should be equal to height + 1.\n\tThe number o... | [
{
"hash": 4563090143597374500,
"runtime": "12ms",
"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 pr... | # 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 printTree(self, root):
"""
:type root: TreeNode
:rtype: List[Lis... | None | None | None | None | None | None | 62.8 | Level 2 | Hi |
map-of-highest-peak | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer matrix <code>isWater</code> of size <code>m x n</code> that represents a map of <strong>land</strong> and <strong>water</strong> cells.</p>\n\n<ul>\n\t<li>If <code>isWater[i][j] == 0</code>, cell <code>(i,... | 1765 | Medium | [
"You are given an integer matrix isWater of size m x n that represents a map of land and water cells.\n\n\n\tIf isWater[i][j] == 0, cell (i, j) is a land cell.\n\tIf isWater[i][j] == 1, cell (i, j) is a water cell.\n\n\nYou must assign each cell a height in a way that follows these rules:\n\n\n\tThe height of each ... | [
{
"hash": 646649195629280300,
"runtime": "2994ms",
"solution": "class Solution(object):\n def highestPeak(self, isWater):\n \"\"\"\n :type isWater: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"\n def bfs(i,j,z):\n if 0<=i<len(isWater) and 0<=j<len(is... | class Solution(object):
def highestPeak(self, isWater):
"""
:type isWater: List[List[int]]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 61.3 | Level 2 | Hi |
maximum-number-of-fish-in-a-grid | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> 2D matrix <code>grid</code> of size <code>m x n</code>, where <code>(r, c)</code> represents:</p>\n\n<ul>\n\t<li>A <strong>land</strong> cell if <code>grid[r][c] = 0</code>, or</li>\n\t<l... | 2658 | Medium | [
"You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents:\n\n\n\tA land cell if grid[r][c] = 0, or\n\tA water cell containing grid[r][c] fish, if grid[r][c] > 0.\n\n\nA fisher can start at any water cell (r, c) and can do the following operations any number of times:\n\n\n\tCatch all the fis... | [
{
"hash": 9029729987447891000,
"runtime": "185ms",
"solution": "class Solution(object):\n def findMaxFish(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n \n def dfs(i, j):\n if i < 0 or j < 0 or i >= num_rows or j >= num_co... | class Solution(object):
def findMaxFish(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 58.9 | Level 3 | Hi |
minimum-swaps-to-make-strings-equal | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two strings <code>s1</code> and <code>s2</code> of equal length consisting of letters <code>"x"</code> and <code>"y"</code> <strong>only</strong>. Your task is to make these two strings equal to e... | 1247 | Medium | [
"You are given two strings s1 and s2 of equal length consisting of letters \"x\" and \"y\" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings, which means: swap s1[i] and s2[j].\n\nReturn the minimum number of swaps required to make s1 ... | [
{
"hash": 2861495681237254000,
"runtime": "17ms",
"solution": "class Solution(object):\n def minimumSwap(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: int\n \"\"\"\n n, m = len(s1), len(s2)\n if n != m:\n return -1\n ... | class Solution(object):
def minimumSwap(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: int
"""
| None | None | None | None | None | None | 64.4 | Level 2 | Hi |
match-substring-after-replacement | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two strings <code>s</code> and <code>sub</code>. You are also given a 2D character array <code>mappings</code> where <code>mappings[i] = [old<sub>i</sub>, new<sub>i</sub>]</code> indicates that you may perform the fo... | 2301 | Hard | [
"You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times:\n\n\n\tReplace a character oldi of sub with newi.\n\n\nEach character in sub cannot be replaced more than once.\n\nRetur... | [
{
"hash": 1168098673859448800,
"runtime": "8426ms",
"solution": "class Solution(object):\n def matchReplacement(self, s, sub, mappings):\n \"\"\"\n :type s: str\n :type sub: str\n :type mappings: List[List[str]]\n :rtype: bool\n \"\"\"\n sub_map = dict... | class Solution(object):
def matchReplacement(self, s, sub, mappings):
"""
:type s: str
:type sub: str
:type mappings: List[List[str]]
:rtype: bool
"""
| None | None | None | None | None | None | 39.8 | Level 5 | Hi |
non-decreasing-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array <code>nums</code> with <code>n</code> integers, your task is to check if it could become non-decreasing by modifying <strong>at most one element</strong>.</p>\n\n<p>We define an array is non-decreasing if <code>nums... | 665 | Medium | [
"Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element.\n\nWe define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).\n\n \nExample 1:\n\nInput: nums = [4,2,3]\nOutput: true\nExplanat... | [
{
"hash": -8578946153322953000,
"runtime": "148ms",
"solution": "class Solution(object):\n def checkPossibility(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n modifications = 0\n\n value = nums[0]\n for i in range(len(nums)):\n... | class Solution(object):
def checkPossibility(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 24.5 | Level 4 | Hi |
maximum-number-of-points-from-grid-queries | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> integer matrix <code>grid</code> and an array <code>queries</code> of size <code>k</code>.</p>\n\n<p>Find an array <code>answer</code> of size <code>k</code> such that for each integer <code>que... | 2503 | Hard | [
"You are given an m x n integer matrix grid and an array queries of size k.\n\nFind an array answer of size k such that for each integer queries[i] you start in the top left cell of the matrix and repeat the following process:\n\n\n\tIf queries[i] is strictly greater than the value of the current cell that you are ... | [
{
"hash": -4367023727380548000,
"runtime": "1024ms",
"solution": "class Solution(object):\n import heapq\n def maxPoints(self, grid, queries):\n m = len(grid)\n n = len(grid[0])\n used = [[False for j in range(n)] for i in range(m)]\n hq = [(grid[0][0], 0, 0)]\n ... | class Solution(object):
def maxPoints(self, grid, queries):
"""
:type grid: List[List[int]]
:type queries: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 35.8 | Level 5 | Hi |
number-of-students-unable-to-eat-lunch | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers <code>0</code> and <code>1</code> respectively. All students stand in a queue. Each student either prefers square or circular sandwi... | 1700 | Easy | [
"The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.\n\nThe number of sandwiches in the cafeteria is equal to the number of students. The sandwiches are place... | [
{
"hash": -6985297806004515000,
"runtime": "46ms",
"solution": "class Solution(object):\n def countStudents(self, students, sandwiches):\n \"\"\"\n :type students: List[int]\n :type sandwiches: List[int]\n :rtype: int\n \"\"\"\n \n count = 0\n n... | class Solution(object):
def countStudents(self, students, sandwiches):
"""
:type students: List[int]
:type sandwiches: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 70.4 | Level 1 | Hi |
parsing-a-boolean-expression | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A <strong>boolean expression</strong> is an expression that evaluates to either <code>true</code> or <code>false</code>. It can be in one of the following shapes:</p>\n\n<ul>\n\t<li><code>'t'</code> that evaluates to <code... | 1106 | Hard | [
"A boolean expression is an expression that evaluates to either true or false. It can be in one of the following shapes:\n\n\n\t't' that evaluates to true.\n\t'f' that evaluates to false.\n\t'!(subExpr)' that evaluates to the logical NOT of the inner expression subExpr.\n\t'&(subExpr₁, subExpr₂, ..., subExprn)' tha... | [
{
"hash": 8113254896256334000,
"runtime": "273ms",
"solution": "class Solution(object):\n def NOT(self, expression):\n if \"t\" in expression:\n return \"f\"\n return \"t\"\n\n def AND(self, expression):\n if \"f\" in expression:\n return \"f\"\n r... | class Solution(object):
def parseBoolExpr(self, expression):
"""
:type expression: str
:rtype: bool
"""
| None | None | None | None | None | None | 58.7 | Level 5 | Hi |
partition-array-for-maximum-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>arr</code>, partition the array into (contiguous) subarrays of length <strong>at most</strong> <code>k</code>. After partitioning, each subarray has their values changed to become the maximum value of ... | 1043 | Medium | [
"Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.\n\nReturn the largest sum of the given array after partitioning. Test cases are generated so that the answer fits... | [
{
"hash": 5114471606857475000,
"runtime": "1610ms",
"solution": "class Solution(object):\n def maxSumAfterPartitioning(self, arr, k):\n \"\"\"\n :type arr: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n # cases 0 ... k for index 0\n # cases 0 ... k ... | class Solution(object):
def maxSumAfterPartitioning(self, arr, k):
"""
:type arr: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 72.3 | Level 2 | Hi |
random-pick-index | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code> with possible <strong>duplicates</strong>, randomly output the index of a given <code>target</code> number. You can assume that the given target number must exist in the array.</p>\n\n<p>Im... | 398 | Medium | [
"Given an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.\n\nImplement the Solution class:\n\n\n\tSolution(int[] nums) Initializes the object with the array nums.\n\tint pick(int target) Picks a ran... | [
{
"hash": -210269518505713820,
"runtime": "309ms",
"solution": "class Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n # map: value, list[indexes]\n self.map = {}\n for i in range(len(nums)):\n if nums[i] ... | class Solution(object):
def __init__(self, nums):
"""
:type nums: List[int]
"""
def pick(self, target):
"""
:type target: int
:rtype: int
"""
# Your Solution object will be instantiated and called as such:
# obj = Solution(nums)
# par... | None | None | None | None | None | None | 62.7 | Level 2 | Hi |
row-with-maximum-ones | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <code>m x n</code> binary matrix <code>mat</code>, find the <strong>0-indexed</strong> position of the row that contains the <strong>maximum</strong> count of <strong>ones,</strong> and the number of ones in that row.</p>\... | 2643 | Easy | [
"Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row.\n\nIn case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.\n\nReturn an array containing the ind... | [
{
"hash": 433103331698532350,
"runtime": "755ms",
"solution": "class Solution(object):\n def rowAndMaximumOnes(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: List[int]\n \"\"\"\n max_ones, index = 0, 0\n for entry in mat:\n current_one... | class Solution(object):
def rowAndMaximumOnes(self, mat):
"""
:type mat: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 75.6 | Level 1 | Hi |
find-and-replace-in-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> string <code>s</code> that you must perform <code>k</code> replacement operations on. The replacement operations are given as three <strong>0-indexed</strong> parallel arrays, <code>indic... | 833 | Medium | [
"You are given a 0-indexed string s that you must perform k replacement operations on. The replacement operations are given as three 0-indexed parallel arrays, indices, sources, and targets, all of length k.\n\nTo complete the ith replacement operation:\n\n\n\tCheck if the substring sources[i] occurs at index indic... | [
{
"hash": 1814773856597305900,
"runtime": "27ms",
"solution": "class Solution(object):\n def findReplaceString(self, S, indices, sources, targets):\n \"\"\"\n :type s: str\n :type indices: List[int]\n :type sources: List[str]\n :type targets: List[str]\n :rty... | class Solution(object):
def findReplaceString(self, s, indices, sources, targets):
"""
:type s: str
:type indices: List[int]
:type sources: List[str]
:type targets: List[str]
:rtype: str
"""
| None | None | None | None | None | None | 53.4 | Level 3 | Hi |
last-stone-weight | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array of integers <code>stones</code> where <code>stones[i]</code> is the weight of the <code>i<sup>th</sup></code> stone.</p>\n\n<p>We are playing a game with the stones. On each turn, we choose the <strong>heavi... | 1046 | Easy | [
"You are given an array of integers stones where stones[i] is the weight of the ith stone.\n\nWe are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is:\n\n\n\tIf x == ... | [
{
"hash": 7401271380261462000,
"runtime": "17ms",
"solution": "class Solution(object):\n def lastStoneWeight(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: int\n \"\"\"\n \n while len(stones) > 1:\n big_stone = max(stones)\n ... | class Solution(object):
def lastStoneWeight(self, stones):
"""
:type stones: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 65.2 | Level 1 | Hi |
sum-of-mutated-array-closest-to-target | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>arr</code> and a target value <code>target</code>, return the integer <code>value</code> such that when we change all the integers larger than <code>value</code> in the given array to be equal to <code... | 1300 | Medium | [
"Given an integer array arr and a target value target, return the integer value such that when we change all the integers larger than value in the given array to be equal to value, the sum of the array gets as close as possible (in absolute difference) to target.\n\nIn case of a tie, return the minimum such integer... | [
{
"hash": 1937762296765655000,
"runtime": "107ms",
"solution": "class Solution(object):\n def findBestValue(self, arr, target):\n \"\"\"\n :type arr: List[int]\n :type target: int\n :rtype: int\n \"\"\"\n total = sum(arr)\n arr.sort()\n l = 0\n ... | class Solution(object):
def findBestValue(self, arr, target):
"""
:type arr: List[int]
:type target: int
:rtype: int
"""
| None | None | None | None | None | None | 44.1 | Level 4 | Hi |
partition-array-into-three-parts-with-equal-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>arr</code>, return <code>true</code> if we can partition the array into three <strong>non-empty</strong> parts with equal sums.</p>\n\n<p>Formally, we can partition the array if we can find indexes... | 1013 | Easy | [
"Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.\n\nFormally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] + ... + arr[j - 1] == arr[j] + arr[j + 1] + ... + arr[arr.le... | [
{
"hash": -505256407566111170,
"runtime": "246ms",
"solution": "class Solution(object):\n def canThreePartsEqualSum(self, arr):\n c, s, tot = 0, set(), 0\n for i in range(0, len(arr)):\n tot += arr[i]\n a, b, z = False, False, 0\n for i in range(0, len(arr)-1):\... | class Solution(object):
def canThreePartsEqualSum(self, arr):
"""
:type arr: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 42.1 | Level 1 | Hi |
find-smallest-letter-greater-than-target | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array of characters <code>letters</code> that is sorted in <strong>non-decreasing order</strong>, and a character <code>target</code>. There are <strong>at least two different</strong> characters in <code>letters<... | 744 | Easy | [
"You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.\n\nReturn the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first charac... | [
{
"hash": 805921308578471400,
"runtime": "67ms",
"solution": "class Solution(object):\n def nextGreatestLetter(self, letters, target):\n \"\"\"\n :type letters: List[str]\n :type target: str\n :rtype: str\n \"\"\"\n l = 0\n r = len(letters) - 1\n ... | class Solution(object):
def nextGreatestLetter(self, letters, target):
"""
:type letters: List[str]
:type target: str
:rtype: str
"""
| None | None | None | None | None | None | 51.4 | Level 1 | Hi |
remove-letter-to-equalize-frequency | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> string <code>word</code>, consisting of lowercase English letters. You need to select <strong>one</strong> index and <strong>remove</strong> the letter at that index from <code>word</code... | 2423 | Easy | [
"You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.\n\nReturn true if it is possible to remove one letter so that the frequency of all letters in wo... | [
{
"hash": 4079175898970081000,
"runtime": "14ms",
"solution": "class Solution(object):\n def equalFrequency(self, word):\n \"\"\"\n :type word: str\n :rtype: bool\n \"\"\"\n d = Counter(word)\n\n for c in word:\n d[c] -= 1\n new = []\n ... | class Solution(object):
def equalFrequency(self, word):
"""
:type word: str
:rtype: bool
"""
| None | None | None | None | None | None | 17.3 | Level 1 | Hi |
minimum-cost-to-hire-k-workers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There are <code>n</code> workers. You are given two integer arrays <code>quality</code> and <code>wage</code> where <code>quality[i]</code> is the quality of the <code>i<sup>th</sup></code> worker and <code>wage[i]</code> is the m... | 857 | Hard | [
"There are n workers. You are given two integer arrays quality and wage where quality[i] is the quality of the ith worker and wage[i] is the minimum wage expectation for the ith worker.\n\nWe want to hire exactly k workers to form a paid group. To hire a group of k workers, we must pay them according to the followi... | [
{
"hash": 3872399558052837400,
"runtime": "187ms",
"solution": "class Solution(object):\n def mincostToHireWorkers(self, quality, wage, k):\n \"\"\"\n :type quality: List[int]\n :type wage: List[int]\n :type k: int\n :rtype: float\n \"\"\"\n qsum = 0\n... | class Solution(object):
def mincostToHireWorkers(self, quality, wage, k):
"""
:type quality: List[int]
:type wage: List[int]
:type k: int
:rtype: float
"""
| None | None | None | None | None | None | 52.8 | Level 5 | Hi |
greatest-english-letter-in-upper-and-lower-case | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string of English letters <code>s</code>, return <em>the <strong>greatest </strong>English letter which occurs as <strong>both</strong> a lowercase and uppercase letter in</em> <code>s</code>. The returned letter should be... | 2309 | Easy | [
"Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string.\n\nAn English letter b is greater than another letter a if b appears after a in the Engli... | [
{
"hash": 3985768478428600000,
"runtime": "110ms",
"solution": "class Solution(object):\n def greatestLetter(self, s):\n\n string = list(s)\n\n while len(string) > 0:\n if max(string).upper() in string and not max(string).isupper():\n return max(string).upper()... | class Solution(object):
def greatestLetter(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 69.2 | Level 1 | Hi |
add-to-array-form-of-integer | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The <strong>array-form</strong> of an integer <code>num</code> is an array representing its digits in left to right order.</p>\n\n<ul>\n\t<li>For example, for <code>num = 1321</code>, the array form is <code>[1,3,2,1]</code>.</li>... | 989 | Easy | [
"The array-form of an integer num is an array representing its digits in left to right order.\n\n\n\tFor example, for num = 1321, the array form is [1,3,2,1].\n\n\nGiven num, the array-form of an integer, and an integer k, return the array-form of the integer num + k.\n\n \nExample 1:\n\nInput: num = [1,2,0,0], k =... | [
{
"hash": -4022603359780072400,
"runtime": "1264ms",
"solution": "class Solution(object):\n def addToArrayForm(self, num, k):\n \"\"\"\n :type num: List[int]\n :type k: int\n :rtype: List[int]\n \"\"\"\n int_num = 0\n for digit in num:\n int... | class Solution(object):
def addToArrayForm(self, num, k):
"""
:type num: List[int]
:type k: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 45.9 | Level 1 | Hi |
maximum-distance-between-a-pair-of-values | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two <strong>non-increasing 0-indexed </strong>integer arrays <code>nums1</code> and <code>nums2</code>.</p>\n\n<p>A pair of indices <code>(i, j)</code>, where <code>0 <= i < nums1.length</code> and ... | 1855 | Medium | [
"You are given two non-increasing 0-indexed integer arrays nums1 and nums2.\n\nA pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair is j - i.\n\nReturn the maximum distance of any valid pair (i, j)... | [
{
"hash": 3323487220778564000,
"runtime": "831ms",
"solution": "class Solution(object):\n def maxDistance(self, nums1, nums2):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :rtype: int\n \"\"\"\n i = 0\n distance = 0\n for j in ra... | class Solution(object):
def maxDistance(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 53.4 | Level 3 | Hi |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.