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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
closest-subsequence-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code> and an integer <code>goal</code>.</p>\n\n<p>You want to choose a subsequence of <code>nums</code> such that the sum of its elements is the closest possible to <code>goal</code>. Tha... | 1755 | Hard | [
"You are given an integer array nums and an integer goal.\n\nYou want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is sum, then you want to minimize the absolute difference abs(sum - goal).\n\nReturn the minimum ... | [
{
"hash": -5037098306384467000,
"runtime": "4132ms",
"solution": "class Solution(object):\n def minAbsDifference(self, nums, goal):\n \"\"\"\n :type nums: List[int]\n :type goal: int\n :rtype: int\n \"\"\"\n n = len(nums)\n if n == 0:\n retu... | class Solution(object):
def minAbsDifference(self, nums, goal):
"""
:type nums: List[int]
:type goal: int
:rtype: int
"""
| None | None | None | None | None | None | 38.3 | Level 5 | Hi |
minimum-score-of-a-path-between-two-cities | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a positive integer <code>n</code> representing <code>n</code> cities numbered from <code>1</code> to <code>n</code>. You are also given a <strong>2D</strong> array <code>roads</code> where <code>roads[i] = [a<sub>i</... | 2492 | Medium | [
"You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal to distancei. The cities graph is not necessarily connected.\n\nThe sco... | [
{
"hash": -4948073066380987000,
"runtime": "1347ms",
"solution": "from sys import maxsize\nclass Solution(object):\n def minScore(self, n, roads):\n \"\"\"\n :type n: int\n :type roads: List[List[int]]\n :rtype: int\n \"\"\"\n\n # create adj list represented ... | class Solution(object):
def minScore(self, n, roads):
"""
:type n: int
:type roads: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 57.6 | Level 3 | Hi |
get-equal-substrings-within-budget | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two strings <code>s</code> and <code>t</code> of the same length and an integer <code>maxCost</code>.</p>\n\n<p>You want to change <code>s</code> to <code>t</code>. Changing the <code>i<sup>th</sup></code> character ... | 1208 | Medium | [
"You are given two strings s and t of the same length and an integer maxCost.\n\nYou want to change s to t. Changing the ith character of s to ith character of t costs |s[i] - t[i]| (i.e., the absolute difference between the ASCII values of the characters).\n\nReturn the maximum length of a substring of s that can ... | [
{
"hash": 5393698804397611000,
"runtime": "71ms",
"solution": "class Solution(object):\n def equalSubstring(self, s, t, maxCost):\n \"\"\"\n :type s: str\n :type t: str\n :type maxCost: int\n :rtype: int\n \"\"\"\n slow_index = 0\n fast_index = ... | class Solution(object):
def equalSubstring(self, s, t, maxCost):
"""
:type s: str
:type t: str
:type maxCost: int
:rtype: int
"""
| None | None | None | None | None | None | 50.1 | Level 3 | Hi |
brick-wall | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a rectangular brick wall in front of you with <code>n</code> rows of bricks. The <code>i<sup>th</sup></code> row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The ... | 554 | Medium | [
"There is a rectangular brick wall in front of you with n rows of bricks. The ith row has some number of bricks each of the same height (i.e., one unit) but they can be of different widths. The total width of each row is the same.\n\nDraw a vertical line from the top to the bottom and cross the least bricks. If you... | [
{
"hash": -802838922869049200,
"runtime": "140ms",
"solution": "class Solution(object):\n def leastBricks(self, wall):\n \"\"\"\n :type wall: List[List[int]]\n :rtype: int\n \"\"\"\n # 1,3,5,6\n # 3,4,6\n # 1,4,6\n # 2,6\n # 3,4,6\n ... | class Solution(object):
def leastBricks(self, wall):
"""
:type wall: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 54.3 | Level 3 | Hi |
find-the-middle-index-in-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a <strong>0-indexed</strong> integer array <code>nums</code>, find the <strong>leftmost</strong> <code>middleIndex</code> (i.e., the smallest amongst all the possible ones).</p>\n\n<p>A <code>middleIndex</code> is an index w... | 1991 | Easy | [
"Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones).\n\nA middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[nums.length-1].\n\nIf middleIndex == 0, the left side su... | [
{
"hash": 3371297223611768000,
"runtime": "10ms",
"solution": "class Solution(object):\n def findMiddleIndex(self, nums):\n nums=[0]+nums+[0]\n total=sum(nums)\n i=1\n left=0\n # print(nums)\n while i<len(nums)-1:\n left+=nums[i-1]\n rig... | class Solution(object):
def findMiddleIndex(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 67.4 | Level 1 | Hi |
subarrays-with-k-different-integers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of <strong>good subarrays</strong> of </em><code>nums</code>.</p>\n\n<p>A <strong>good array</strong> is an array where the number of di... | 992 | Hard | [
"Given an integer array nums and an integer k, return the number of good subarrays of nums.\n\nA good array is an array where the number of different integers in that array is exactly k.\n\n\n\tFor example, [1,2,3,1,2] has 3 different integers: 1, 2, and 3.\n\n\nA subarray is a contiguous part of an array.\n\n \nEx... | [
{
"hash": -1896786524444476200,
"runtime": "357ms",
"solution": "class Solution(object):\n def subarraysWithKDistinct(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n return self.atmostk(nums, k) - self.atmostk(nums, k-... | class Solution(object):
def subarraysWithKDistinct(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 56.1 | Level 5 | Hi |
maximum-candies-you-can-get-from-boxes | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You have <code>n</code> boxes labeled from <code>0</code> to <code>n - 1</code>. You are given four arrays: <code>status</code>, <code>candies</code>, <code>keys</code>, and <code>containedBoxes</code> where:</p>\n\n<ul>\n\t<li><c... | 1298 | Hard | [
"You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where:\n\n\n\tstatus[i] is 1 if the ith box is open and 0 if the ith box is closed,\n\tcandies[i] is the number of candies in the ith box,\n\tkeys[i] is a list of the labels of the boxes you can open afte... | [
{
"hash": 8739237318485361000,
"runtime": "631ms",
"solution": "class Solution(object):\n def maxCandies(self, status, candies, keys, containedBoxes, initialBoxes):\n q = deque(initialBoxes)\n visited = set()\n res = 0\n while q:\n itr, opened = len(q), False\n ... | class Solution(object):
def maxCandies(self, status, candies, keys, containedBoxes, initialBoxes):
"""
:type status: List[int]
:type candies: List[int]
:type keys: List[List[int]]
:type containedBoxes: List[List[int]]
:type initialBoxes: List[int]
:rtype: int
... | None | None | None | None | None | None | 58.3 | Level 5 | Hi |
h-index | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>citations</code> where <code>citations[i]</code> is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return <em>the researcher's h-index</em>.</p>\n\n<... | 274 | Medium | [
"Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.\n\nAccording to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at lea... | [
{
"hash": -8617253965519530000,
"runtime": "59ms",
"solution": "class Solution:\n def hIndex(self, citations: List[int]) -> int:\n papers = defaultdict(int)\n for i in citations:\n papers[min(i,len(citations))]+=1\n h = len(citations)\n s = papers[h]\n pr... | class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 38.6 | Level 4 | Hi |
lowest-common-ancestor-of-deepest-leaves | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a binary tree, return <em>the lowest common ancestor of its deepest leaves</em>.</p>\n\n<p>Recall that:</p>\n\n<ul>\n\t<li>The node of a binary tree is a leaf if and only if it has no children</li>\n... | 1123 | Medium | [
"Given the root of a binary tree, return the lowest common ancestor of its deepest leaves.\n\nRecall that:\n\n\n\tThe node of a binary tree is a leaf if and only if it has no children\n\tThe depth of the root of the tree is 0. if the depth of a node is d, the depth of each of its children is d + 1.\n\tThe lowest co... | [
{
"hash": 110136041733751870,
"runtime": "59ms",
"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 lcaDeepestLeaves(se... | # 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 lcaDeepestLeaves(self, root):
"""
:type root: TreeNode
:rtype: T... | None | None | None | None | None | None | 71.5 | Level 2 | Hi |
number-of-good-ways-to-split-a-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code>.</p>\n\n<p>A split is called <strong>good</strong> if you can split <code>s</code> into two non-empty strings <code>s<sub>left</sub></code> and <code>s<sub>right</sub></code> where their conca... | 1525 | Medium | [
"You are given a string s.\n\nA split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in sleft and sright is the same.\n\nReturn the number of good splits you can make in s.\n\n \nExam... | [
{
"hash": -5295300293686628000,
"runtime": "98ms",
"solution": "class Solution(object):\n def numSplits(self, s):\n count = 0\n left_set = set()\n right_set = set()\n left_count = [0] * len(s)\n right_count = [0] * len(s)\n\n for i in range(len(s)):\n ... | class Solution(object):
def numSplits(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 68.6 | Level 2 | Hi |
words-within-two-edits-of-dictionary | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two string arrays, <code>queries</code> and <code>dictionary</code>. All words in each array comprise of lowercase English letters and have the same length.</p>\n\n<p>In one <strong>edit</strong> you can take a word ... | 2452 | Medium | [
"You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length.\n\nIn one edit you can take a word from queries, and change any letter in it to any other letter. Find all words from queries that, after a maximum of two edits, equal so... | [
{
"hash": 2342973541591496700,
"runtime": "45ms",
"solution": "class Solution(object):\n def twoEditWords(self, queries, dictionary):\n \"\"\"\n :type queries: List[str]\n :type dictionary: List[str]\n :rtype: List[str]\n \"\"\"\n # Внутренняя функция для про... | class Solution(object):
def twoEditWords(self, queries, dictionary):
"""
:type queries: List[str]
:type dictionary: List[str]
:rtype: List[str]
"""
| None | None | None | None | None | None | 60.3 | Level 2 | Hi |
positions-of-large-groups | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>In a string <code><font face=\"monospace\">s</font></code> of lowercase letters, these letters form consecutive groups of the same character.</p>\n\n<p>For example, a string like <code>s = "abbxxxxzyy"</code> has th... | 830 | Easy | [
"In a string s of lowercase letters, these letters form consecutive groups of the same character.\n\nFor example, a string like s = \"abbxxxxzyy\" has the groups \"a\", \"bb\", \"xxxx\", \"z\", and \"yy\".\n\nA group is identified by an interval [start, end], where start and end denote the start and end indices (in... | [
{
"hash": 1270552667070274800,
"runtime": "10ms",
"solution": "class Solution(object):\n def largeGroupPositions(self, s):\n \"\"\"\n :type s: str\n :rtype: List[List[int]]\n \"\"\"\n result = []\n n = len(s)\n\n start = 0\n\n for i in range(1,n... | class Solution(object):
def largeGroupPositions(self, s):
"""
:type s: str
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 52.1 | Level 1 | Hi |
maximum-number-of-jumps-to-reach-the-last-index | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> of <code>n</code> integers and an integer <code>target</code>.</p>\n\n<p>You are initially positioned at index <code>0</code>. In one step, you can jump from index... | 2770 | Medium | [
"You are given a 0-indexed array nums of n integers and an integer target.\n\nYou are initially positioned at index 0. In one step, you can jump from index i to any index j such that:\n\n\n\t0 <= i < j < n\n\t-target <= nums[j] - nums[i] <= target\n\n\nReturn the maximum number of jumps you can make to reach index ... | [
{
"hash": -8895408609263050000,
"runtime": "626ms",
"solution": "class Solution(object):\n # strictly increasing jumps, cant jump on same\n # abs(nums[j] - nums[i]) <= target\n # max jumps\n # ideal -> 0 -> 1 -> 2 -> 3..., as soon as you can jump, you should\n # 0, 1, 1, 99, 99, 99, 99, 1... | class Solution(object):
def maximumJumps(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
| None | None | None | None | None | None | 29.1 | Level 4 | Hi |
arithmetic-subarrays | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A sequence of numbers is called <strong>arithmetic</strong> if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence <code>s</code> is arithmetic if ... | 1630 | Medium | [
"A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1] - s[i] == s[1] - s[0] for all valid i.\n\nFor example, these are arithmetic sequences:\n\n1, 3, ... | [
{
"hash": 2484813487961145300,
"runtime": "167ms",
"solution": "class Solution(object):\n def checkArithmeticSubarrays(self, nums, l, r):\n \"\"\"\n :type nums: List[int]\n :type l: List[int]\n :type r: List[int]\n :rtype: List[bool]\n \"\"\"\n \n ... | class Solution(object):
def checkArithmeticSubarrays(self, nums, l, r):
"""
:type nums: List[int]
:type l: List[int]
:type r: List[int]
:rtype: List[bool]
"""
| None | None | None | None | None | None | 84 | Level 2 | Hi |
lowest-common-ancestor-of-a-binary-search-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.</p>\n\n<p>According to the <a href=\"https://en.wikipedia.org/wiki/Lowest_common_ancestor\" target=\"_blank\">definition o... | 235 | Medium | [
"Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.\n\nAccording to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be ... | [
{
"hash": -8977613147802231000,
"runtime": "73ms",
"solution": "# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, x):\n# self.val = x\n# self.left = None\n# self.right = None\n\nclass Solution:\n def lowestCommonAncestor(self, root: 'TreeNode', ... | # Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def lowestCommonAncestor(self, root, p, q):
"""
:type root: TreeNode
:type p: TreeNode
:t... | None | None | None | None | None | None | 63.6 | Level 2 | Hi |
minimum-length-of-string-after-deleting-similar-ends | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code> consisting only of characters <code>'a'</code>, <code>'b'</code>, and <code>'c'</code>. You are asked to apply the following algorithm on the string any number of times:</p>\n\... | 1750 | Medium | [
"Given a string s consisting only of characters 'a', 'b', and 'c'. You are asked to apply the following algorithm on the string any number of times:\n\n\n\tPick a non-empty prefix from the string s where all the characters in the prefix are equal.\n\tPick a non-empty suffix from the string s where all the character... | [
{
"hash": 1557989670846521600,
"runtime": "65ms",
"solution": "class Solution(object):\n def minimumLength(self, s):\n left, right = 0, len(s) - 1\n\n while left < right and s[left] == s[right]:\n char = s[left]\n while left <= right and s[left] == char:\n ... | class Solution(object):
def minimumLength(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 44.7 | Level 4 | Hi |
number-of-good-paths | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a tree (i.e. a connected, undirected graph with no cycles) consisting of <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> and exactly <code>n - 1</code> edges.</p>\n\n<p>You are given a <strong>0-in... | 2421 | Hard | [
"There is a tree (i.e. a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges.\n\nYou are given a 0-indexed integer array vals of length n where vals[i] denotes the value of the ith node. You are also given a 2D integer array edges where edges[i] = [ai, ... | [
{
"hash": -4299128593585955000,
"runtime": "1715ms",
"solution": "class UnionFind:\n def __init__(self, n):\n self.parent = [i for i in range(n)]\n self.rank = [0] * n\n self.size = [1] * n\n\n def findparent(self, node):\n if self.parent[node]==node:\n retur... | class Solution(object):
def numberOfGoodPaths(self, vals, edges):
"""
:type vals: List[int]
:type edges: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 56.7 | Level 5 | Hi |
ways-to-split-array-into-three-subarrays | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A split of an integer array is <strong>good</strong> if:</p>\n\n<ul>\n\t<li>The array is split into three <strong>non-empty</strong> contiguous subarrays - named <code>left</code>, <code>mid</code>, <code>right</code> respectively... | 1712 | Medium | [
"A split of an integer array is good if:\n\n\n\tThe array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.\n\tThe sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal ... | [
{
"hash": 7840718067809042000,
"runtime": "1139ms",
"solution": "class Solution(object):\n def waysToSplit(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n m = 10**9 + 7\n prefix = [0]\n for x in nums: prefix.append(prefix[-1] + x... | class Solution(object):
def waysToSplit(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 32.8 | Level 4 | Hi |
intersection-of-multiple-arrays | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "Given a 2D integer array <code>nums</code> where <code>nums[i]</code> is a non-empty array of <strong>distinct</strong> positive integers, return <em>the list of integers that are present in <strong>each array</strong> of</em> <code>... | 2248 | Easy | [
"Given a 2D integer array nums where nums[i] is a non-empty array of distinct positive integers, return the list of integers that are present in each array of nums sorted in ascending order.\n \nExample 1:\n\nInput: nums = [[3,1,2,4,5],[1,2,3,4],[3,4,5,6]]\nOutput: [3,4]\nExplanation: \nThe only integers present in... | [
{
"hash": -1459838185063307000,
"runtime": "46ms",
"solution": "class Solution(object):\n def intersection(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: List[int]\n \"\"\"\n\n seen = {}\n ans = []\n\n for i in nums:\n for j i... | class Solution(object):
def intersection(self, nums):
"""
:type nums: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 68.1 | Level 1 | Hi |
detect-squares | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a stream of points on the X-Y plane. Design an algorithm that:</p>\n\n<ul>\n\t<li><strong>Adds</strong> new points from the stream into a data structure. <strong>Duplicate</strong> points are allowed and should be tr... | 2013 | Medium | [
"You are given a stream of points on the X-Y plane. Design an algorithm that:\n\n\n\tAdds new points from the stream into a data structure. Duplicate points are allowed and should be treated as different points.\n\tGiven a query point, counts the number of ways to choose three points from the data structure such th... | [
{
"hash": 8441506589911685000,
"runtime": "295ms",
"solution": "class DetectSquares(object):\n\n def __init__(self):\n self.x_axis = defaultdict(set)\n self.y_axis = defaultdict(set)\n self.freq = defaultdict(int)\n\n def add(self, point):\n \"\"\"\n :type point:... | class DetectSquares(object):
def __init__(self):
def add(self, point):
"""
:type point: List[int]
:rtype: None
"""
def count(self, point):
"""
:type point: List[int]
:rtype: int
"""
# Your DetectSquares object wi... | None | None | None | None | None | None | 50.4 | Level 3 | Hi |
longest-mountain-in-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You may recall that an array <code>arr</code> is a <strong>mountain array</strong> if and only if:</p>\n\n<ul>\n\t<li><code>arr.length >= 3</code></li>\n\t<li>There exists some index <code>i</code> (<strong>0-indexed</strong>) ... | 845 | Medium | [
"You may recall that an array arr is a mountain array if and only if:\n\n\n\tarr.length >= 3\n\tThere exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:\n\t\n\t\tarr[0] < arr[1] < ... < arr[i - 1] < arr[i]\n\t\tarr[i] > arr[i + 1] > ... > arr[arr.length - 1]\n\t\n\t\n\n\nGiven an integer array a... | [
{
"hash": -7292976315779997000,
"runtime": "120ms",
"solution": "class Solution(object):\n def longestMountain(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: int\n \"\"\"\n\n if len(arr) < 3:\n return 0\n \n longest = 0\n curr ... | class Solution(object):
def longestMountain(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 40.2 | Level 4 | Hi |
maximum-number-of-consecutive-values-you-can-make | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>coins</code> of length <code>n</code> which represents the <code>n</code> coins that you own. The value of the <code>i<sup>th</sup></code> coin is <code>coins[i]</code>. You can <strong>make</s... | 1798 | Medium | [
"You are given an integer array coins of length n which represents the n coins that you own. The value of the ith coin is coins[i]. You can make some value x if you can choose some of your n coins such that their values sum up to x.\n\nReturn the maximum number of consecutive integer values that you can make with y... | [
{
"hash": -6696261363362799000,
"runtime": "587ms",
"solution": "class Solution(object):\n def getMaximumConsecutive(self, coins):\n coins = sorted(coins)\n res=0\n\n for i in coins:\n if i - res >1:\n return res +1\n else:\n re... | class Solution(object):
def getMaximumConsecutive(self, coins):
"""
:type coins: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 57.5 | Level 3 | Hi |
find-champion-i | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There are <code>n</code> teams numbered from <code>0</code> to <code>n - 1</code> in a tournament.</p>\n\n<p>Given a <strong>0-indexed</strong> 2D boolean matrix <code>grid</code> of size <code>n * n</code>. For all <code>i, j</co... | 2923 | Easy | [
"There are n teams numbered from 0 to n - 1 in a tournament.\n\nGiven a 0-indexed 2D boolean matrix grid of size n * n. For all i, j that 0 <= i, j <= n - 1 and i != j team i is stronger than team j if grid[i][j] == 1, otherwise, team j is stronger than team i.\n\nTeam a will be the champion of the tournament if th... | [
{
"hash": 8192825053168886000,
"runtime": "463ms",
"solution": "class Solution(object):\n def findChampion(self, grid):\n highest = 0\n count = 0\n for i in range(len(grid)):\n temp = 0\n for j in range(len(grid[i])):\n temp += grid[i][j]\n ... | class Solution(object):
def findChampion(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 71.9 | Level 1 | Hi |
shortest-distance-to-a-character | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code> and a character <code>c</code> that occurs in <code>s</code>, return <em>an array of integers </em><code>answer</code><em> where </em><code>answer.length == s.length</code><em> and </em><code>answer[i... | 821 | Easy | [
"Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s.\n\nThe distance between two indices i and j is abs(i - j), where abs is the absolute value function.\n\n ... | [
{
"hash": -3788938476300908000,
"runtime": "60ms",
"solution": "class Solution(object):\n def shortestToChar(self, s, c):\n p=[]\n for i in range(0,len(s)):\n if s[i]==c:\n p.append(i)\n res=[]\n for i in range(0,len(s)):\n if s[i]==c:\... | class Solution(object):
def shortestToChar(self, s, c):
"""
:type s: str
:type c: str
:rtype: List[int]
"""
| None | None | None | None | None | None | 71.3 | Level 1 | Hi |
semi-ordered-permutation | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> permutation of <code>n</code> integers <code>nums</code>.</p>\n\n<p>A permutation is called <strong>semi-ordered</strong> if the first number equals <code>1</code> and the last number equ... | 2717 | Easy | [
"You are given a 0-indexed permutation of n integers nums.\n\nA permutation is called semi-ordered if the first number equals 1 and the last number equals n. You can perform the below operation as many times as you want until you make nums a semi-ordered permutation:\n\n\n\tPick two adjacent elements in nums, then ... | [
{
"hash": 3112820663777536000,
"runtime": "53ms",
"solution": "class Solution(object):\n def semiOrderedPermutation(self, nums):\n n=len(nums)\n i=nums.index(1)\n j=nums.index(n)\n ans=i+n-1-j-(i>j)\n return ans"
},
{
"hash": 7429601702986674000,
"runtim... | class Solution(object):
def semiOrderedPermutation(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 62.8 | Level 1 | Hi |
find-center-of-star-graph | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is an undirected <strong>star</strong> graph consisting of <code>n</code> nodes labeled from <code>1</code> to <code>n</code>. A star graph is a graph where there is one <strong>center</strong> node and <strong>exactly</stro... | 1791 | Easy | [
"There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.\n\nYou are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge be... | [
{
"hash": -600806994982344000,
"runtime": "693ms",
"solution": "class Solution:\n def findCenter(self, edges):\n n = len(edges)\n \n max_vertex = max(max(x, y) for x, y in edges) #highest node value = number of nodes\n graph = [[] for _ in range(max_vertex + 1)]\n f... | class Solution(object):
def findCenter(self, edges):
"""
:type edges: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 83.5 | Level 1 | Hi |
minimum-operations-to-make-the-array-alternating | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of <code>n</code> positive integers.</p>\n\n<p>The array <code>nums</code> is called <strong>alternating</strong> if:</p>\n\n<ul>\n\t<li><code>nums[i - ... | 2170 | Medium | [
"You are given a 0-indexed array nums consisting of n positive integers.\n\nThe array nums is called alternating if:\n\n\n\tnums[i - 2] == nums[i], where 2 <= i <= n - 1.\n\tnums[i - 1] != nums[i], where 1 <= i <= n - 1.\n\n\nIn one operation, you can choose an index i and change nums[i] into any positive integer.\... | [
{
"hash": -5485223108310399000,
"runtime": "1023ms",
"solution": "class Solution(object):\n\n def minimumOperations(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\" \n\n if len(nums) == 1:\n return 0\n\n if len(nums) == 2:\n ... | class Solution(object):
def minimumOperations(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 33.1 | Level 4 | Hi |
put-marbles-in-bags | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You have <code>k</code> bags. You are given a <strong>0-indexed</strong> integer array <code>weights</code> where <code>weights[i]</code> is the weight of the <code>i<sup>th</sup></code> marble. You are also given the integer <cod... | 2551 | Hard | [
"You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k.\n\nDivide the marbles into the k bags according to the following rules:\n\n\n\tNo bag is empty.\n\tIf the ith marble and jth marble are in a bag, then all marbles wit... | [
{
"hash": -2091940742408666000,
"runtime": "578ms",
"solution": "class Solution(object):\n def putMarbles(self, weights, k):\n i=0\n j=0\n l=[]\n for j in range(len(weights)-1):\n sum=weights[j]+weights[j+1]\n l.append(sum)\n sum=0\n ... | class Solution(object):
def putMarbles(self, weights, k):
"""
:type weights: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 66.9 | Level 5 | Hi |
valid-tic-tac-toe-state | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a Tic-Tac-Toe board as a string array <code>board</code>, return <code>true</code> if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.</p>\n\n<p>The board is a <code>3 x ... | 794 | Medium | [
"Given a Tic-Tac-Toe board as a string array board, return true if and only if it is possible to reach this board position during the course of a valid tic-tac-toe game.\n\nThe board is a 3 x 3 array that consists of characters ' ', 'X', and 'O'. The ' ' character represents an empty square.\n\nHere are the rules o... | [
{
"hash": -8050800981552927000,
"runtime": "11ms",
"solution": "class Solution(object):\n def validTicTacToe(self, board):\n \"\"\"\n :type board: List[str]\n :rtype: bool\n \"\"\"\n x_count, o_count = 0, 0\n \n for i in range(len(board)):\n ... | class Solution(object):
def validTicTacToe(self, board):
"""
:type board: List[str]
:rtype: bool
"""
| None | None | None | None | None | None | 34.9 | Level 4 | Hi |
the-number-of-full-rounds-you-have-played | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are participating in an online chess tournament. There is a chess round that starts every <code>15</code> minutes. The first round of the day starts at <code>00:00</code>, and after every <code>15</code> minutes, a new round s... | 1904 | Medium | [
"You are participating in an online chess tournament. There is a chess round that starts every 15 minutes. The first round of the day starts at 00:00, and after every 15 minutes, a new round starts.\n\n\n\tFor example, the second round starts at 00:15, the fourth round starts at 00:45, and the seventh round starts ... | [
{
"hash": -4757640784484902000,
"runtime": "12ms",
"solution": "class Solution(object):\n def numberOfRounds(self, loginTime, logoutTime):\n \"\"\"\n :type loginTime: str\n :type logoutTime: str\n :rtype: int\n \"\"\"\n\n login_hr = int(loginTime[0]+loginT... | class Solution(object):
def numberOfRounds(self, loginTime, logoutTime):
"""
:type loginTime: str
:type logoutTime: str
:rtype: int
"""
| None | None | None | None | None | None | 44.1 | Level 4 | Hi |
132-pattern | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of <code>n</code> integers <code>nums</code>, a <strong>132 pattern</strong> is a subsequence of three integers <code>nums[i]</code>, <code>nums[j]</code> and <code>nums[k]</code> such that <code>i < j < k</co... | 456 | Medium | [
"Given an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i < j < k and nums[i] < nums[k] < nums[j].\n\nReturn true if there is a 132 pattern in nums, otherwise, return false.\n\n \nExample 1:\n\nInput: nums = [1,2,3,4]\nOutput: false\nExplanation: T... | [
{
"hash": -7636580886328686000,
"runtime": "590ms",
"solution": "class Solution(object):\n def find132pattern(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n\n n = len(nums)\n minimums_index = [0] * n\n stack = []\n \n ... | class Solution(object):
def find132pattern(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 33.8 | Level 4 | Hi |
check-if-one-string-swap-can-make-strings-equal | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two strings <code>s1</code> and <code>s2</code> of equal length. A <strong>string swap</strong> is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these in... | 1790 | Easy | [
"You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices.\n\nReturn true if it is possible to make both strings equal by performing at most one string swap on exactly one of the s... | [
{
"hash": 8662316915411263000,
"runtime": "21ms",
"solution": "class Solution(object):\n def areAlmostEqual(self, s1, s2):\n \"\"\"\n :type s1: str\n :type s2: str\n :rtype: bool\n \"\"\"\n if s1 == s2:\n return True\n\n\n indexes = []\n ... | class Solution(object):
def areAlmostEqual(self, s1, s2):
"""
:type s1: str
:type s2: str
:rtype: bool
"""
| None | None | None | None | None | None | 45.4 | Level 1 | Hi |
pairs-of-songs-with-total-durations-divisible-by-60 | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a list of songs where the <code>i<sup>th</sup></code> song has a duration of <code>time[i]</code> seconds.</p>\n\n<p>Return <em>the number of pairs of songs for which their total duration in seconds is divisible by</... | 1010 | Medium | [
"You are given a list of songs where the ith song has a duration of time[i] seconds.\n\nReturn the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of indices i, j such that i < j with (time[i] + time[j]) % 60 == 0.\n\n \nExample 1:\n\nInput: time =... | [
{
"hash": 7294166785077365000,
"runtime": "215ms",
"solution": "class Solution(object):\n def numPairsDivisibleBy60_(self, time):\n ans, cnt = 0, collections.Counter()\n for t in time:\n theOther = -t % 60\n ans += cnt[theOther]\n cnt[t % 60] += 1\n ... | class Solution(object):
def numPairsDivisibleBy60(self, time):
"""
:type time: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 52.8 | Level 3 | Hi |
unique-substrings-in-wraparound-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We define the string <code>base</code> to be the infinite wraparound string of <code>"abcdefghijklmnopqrstuvwxyz"</code>, so <code>base</code> will look like this:</p>\n\n<ul>\n\t<li><code>"...zabcdefghijklmnopqrstu... | 467 | Medium | [
"We define the string base to be the infinite wraparound string of \"abcdefghijklmnopqrstuvwxyz\", so base will look like this:\n\n\n\t\"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....\".\n\n\nGiven a string s, return the number of unique non-empty substrings of s are present in base.\n\n \nExample... | [
{
"hash": 2704632927430530600,
"runtime": "135ms",
"solution": "class Solution(object):\n def findSubstringInWraproundString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n # sliding window: keep incresing the windo util contiguous\n n = len(s)\n ... | class Solution(object):
def findSubstringInWraproundString(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 39.2 | Level 4 | Hi |
largest-submatrix-with-rearrangements | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a binary matrix <code>matrix</code> of size <code>m x n</code>, and you are allowed to rearrange the <strong>columns</strong> of the <code>matrix</code> in any order.</p>\n\n<p>Return <em>the area of the largest subm... | 1727 | Medium | [
"You are given a binary matrix matrix of size m x n, and you are allowed to rearrange the columns of the matrix in any order.\n\nReturn the area of the largest submatrix within matrix where every element of the submatrix is 1 after reordering the columns optimally.\n\n \nExample 1:\n\nInput: matrix = [[0,0,1],[1,1,... | [
{
"hash": -2969212973057281500,
"runtime": "977ms",
"solution": "class Solution(object):\n def largestSubmatrix(self, matrix):\n m, n = len(matrix), len(matrix[0])\n \n for i in range(1, m):\n for j in range(n):\n if matrix[i][j] == 1:\n ... | class Solution(object):
def largestSubmatrix(self, matrix):
"""
:type matrix: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 75.5 | Level 2 | Hi |
minimize-the-difference-between-target-and-chosen-elements | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> integer matrix <code>mat</code> and an integer <code>target</code>.</p>\n\n<p>Choose one integer from <strong>each row</strong> in the matrix such that the <strong>absolute difference</strong> b... | 1981 | Medium | [
"You are given an m x n integer matrix mat and an integer target.\n\nChoose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized.\n\nReturn the minimum absolute difference.\n\nThe absolute difference between two numbers a and b is t... | [
{
"hash": 6083060215305282000,
"runtime": "2782ms",
"solution": "class Solution(object):\n def minimizeTheDifference(self, mat, target):\n \"\"\"\n :type mat: List[List[int]]\n :type target: int\n :rtype: int\n \"\"\"\n seen = set([0])\n ans = 50000\n ... | class Solution(object):
def minimizeTheDifference(self, mat, target):
"""
:type mat: List[List[int]]
:type target: int
:rtype: int
"""
| None | None | None | None | None | None | 33.8 | Level 4 | Hi |
number-of-adjacent-elements-with-the-same-color | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a <strong>0-indexed</strong> array <code>nums</code> of length <code>n</code>. Initially, all elements are <strong>uncolored </strong>(has a value of <code>0</code>).</p>\n\n<p>You are given a 2D integer array <code>queri... | 2672 | Medium | [
"There is a 0-indexed array nums of length n. Initially, all elements are uncolored (has a value of 0).\n\nYou are given a 2D integer array queries where queries[i] = [indexi, colori].\n\nFor each query, you color the index indexi with the color colori in the array nums.\n\nReturn an array answer of the same length... | [
{
"hash": -1354320107113053000,
"runtime": "1825ms",
"solution": "class Solution(object):\n def colorTheArray(self, n, queries):\n \"\"\"\n :type n: int\n :type queries: List[List[int]]\n :rtype: List[int]\n \"\"\"\n if n == 0:\n return [0]\n ... | class Solution(object):
def colorTheArray(self, n, queries):
"""
:type n: int
:type queries: List[List[int]]
:rtype: List[int]
"""
| None | None | None | None | None | None | 54 | Level 3 | Hi |
create-target-array-in-the-given-order | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given two arrays of integers <code>nums</code> and <code>index</code>. Your task is to create <em>target</em> array under the following rules:</p>\n\n<ul>\n\t<li>Initially <em>target</em> array is empty.</li>\n\t<li>From left... | 1389 | Easy | [
"Given two arrays of integers nums and index. Your task is to create target array under the following rules:\n\n\n\tInitially target array is empty.\n\tFrom left to right read nums[i] and index[i], insert at index index[i] the value nums[i] in target array.\n\tRepeat the previous step until there are no elements to... | [
{
"hash": -3153368820622699000,
"runtime": "9ms",
"solution": "class Solution(object):\n def createTargetArray(self, nums, index):\n target = []\n for i,j in zip(nums,index):\n target.insert(j,i)\n return target\n "
},
{
"hash": -2446686531644762600,
... | class Solution(object):
def createTargetArray(self, nums, index):
"""
:type nums: List[int]
:type index: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 85.7 | Level 1 | Hi |
bag-of-tokens | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You have an initial <strong>power</strong> of <code>power</code>, an initial <strong>score</strong> of <code>0</code>, and a bag of <code>tokens</code> where <code>tokens[i]</code> is the value of the <code>i<sup>th</sup></code> t... | 948 | Medium | [
"You have an initial power of power, an initial score of 0, and a bag of tokens where tokens[i] is the value of the ith token (0-indexed).\n\nYour goal is to maximize your total score by potentially playing each token in one of two ways:\n\n\n\tIf your current power is at least tokens[i], you may play the ith token... | [
{
"hash": -6483155471671746000,
"runtime": "37ms",
"solution": "class Solution(object):\n def bagOfTokensScore(self, tokens, power):\n \"\"\"\n :type tokens: List[int]\n :type power: int\n :rtype: int\n \"\"\"\n\n tokens.sort()\n\n res = 0\n\n l... | class Solution(object):
def bagOfTokensScore(self, tokens, power):
"""
:type tokens: List[int]
:type power: int
:rtype: int
"""
| None | None | None | None | None | None | 52.2 | Level 3 | Hi |
next-greater-numerically-balanced-number | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>An integer <code>x</code> is <strong>numerically balanced</strong> if for every digit <code>d</code> in the number <code>x</code>, there are <strong>exactly</strong> <code>d</code> occurrences of that digit in <code>x</code>.</p>\... | 2048 | Medium | [
"An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x.\n\nGiven an integer n, return the smallest numerically balanced number strictly greater than n.\n\n \nExample 1:\n\nInput: n = 1\nOutput: 22\nExplanation: \n22 is numerically balanced sinc... | [
{
"hash": 5710986658104092000,
"runtime": "7ms",
"solution": "class Solution(object):\n def nextBeautifulNumber(self, n):\n balanced=[0, 1, 22, 122, 212, 221, 333, 1333, 3133, 3313, 3331, 4444, 14444, 22333, 23233, 23323, 23332, 32233, 32323, 32332, 33223, 33232, 33322, 41444, 44144, 44414, 44... | class Solution(object):
def nextBeautifulNumber(self, n):
"""
:type n: int
:rtype: int
"""
| None | None | None | None | None | None | 47.6 | Level 3 | Hi |
01-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p>\n\n<p>The distance between two adjacent cells is <code>1</code>.</p>\n\n<p> </... | 542 | Medium | [
"Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell.\n\nThe distance between two adjacent cells is 1.\n\n \nExample 1:\n\nInput: mat = [[0,0,0],[0,1,0],[0,0,0]]\nOutput: [[0,0,0],[0,1,0],[0,0,0]]\n\n\nExample 2:\n\nInput: mat = [[0,0,0],[0,1,0],[1,1,1]]\nOutput: [[0,0,0],[0,1,0],[1... | [
{
"hash": 6249693407273703000,
"runtime": "870ms",
"solution": "class Solution:\n def updateMatrix(self, mat: List[List[int]]) -> List[List[int]]:\n # traverse the matrix, adding 0s to queue and initializing the 1s to INF\n queue = deque()\n width = len(mat[0])\n height = l... | class Solution(object):
def updateMatrix(self, mat):
"""
:type mat: List[List[int]]
:rtype: List[List[int]]
"""
| None | None | None | None | None | None | 47.9 | Level 3 | Hi |
rle-iterator | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We can use run-length encoding (i.e., <strong>RLE</strong>) to encode a sequence of integers. In a run-length encoded array of even length <code>encoding</code> (<strong>0-indexed</strong>), for all even <code>i</code>, <code>enco... | 900 | Medium | [
"We can use run-length encoding (i.e., RLE) to encode a sequence of integers. In a run-length encoded array of even length encoding (0-indexed), for all even i, encoding[i] tells us the number of times that the non-negative integer value encoding[i + 1] is repeated in the sequence.\n\n\n\tFor example, the sequence ... | [
{
"hash": -32474176794690404,
"runtime": "26ms",
"solution": "class RLEIterator:\n\n def __init__(self, encoding):\n \"\"\"\n :type encoding: List[int]\n \"\"\"\n self.encoding = encoding\n self.startidx = 0\n\n def next(self, n):\n \"\"\"\n :type n... | class RLEIterator(object):
def __init__(self, encoding):
"""
:type encoding: List[int]
"""
def next(self, n):
"""
:type n: int
:rtype: int
"""
# Your RLEIterator object will be instantiated and called as such:
# obj = RLEIterator(enco... | None | None | None | None | None | None | 59.4 | Level 2 | Hi |
my-calendar-i | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a <strong>double booking</strong>.</p>\n\n<p>A <strong>double booking</strong> happens when two events have some non... | 729 | Medium | [
"You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking.\n\nA double booking happens when two events have some non-empty intersection (i.e., some moment is common to both events.).\n\nThe event can be represented as a pair of integers start... | [
{
"hash": -5814756535899040000,
"runtime": "1008ms",
"solution": "class MyCalendar(object):\n def __init__(self):\n self.booking = {}\n\n def book(self, start, end):\n \"\"\"\n :type start: int\n :type end: int\n :rtype: bool\n \"\"\"\n for k,v in s... | class MyCalendar(object):
def __init__(self):
def book(self, start, end):
"""
:type start: int
:type end: int
:rtype: bool
"""
# Your MyCalendar object will be instantiated and called as such:
# obj = MyCalendar()
# param_1 = obj.book(start,end)
| None | None | None | None | None | None | 56.6 | Level 3 | Hi |
find-pivot-index | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>nums</code>, calculate the <strong>pivot index</strong> of this array.</p>\n\n<p>The <strong>pivot index</strong> is the index where the sum of all the numbers <strong>strictly</strong> to the left... | 724 | Easy | [
"Given an array of integers nums, calculate the pivot index of this array.\n\nThe pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right.\n\nIf the index is on the left edge of the array, then the left sum is 0... | [
{
"hash": 2574900365671780000,
"runtime": "2510ms",
"solution": "class Solution:\n def pivotIndex(self, nums: List[int]) -> int:\n length = len(nums)\n Total = sum(nums[0:])\n for i in range(length):\n left_sum = sum(nums[0:i])\n right_sum = Total - left_sum... | class Solution(object):
def pivotIndex(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 56.5 | Level 1 | Hi |
product-of-array-except-self | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code>, return <em>an array</em> <code>answer</code> <em>such that</em> <code>answer[i]</code> <em>is equal to the product of all the elements of</em> <code>nums</code> <em>except</em> <code>nums[... | 238 | Medium | [
"Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].\n\nThe product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\n\nYou must write an algorithm that runs in O(n) time and without using the division o... | [
{
"hash": 2014473496812489000,
"runtime": "76ms",
"solution": "class Solution:\n def main(nums: List[int]) -> List[int]:\n n = len(nums)\n ans = [1] * n\n for i in range(1, n):\n ans[i] = ans[i-1] * nums[i-1]\n \n postfix = 1\n for i in range(n... | class Solution(object):
def productExceptSelf(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 65.1 | Level 2 | Hi |
sum-in-a-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> 2D integer array <code>nums</code>. Initially, your score is <code>0</code>. Perform the following operations until the matrix becomes empty:</p>\n\n<ol>\n\t<li>From each row in the matri... | 2679 | Medium | [
"You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty:\n\n\n\tFrom each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen.\n\tIdentify the highest number ... | [
{
"hash": 1468499061018200600,
"runtime": "608ms",
"solution": "class Solution(object):\n def matrixSum(self, nums):\n \"\"\"\n :type nums: List[List[int]]\n :rtype: int\n \"\"\"\n ans = 0\n for i in range(len(nums)):\n nums[i] = sorted(nums[i])\n ... | class Solution(object):
def matrixSum(self, nums):
"""
:type nums: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 58.8 | Level 3 | Hi |
final-prices-with-a-special-discount-in-a-shop | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>prices</code> where <code>prices[i]</code> is the price of the <code>i<sup>th</sup></code> item in a shop.</p>\n\n<p>There is a special discount for items in the shop. If you buy the <code>i<su... | 1475 | Easy | [
"You are given an integer array prices where prices[i] is the price of the ith item in a shop.\n\nThere is a special discount for items in the shop. If you buy the ith item, then you will receive a discount equivalent to prices[j] where j is the minimum index such that j > i and prices[j] <= prices[i]. Otherwise, y... | [
{
"hash": -2641630342409739300,
"runtime": "18ms",
"solution": "class Solution(object):\n def finalPrices(self, prices):\n \"\"\"\n :type prices: List[int]\n :rtype: List[int]\n \"\"\"\n stack = []\n # ans = []\n for i in range(len(prices)):\n ... | class Solution(object):
def finalPrices(self, prices):
"""
:type prices: List[int]
:rtype: List[int]
"""
| None | None | None | None | None | None | 77 | Level 1 | Hi |
knight-dialer | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>The chess knight has a <strong>unique movement</strong>, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an <strong>L</stro... | 935 | Medium | [
"The chess knight has a unique movement, it may move two squares vertically and one square horizontally, or two squares horizontally and one square vertically (with both forming the shape of an L). The possible movements of chess knight are shown in this diagaram:\n\nA chess knight can move as indicated in the ches... | [
{
"hash": -1043159293288392600,
"runtime": "1297ms",
"solution": "class Solution(object):\n mod = 10**9 + 7\n MOVES = [\n [4, 6],\n [6, 8],\n [7, 9],\n [4, 8],\n [0, 3, 9],\n [],\n [0, 1, 7],\n [2, 6],\n [1, 3],\n [2, 4]\n ]\... | class Solution(object):
def knightDialer(self, n):
"""
:type n: int
:rtype: int
"""
| None | None | None | None | None | None | 59.6 | Level 2 | Hi |
number-of-orders-in-the-backlog | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a 2D integer array <code>orders</code>, where each <code>orders[i] = [price<sub>i</sub>, amount<sub>i</sub>, orderType<sub>i</sub>]</code> denotes that <code>amount<sub>i</sub></code><sub> </sub>orders have been plac... | 1801 | Medium | [
"You are given a 2D integer array orders, where each orders[i] = [pricei, amounti, orderTypei] denotes that amounti orders have been placed of type orderTypei at the price pricei. The orderTypei is:\n\n\n\t0 if it is a batch of buy orders, or\n\t1 if it is a batch of sell orders.\n\n\nNote that orders[i] represents... | [
{
"hash": -5486096386511783000,
"runtime": "581ms",
"solution": "class Solution(object):\n def getNumberOfBacklogOrders(self, orders):\n \"\"\"\n :type orders: List[List[int]]\n :rtype: int\n \"\"\"\n buy = []\n sell = []\n for price, amount, orderType... | class Solution(object):
def getNumberOfBacklogOrders(self, orders):
"""
:type orders: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 49.2 | Level 3 | Hi |
number-of-pairs-satisfying-inequality | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code>, each of size <code>n</code>, and an integer <code>diff</code>. Find the number of <strong>pairs</strong> <code>(i, j)</code> su... | 2426 | Hard | [
"You are given two 0-indexed integer arrays nums1 and nums2, each of size n, and an integer diff. Find the number of pairs (i, j) such that:\n\n\n\t0 <= i < j <= n - 1 and\n\tnums1[i] - nums1[j] <= nums2[i] - nums2[j] + diff.\n\n\nReturn the number of pairs that satisfy the conditions.\n\n \nExample 1:\n\nInput: nu... | [
{
"hash": 1808826974507059000,
"runtime": "1278ms",
"solution": "class BinaryIndexedTree:\n def __init__(self, n):\n self.n = n\n self.c = [0] * (n + 1)\n\n @staticmethod\n def lowbit(x):\n return x & -x\n\n def update(self, x, delta):\n x += 40000\n while ... | class Solution(object):
def numberOfPairs(self, nums1, nums2, diff):
"""
:type nums1: List[int]
:type nums2: List[int]
:type diff: int
:rtype: int
"""
| None | None | None | None | None | None | 43.4 | Level 5 | Hi |
shortest-path-visiting-all-nodes | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You have an undirected, connected graph of <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>. You are given an array <code>graph</code> where <code>graph[i]</code> is a list of all the nodes connected with nod... | 847 | Hard | [
"You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.\n\nReturn the length of the shortest path that visits every node. You may start and stop at any node, you may revisit nodes multiple t... | [
{
"hash": 8503943285135236000,
"runtime": "138ms",
"solution": "class Solution(object):\n def shortestPathLength(self, graph):\n \"\"\"\n :type graph: List[List[int]]\n :rtype: int\n \"\"\"\n n = len(graph)\n if n == 1:\n return 0\n \n ... | class Solution(object):
def shortestPathLength(self, graph):
"""
:type graph: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 65.9 | Level 5 | Hi |
maximum-ice-cream-bars | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>It is a sweltering summer day, and a boy wants to buy some ice cream bars.</p>\n\n<p>At the store, there are <code>n</code> ice cream bars. You are given an array <code>costs</code> of length <code>n</code>, where <code>costs[i]</... | 1833 | Medium | [
"It is a sweltering summer day, and a boy wants to buy some ice cream bars.\n\nAt the store, there are n ice cream bars. You are given an array costs of length n, where costs[i] is the price of the ith ice cream bar in coins. The boy initially has coins coins to spend, and he wants to buy as many ice cream bars as ... | [
{
"hash": -8314839198773169000,
"runtime": "639ms",
"solution": "class Solution(object):\n def maxIceCream(self, costs, coins):\n \"\"\"\n :type costs: List[int]\n :type coins: int\n :rtype: int\n \"\"\"\n\n costs.sort()\n buy = 0\n for price in... | class Solution(object):
def maxIceCream(self, costs, coins):
"""
:type costs: List[int]
:type coins: int
:rtype: int
"""
| None | None | None | None | None | None | 73.8 | Level 2 | Hi |
magic-squares-in-grid | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A <code>3 x 3</code> magic square is a <code>3 x 3</code> grid filled with distinct numbers <strong>from </strong><code>1</code><strong> to </strong><code>9</code> such that each row, column, and both diagonals all have the same s... | 840 | Medium | [
"A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum.\n\nGiven a row x col grid of integers, how many 3 x 3 \"magic square\" subgrids are there? (Each subgrid is contiguous).\n\n \nExample 1:\n\nInput: grid = [[4,3,8,4],... | [
{
"hash": 1828501053616106500,
"runtime": "20ms",
"solution": "class Solution:\n def numMagicSquaresInside(self, grid):\n\n def func(i,j):\n if sum(grid[i][j:j+3])==sum(grid[i+1][j:j+3])==sum(grid[i+2][j:j+3]):\n tmp = sum(grid[i][j:j+3])\n if tmp == gr... | class Solution(object):
def numMagicSquaresInside(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 38.8 | Level 4 | Hi |
1-bit-and-2-bit-characters | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>We have two special characters:</p>\n\n<ul>\n\t<li>The first character can be represented by one bit <code>0</code>.</li>\n\t<li>The second character can be represented by two bits (<code>10</code> or <code>11</code>).</li>\n</ul>... | 717 | Easy | [
"We have two special characters:\n\n\n\tThe first character can be represented by one bit 0.\n\tThe second character can be represented by two bits (10 or 11).\n\n\nGiven a binary array bits that ends with 0, return true if the last character must be a one-bit character.\n\n \nExample 1:\n\nInput: bits = [1,0,0]\nO... | [
{
"hash": -6273288095471998000,
"runtime": "30ms",
"solution": "class Solution(object):\n def isOneBitCharacter(self, bits):\n \"\"\"\n :type bits: List[int]\n :rtype: bool\n \"\"\"\n ret = True\n for bit in bits[-2::-1]:\n if bit: ret = not ret\n ... | class Solution(object):
def isOneBitCharacter(self, bits):
"""
:type bits: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 45.2 | Level 1 | Hi |
smallest-missing-non-negative-integer-after-operations | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>value</code>.</p>\n\n<p>In one operation, you can add or subtract <code>value</code> from any element of <code>nums</code>.</p>\n\n<ul... | 2598 | Medium | [
"You are given a 0-indexed integer array nums and an integer value.\n\nIn one operation, you can add or subtract value from any element of nums.\n\n\n\tFor example, if nums = [1,2,3] and value = 2, you can choose to subtract value from nums[0] to make nums = [-1,2,3].\n\n\nThe MEX (minimum excluded) of an array is ... | [
{
"hash": 6530347228377335000,
"runtime": "797ms",
"solution": "class Solution(object):\n def findSmallestInteger(self, nums, value):\n \"\"\"\n :type nums: List[int]\n :type value: int\n :rtype: int\n \"\"\"\n count = Counter(num % value for num in nums)\n ... | class Solution(object):
def findSmallestInteger(self, nums, value):
"""
:type nums: List[int]
:type value: int
:rtype: int
"""
| None | None | None | None | None | None | 38.8 | Level 4 | Hi |
total-cost-to-hire-k-workers | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>costs</code> where <code>costs[i]</code> is the cost of hiring the <code>i<sup>th</sup></code> worker.</p>\n\n<p>You are also given two integers <code>k</code> and <co... | 2462 | Medium | [
"You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker.\n\nYou are also given two integers k and candidates. We want to hire exactly k workers according to the following rules:\n\n\n\tYou will run k sessions and hire exactly one worker in each session.\n\tIn each hiring s... | [
{
"hash": 1787385319428078300,
"runtime": "1227ms",
"solution": "import heapq\n\nclass Solution(object):\n def totalCost(self, costs, k, candidates):\n \"\"\"\n :type costs: List[int]\n :type k: int\n :type candidates: int\n :rtype: int\n \"\"\"\n cost... | class Solution(object):
def totalCost(self, costs, k, candidates):
"""
:type costs: List[int]
:type k: int
:type candidates: int
:rtype: int
"""
| None | None | None | None | None | None | 43.9 | Level 4 | Hi |
score-after-flipping-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>\n\n<p>A <strong>move</strong> consists of choosing any row or column and toggling each value in that row or column (i.e., changing all <code>0</code>'s t... | 861 | Medium | [
"You are given an m x n binary matrix grid.\n\nA move consists of choosing any row or column and toggling each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).\n\nEvery row of the matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers.\n\nRe... | [
{
"hash": 6151558070006726000,
"runtime": "39ms",
"solution": "class Solution:\n def matrixScore(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n print(5//2)\n def flip_row(r):\n for c in range(n):\n grid[r][c] = 1 - grid[r][c]\n ... | class Solution(object):
def matrixScore(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 74.9 | Level 2 | Hi |
neither-minimum-nor-maximum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code> containing <strong>distinct</strong> <strong>positive</strong> integers, find and return <strong>any</strong> number from the array that is neither the <strong>minimum</strong> nor the <str... | 2733 | Easy | [
"Given an integer array nums containing distinct positive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number.\n\nReturn the selected integer.\n\n \nExample 1:\n\nInput: nums = [3,2,1,4]\nOutput: 2\nExplanation: In this... | [
{
"hash": 2699286151329768000,
"runtime": "289ms",
"solution": "class Solution:\n def findNonMinOrMax(self, nums):\n nums.sort()\n if len(nums) > 2:\n return nums[1]\n else:\n return -1"
},
{
"hash": 7139922886470540000,
"runtime": "305ms",
"... | class Solution(object):
def findNonMinOrMax(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 76.7 | Level 1 | Hi |
maximum-product-of-the-length-of-two-palindromic-subsequences | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code>, find two <strong>disjoint palindromic subsequences</strong> of <code>s</code> such that the <strong>product</strong> of their lengths is <strong>maximized</strong>. The two subsequences are <strong>d... | 2002 | Medium | [
"Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index.\n\nReturn the maximum possible product of the lengths of the two palindromic subsequences.\n\nA subsequenc... | [
{
"hash": 912175283001396500,
"runtime": "3137ms",
"solution": "class Solution(object):\n def maxProduct(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n\n self.maxProduct = 0\n\n def backtrack(subOne, subTwo, index):\n if index >= len(s)... | class Solution(object):
def maxProduct(self, s):
"""
:type s: str
:rtype: int
"""
| None | None | None | None | None | None | 57.5 | Level 3 | Hi |
n-repeated-element-in-size-2n-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code> with the following properties:</p>\n\n<ul>\n\t<li><code>nums.length == 2 * n</code>.</li>\n\t<li><code>nums</code> contains <code>n + 1</code> <strong>unique</strong> elements.</li>... | 961 | Easy | [
"You are given an integer array nums with the following properties:\n\n\n\tnums.length == 2 * n.\n\tnums contains n + 1 unique elements.\n\tExactly one element of nums is repeated n times.\n\n\nReturn the element that is repeated n times.\n\n \nExample 1:\nInput: nums = [1,2,3,3]\nOutput: 3\nExample 2:\nInput: nums... | [
{
"hash": 1619412927568574000,
"runtime": "194ms",
"solution": "class Solution:\n def repeatedNTimes(self, nums: List[int]) -> int:\n n = len(nums) // 2\n book = defaultdict(int)\n for ans in nums:\n book[ans] += 1\n if book[ans] == n:\n retur... | class Solution(object):
def repeatedNTimes(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 76.4 | Level 1 | Hi |
bulb-switcher-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a room with <code>n</code> bulbs labeled from <code>1</code> to <code>n</code> that all are turned on initially, and <strong>four buttons</strong> on the wall. Each of the four buttons has a different functionality where:... | 672 | Medium | [
"There is a room with n bulbs labeled from 1 to n that all are turned on initially, and four buttons on the wall. Each of the four buttons has a different functionality where:\n\n\n\tButton 1: Flips the status of all the bulbs.\n\tButton 2: Flips the status of all the bulbs with even labels (i.e., 2, 4, ...).\n\tBu... | [
{
"hash": -1961112970544776700,
"runtime": "8ms",
"solution": "class Solution(object):\n def flipLights(self, n, presses):\n \"\"\"\n :type n: int\n :type presses: int\n :rtype: int\n \"\"\"\n k=presses\n if(k == 0):\n return 1\n if(n... | class Solution(object):
def flipLights(self, n, presses):
"""
:type n: int
:type presses: int
:rtype: int
"""
| None | None | None | None | None | None | 50.2 | Level 3 | Hi |
minimum-sum-of-four-digit-number-after-splitting-digits | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>positive</strong> integer <code>num</code> consisting of exactly four digits. Split <code>num</code> into two new integers <code>new1</code> and <code>new2</code> by using the <strong>digits</strong> found ... | 2160 | Easy | [
"You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.\n\n\n\tFor example, given num = 2932, you have the following digits: two ... | [
{
"hash": 4008385482091865600,
"runtime": "19ms",
"solution": "class Solution(object):\n def minimumSum(self, num):\n l=[int(i) for i in str(num)]\n l.sort()\n return int((str(l[0])+str(l[2]))) + int((str(l[1])+str(l[3])))\n "
},
{
"hash": 1073823777369067300,
... | class Solution(object):
def minimumSum(self, num):
"""
:type num: int
:rtype: int
"""
| None | None | None | None | None | None | 86.2 | Level 1 | Hi |
subarray-sums-divisible-by-k | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <em>the number of non-empty <strong>subarrays</strong> that have a sum divisible by </em><code>k</code>.</p>\n\n<p>A <strong>subarray</strong> is a <st... | 974 | Medium | [
"Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.\n\nA subarray is a contiguous part of an array.\n\n \nExample 1:\n\nInput: nums = [4,5,0,-2,-3,1], k = 5\nOutput: 7\nExplanation: There are 7 subarrays with a sum divisible by k = 5:\n[4, 5, 0, -2... | [
{
"hash": -2390305071371962000,
"runtime": "279ms",
"solution": "class Solution(object):\n def subarraysDivByK(self, nums, k):\n prefix=[nums[0]]\n for i in range(1,len(nums)):\n prefix.append(prefix[i-1]+nums[i])\n d={0:0}\n c=0\n print(prefix)\n ... | class Solution(object):
def subarraysDivByK(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 53.9 | Level 3 | Hi |
decode-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an encoded string, return its decoded string.</p>\n\n<p>The encoding rule is: <code>k[encoded_string]</code>, where the <code>encoded_string</code> inside the square brackets is being repeated exactly <code>k</code> times. N... | 394 | Medium | [
"Given an encoded string, return its decoded string.\n\nThe encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.\n\nYou may assume that the input string is always valid; there are no extra whit... | [
{
"hash": 8334345433460564000,
"runtime": "44ms",
"solution": "class Solution:\n def decodeString(self, s: str) -> str:\n stack = []; curNum = 0; curString = ''\n for c in s:\n if c == '[':\n stack.append(curString)\n stack.append(curNum)\n ... | class Solution(object):
def decodeString(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 58.7 | Level 3 | Hi |
max-area-of-island | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <code>m x n</code> binary matrix <code>grid</code>. An island is a group of <code>1</code>'s (representing land) connected <strong>4-directionally</strong> (horizontal or vertical.) You may assume all four edg... | 695 | Medium | [
"You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.\n\nThe area of an island is the number of cells with a value 1 in the island.\n\nReturn the maximum area ... | [
{
"hash": -8669217210017738000,
"runtime": "169ms",
"solution": "import numpy as np\n\nclass Solution(object):\n def maxAreaOfIsland(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: int\n \"\"\"\n m = len(grid)\n n = len(grid[0])\n \n ... | class Solution(object):
def maxAreaOfIsland(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 71.9 | Level 2 | Hi |
form-largest-integer-with-digits-that-add-up-to-target | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>cost</code> and an integer <code>target</code>, return <em>the <strong>maximum</strong> integer you can paint under the following rules</em>:</p>\n\n<ul>\n\t<li>The cost of painting a digit <code>(... | 1449 | Hard | [
"Given an array of integers cost and an integer target, return the maximum integer you can paint under the following rules:\n\n\n\tThe cost of painting a digit (i + 1) is given by cost[i] (0-indexed).\n\tThe total cost used must be equal to target.\n\tThe integer does not have 0 digits.\n\n\nSince the answer may be... | [
{
"hash": -6356832323435200000,
"runtime": "168ms",
"solution": "class Solution(object):\n def largestNumber(self, cost, target):\n \"\"\"\n :type cost: List[int]\n :type target: int\n :rtype: str\n \"\"\"\n dp = [0] + [-1] * target\n for t in range(1,... | class Solution(object):
def largestNumber(self, cost, target):
"""
:type cost: List[int]
:type target: int
:rtype: str
"""
| None | None | None | None | None | None | 47.9 | Level 5 | Hi |
minimum-total-space-wasted-with-k-resizing-operations | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are currently designing a dynamic array. You are given a <strong>0-indexed</strong> integer array <code>nums</code>, where <code>nums[i]</code> is the number of elements that will be in the array at time <code>i</code>. In add... | 1959 | Medium | [
"You are currently designing a dynamic array. You are given a 0-indexed integer array nums, where nums[i] is the number of elements that will be in the array at time i. In addition, you are given an integer k, the maximum number of times you can resize the array (to any size).\n\nThe size of the array at time t, si... | [
{
"hash": 2838511811178706400,
"runtime": "4279ms",
"solution": "class Solution(object):\n def minSpaceWastedKResizing(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: int\n \"\"\"\n n = len(nums)\n dp = [[-1]*(k+1) for _ in ra... | class Solution(object):
def minSpaceWastedKResizing(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 42.6 | Level 4 | Hi |
minimum-operations-to-reduce-x-to-zero | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code> and an integer <code>x</code>. In one operation, you can either remove the leftmost or the rightmost element from the array <code>nums</code> and subtract its value from <code>x</co... | 1658 | Medium | [
"You are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array nums and subtract its value from x. Note that this modifies the array for future operations.\n\nReturn the minimum number of operations to reduce x to exactly 0 if it i... | [
{
"hash": -5855620752167456000,
"runtime": "1229ms",
"solution": "class Solution(object):\n def minOperations(self, nums, x):\n \"\"\"\n :type nums: List[int]\n :type x: int\n :rtype: int\n \"\"\"\n n = len(nums)\n res = float('Inf')\n right = [... | class Solution(object):
def minOperations(self, nums, x):
"""
:type nums: List[int]
:type x: int
:rtype: int
"""
| None | None | None | None | None | None | 39.8 | Level 4 | Hi |
binary-tree-cameras | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given the <code>root</code> of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.</p>\n\n<p>Return <em>the minimum number of cameras ... | 968 | Hard | [
"You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.\n\nReturn the minimum number of cameras needed to monitor all nodes of the tree.\n\n \nExample 1:\n\nInput: root = [0,0,null,0,0]\nOutput: 1\nExplana... | [
{
"hash": 2790075976828360700,
"runtime": "16ms",
"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 mi... | # 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 minCameraCover(self, root):
"""
:type root: TreeNode
:rtype: int... | None | None | None | None | None | None | 46.5 | Level 5 | Hi |
partition-array-according-to-given-pivot | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>pivot</code>. Rearrange <code>nums</code> such that the following conditions are satisfied:</p>\n\n<ul>\n\t<li>Every element less than... | 2161 | Medium | [
"You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:\n\n\n\tEvery element less than pivot appears before every element greater than pivot.\n\tEvery element equal to pivot appears in between the elements less than and greater than pivot.... | [
{
"hash": -6733071753004351000,
"runtime": "998ms",
"solution": "class Solution(object):\n def pivotArray(self, nums, pivot):\n \"\"\"\n :type nums: List[int]\n :type pivot: int\n :rtype: List[int]\n \"\"\"\n # O(n) to find numbers < pivot\n res = [n f... | class Solution(object):
def pivotArray(self, nums, pivot):
"""
:type nums: List[int]
:type pivot: int
:rtype: List[int]
"""
| None | None | None | None | None | None | 84.7 | Level 2 | Hi |
compare-strings-by-frequency-of-the-smallest-character | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Let the function <code>f(s)</code> be the <strong>frequency of the lexicographically smallest character</strong> in a non-empty string <code>s</code>. For example, if <code>s = "dcce"</code> then <code>f(s) = 2</code> be... | 1170 | Medium | [
"Let the function f(s) be the frequency of the lexicographically smallest character in a non-empty string s. For example, if s = \"dcce\" then f(s) = 2 because the lexicographically smallest character is 'c', which has a frequency of 2.\n\nYou are given an array of strings words and another array of query strings q... | [
{
"hash": 3130465109248622000,
"runtime": "47ms",
"solution": "class Solution(object):\n def frequency(self, word):\n mini = \"z\"\n ans = 0\n for sym in word:\n if sym < mini:\n mini = sym\n ans = 1\n elif sym == mini:\n ... | class Solution(object):
def numSmallerByFrequency(self, queries, words):
"""
:type queries: List[str]
:type words: List[str]
:rtype: List[int]
"""
| None | None | None | None | None | None | 61.8 | Level 2 | Hi |
check-if-a-string-is-an-acronym-of-words | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of strings <code>words</code> and a string <code>s</code>, determine if <code>s</code> is an <strong>acronym</strong> of words.</p>\n\n<p>The string <code>s</code> is considered an acronym of <code>words</code> if i... | 2828 | Easy | [
"Given an array of strings words and a string s, determine if s is an acronym of words.\n\nThe string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, \"ab\" can be formed from [\"apple\", \"banana\"], but it can't be formed ... | [
{
"hash": 7452387928815736000,
"runtime": "15ms",
"solution": "class Solution(object):\n def isAcronym(self, words, s):\n \"\"\"\n :type words: List[str]\n :type s: str\n :rtype: bool\n \"\"\"\n l=[]\n for i in words[:]:\n nex=i[0]\n ... | class Solution(object):
def isAcronym(self, words, s):
"""
:type words: List[str]
:type s: str
:rtype: bool
"""
| None | None | None | None | None | None | 82.9 | Level 1 | Hi |
minimum-number-of-operations-to-reinitialize-a-permutation | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an <strong>even</strong> integer <code>n</code>. You initially have a permutation <code>perm</code> of size <code>n</code> where <code>perm[i] == i</code> <strong>(0-indexed)</strong>.</p>\n\n<p>In one o... | 1806 | Medium | [
"You are given an even integer n. You initially have a permutation perm of size n where perm[i] == i (0-indexed).\n\nIn one operation, you will create a new array arr, and for each i:\n\n\n\tIf i % 2 == 0, then arr[i] = perm[i / 2].\n\tIf i % 2 == 1, then arr[i] = perm[n / 2 + (i - 1) / 2].\n\n\nYou wi... | [
{
"hash": -5215602312256308000,
"runtime": "363ms",
"solution": "class Solution(object):\n def reinitializePermutation(self, n):\n perm = range(n)\n arr = [0] * n\n operations = 0\n \n while True:\n for i in range(n):\n if i % 2 == 0:\n ... | class Solution(object):
def reinitializePermutation(self, n):
"""
:type n: int
:rtype: int
"""
| None | None | None | None | None | None | 72.3 | Level 2 | Hi |
can-make-palindrome-from-substring | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code> and array <code>queries</code> where <code>queries[i] = [left<sub>i</sub>, right<sub>i</sub>, k<sub>i</sub>]</code>. We may rearrange the substring <code>s[left<sub>i</sub>...right<sub>i</sub>... | 1177 | Medium | [
"You are given a string s and array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English letter.\n\nIf the substring is possible to be a palindrome string after the operations above, the... | [
{
"hash": 6345343467544918000,
"runtime": "1858ms",
"solution": "class Solution(object):\n def canMakePaliQueries(self, s, queries):\n \"\"\"\n :type s: str\n :type queries: List[List[int]]\n :rtype: List[bool]\n \"\"\"\n \n freq = [0 for _ in range(26... | class Solution(object):
def canMakePaliQueries(self, s, queries):
"""
:type s: str
:type queries: List[List[int]]
:rtype: List[bool]
"""
| None | None | None | None | None | None | 38.7 | Level 4 | Hi |
dice-roll-simulation | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>A die simulator generates a random number from <code>1</code> to <code>6</code> for each roll. You introduced a constraint to the generator such that it cannot roll the number <code>i</code> more than <code>rollMax[i]</code> (<str... | 1223 | Hard | [
"A die simulator generates a random number from 1 to 6 for each roll. You introduced a constraint to the generator such that it cannot roll the number i more than rollMax[i] (1-indexed) consecutive times.\n\nGiven an array of integers rollMax and an integer n, return the number of distinct sequences that can be obt... | [
{
"hash": -2469549811527595500,
"runtime": "302ms",
"solution": "class Solution(object):\n def dieSimulator(self, n, rollMax):\n\n mod=10**9+7\n dp=[[0]*6 for _ in range(n+1)]\n dp[1]=[1]*6\n for i in range(2, n+1):\n for j in range(6):\n dp[i][j]... | class Solution(object):
def dieSimulator(self, n, rollMax):
"""
:type n: int
:type rollMax: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 48.8 | Level 5 | Hi |
min-cost-climbing-stairs | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>cost</code> where <code>cost[i]</code> is the cost of <code>i<sup>th</sup></code> step on a staircase. Once you pay the cost, you can either climb one or two steps.</p>\n\n<p>You can either sta... | 746 | Easy | [
"You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.\n\nYou can either start from the step with index 0, or the step with index 1.\n\nReturn the minimum cost to reach the top of the floor.\n\n \nExample 1:\n\nInput: ... | [
{
"hash": 4955757122769531000,
"runtime": "24ms",
"solution": "class Solution(object):\n def minCostClimbingStairs(self, cost):\n \"\"\"\n :type cost: List[int]\n :rtype: int\n \"\"\"\n n = len(cost)\n\n dp = [0] * (n)\n\n def helper(n):\n i... | class Solution(object):
def minCostClimbingStairs(self, cost):
"""
:type cost: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 65.2 | Level 1 | Hi |
maximum-average-subarray-i | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code> consisting of <code>n</code> elements, and an integer <code>k</code>.</p>\n\n<p>Find a contiguous subarray whose <strong>length is equal to</strong> <code>k</code> that has the maxi... | 643 | Easy | [
"You are given an integer array nums consisting of n elements, and an integer k.\n\nFind a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calculation error less than 10-5 will be accepted.\n\n \nExample 1:\n\nInput: nums = [1,12,-5,-6,50,3]... | [
{
"hash": -9090883330319423000,
"runtime": "967ms",
"solution": "class Solution(object):\n def findMaxAverage(self, nums, k):\n \"\"\"\n :type nums: List[int]\n :type k: int\n :rtype: float\n s=float(sum(nums[:k]))\n res=s\n for i in range(len(nums)-k)... | class Solution(object):
def findMaxAverage(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: float
"""
| None | None | None | None | None | None | 43.1 | Level 1 | Hi |
stone-game-vi | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Alice and Bob take turns playing a game, with Alice starting first.</p>\n\n<p>There are <code>n</code> stones in a pile. On each player's turn, they can <strong>remove</strong> a stone from the pile and receive points based on... | 1686 | Medium | [
"Alice and Bob take turns playing a game, with Alice starting first.\n\nThere are n stones in a pile. On each player's turn, they can remove a stone from the pile and receive points based on the stone's value. Alice and Bob may value the stones differently.\n\nYou are given two integer arrays of length n, aliceValu... | [
{
"hash": 8895784491561680000,
"runtime": "991ms",
"solution": "\nclass Solution(object):\n def stoneGameVI(self, aliceValues, bobValues):\n \"\"\"\n :type aliceValues: List[int]\n :type bobValues: List[int]\n :rtype: int\n \"\"\"\n \n n = len(aliceVal... | class Solution(object):
def stoneGameVI(self, aliceValues, bobValues):
"""
:type aliceValues: List[int]
:type bobValues: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 56.2 | Level 3 | Hi |
disconnect-path-in-a-binary-matrix-by-at-most-one-flip | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a <strong>0-indexed</strong> <code>m x n</code> <strong>binary</strong> matrix <code>grid</code>. You can move from a cell <code>(row, col)</code> to any of the cells <code>(row + 1, col)</code> or <code>(row, col + ... | 2556 | Medium | [
"You are given a 0-indexed m x n binary matrix grid. You can move from a cell (row, col) to any of the cells (row + 1, col) or (row, col + 1) that has the value 1. The matrix is disconnected if there is no path from (0, 0) to (m - 1, n - 1).\n\nYou can flip the value of at most one (possibly none) cell. You cannot ... | [
{
"hash": -6283370115263034000,
"runtime": "715ms",
"solution": "class Solution(object):\n def isPossibleToCutPath(self, grid):\n \"\"\"\n :type grid: List[List[int]]\n :rtype: bool\n \"\"\"\n m, n = len(grid), len(grid[0])\n if m == 1 and n == 2:\n ... | class Solution(object):
def isPossibleToCutPath(self, grid):
"""
:type grid: List[List[int]]
:rtype: bool
"""
| None | None | None | None | None | None | 27.3 | Level 4 | Hi |
minimum-flips-to-make-a-or-b-equal-to-c | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given 3 positives numbers <code>a</code>, <code>b</code> and <code>c</code>. Return the minimum flips required in some bits of <code>a</code> and <code>b</code> to make ( <code>a</code> OR <code>b</code> == <code>c</code>&nbs... | 1318 | Medium | [
"Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).\nFlip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation.\n\n \nExample 1:\n\n\n\nInput: a = 2, b = 6, c = 5\nOutp... | [
{
"hash": -6186041273935092000,
"runtime": "6ms",
"solution": "class Solution(object):\n def minFlips(self, a, b, c):\n \"\"\"\n :type a: int\n :type b: int\n :type c: int\n :rtype: int\n \"\"\"\n ans = 0\n while a or b or c:\n x1 = a... | class Solution(object):
def minFlips(self, a, b, c):
"""
:type a: int
:type b: int
:type c: int
:rtype: int
"""
| None | None | None | None | None | None | 71.2 | Level 2 | Hi |
partition-array-into-two-arrays-to-minimize-sum-difference | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer array <code>nums</code> of <code>2 * n</code> integers. You need to partition <code>nums</code> into <strong>two</strong> arrays of length <code>n</code> to <strong>minimize the absolute difference</strong... | 2035 | Hard | [
"You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.\n\nReturn the minimum possible absolute difference.\n\n \nExample 1:\n... | [
{
"hash": 3842321218845645300,
"runtime": "2141ms",
"solution": "class Solution(object):\n def minimumDifference(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n N = len(nums) // 2 \n \n def get_sums(nums):\n ans = {}\n... | class Solution(object):
def minimumDifference(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 19.6 | Level 5 | Hi |
4sum-ii | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given four integer arrays <code>nums1</code>, <code>nums2</code>, <code>nums3</code>, and <code>nums4</code> all of length <code>n</code>, return the number of tuples <code>(i, j, k, l)</code> such that:</p>\n\n<ul>\n\t<li><code>0... | 454 | Medium | [
"Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that:\n\n\n\t0 <= i, j, k, l < n\n\tnums1[i] + nums2[j] + nums3[k] + nums4[l] == 0\n\n\n \nExample 1:\n\nInput: nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]\nOutput: 2\nExplanati... | [
{
"hash": 7271636437655395000,
"runtime": "427ms",
"solution": "class Solution:\n def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:\n myd = collections.defaultdict(int)\n for num1 in nums1:\n for num2 in nums2:\n ... | class Solution(object):
def fourSumCount(self, nums1, nums2, nums3, nums4):
"""
:type nums1: List[int]
:type nums2: List[int]
:type nums3: List[int]
:type nums4: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 57.2 | Level 3 | Hi |
valid-mountain-array | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array of integers <code>arr</code>, return <em><code>true</code> if and only if it is a valid mountain array</em>.</p>\n\n<p>Recall that arr is a mountain array if and only if:</p>\n\n<ul>\n\t<li><code>arr.length >= 3<... | 941 | Easy | [
"Given an array of integers arr, return true if and only if it is a valid mountain array.\n\nRecall that arr is a mountain array if and only if:\n\n\n\tarr.length >= 3\n\tThere exists some i with 0 < i < arr.length - 1 such that:\n\t\n\t\tarr[0] < arr[1] < ... < arr[i - 1] < arr[i] \n\t\tarr[i] > arr[i + 1] > ... >... | [
{
"hash": -1259584258829330000,
"runtime": "138ms",
"solution": "class Solution(object):\n def validMountainArray(self, arr):\n \"\"\"\n :type arr: List[int]\n :rtype: bool\n \"\"\"\n if len(arr) < 3:\n return False\n i = 1\n while (i < len(... | class Solution(object):
def validMountainArray(self, arr):
"""
:type arr: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 33.3 | Level 1 | Hi |
maximum-score-from-performing-multiplication-operations | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums</code> and <code>multipliers</code><strong> </strong>of size <code>n</code> and <code>m</code> respectively, where <code>n >= m</code>.</p>\n\n<p>You begin ... | 1770 | Hard | [
"You are given two 0-indexed integer arrays nums and multipliers of size n and m respectively, where n >= m.\n\nYou begin with a score of 0. You want to perform exactly m operations. On the ith operation (0-indexed) you will:\n\n\n Choose one integer x from either the start or the end of the array nums.\n Add... | [
{
"hash": -2136109046010802200,
"runtime": "851ms",
"solution": "class Solution(object):\n def maximumScore(self, nums, multipliers):\n \"\"\"\n :type nums: List[int]\n :type multipliers: List[int]\n :rtype: int\n \"\"\"\n m, n = len(multipliers), len(nums)\n... | class Solution(object):
def maximumScore(self, nums, multipliers):
"""
:type nums: List[int]
:type multipliers: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 39.1 | Level 5 | Hi |
find-numbers-with-even-number-of-digits | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given an array <code>nums</code> of integers, return how many of them contain an <strong>even number</strong> of digits.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> ... | 1295 | Easy | [
"Given an array nums of integers, return how many of them contain an even number of digits.\n\n \nExample 1:\n\nInput: nums = [12,345,2,6,7896]\nOutput: 2\nExplanation: \n12 contains 2 digits (even number of digits). \n345 contains 3 digits (odd number of digits). \n2 contains 1 digit (odd number of digits). \n6 co... | [
{
"hash": -8067216564442097000,
"runtime": "18ms",
"solution": "class Solution(object):\n def findNumbers(self, nums):\n s=0\n for n in nums:\n if len(str(n))%2==0:\n s+=1\n return s"
},
{
"hash": 3168470007852239000,
"runtime": "26ms",
"... | class Solution(object):
def findNumbers(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 77 | Level 1 | Hi |
cells-with-odd-values-in-a-matrix | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is an <code>m x n</code> matrix that is initialized to all <code>0</code>'s. There is also a 2D array <code>indices</code> where each <code>indices[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> represents a <strong>0-indexe... | 1252 | Easy | [
"There is an m x n matrix that is initialized to all 0's. There is also a 2D array indices where each indices[i] = [ri, ci] represents a 0-indexed location to perform some increment operations on the matrix.\n\nFor each location indices[i], do both of the following:\n\n\n\tIncrement all the cells on row ri.\n\tIncr... | [
{
"hash": -684862740025247500,
"runtime": "35ms",
"solution": "class Solution(object):\n def oddCells(self, m, n, indices):\n ans=0\n matrix=[[0]*n for i in range(m)]\n for i,j in indices:\n for x in range(m):\n matrix[x][j]+=1\n for y in rang... | class Solution(object):
def oddCells(self, m, n, indices):
"""
:type m: int
:type n: int
:type indices: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 78.5 | Level 1 | Hi |
stone-game | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Alice and Bob play a game with piles of stones. There are an <strong>even</strong> number of piles arranged in a row, and each pile has a <strong>positive</strong> integer number of stones <code>piles[i]</code>.</p>\n\n<p>The obje... | 877 | Medium | [
"Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].\n\nThe objective of the game is to end with the most stones. The total number of stones across all the piles is odd, so there are no ties.\n\nAlice an... | [
{
"hash": -2984000415275233300,
"runtime": "558ms",
"solution": "class Solution:\n def stoneGame(self, piles: List[int]) -> bool:\n dp = {}\n\n\n def solve(l,r,s):\n if (l,r,s) in dp:\n return dp[(l,r,s)]\n if l+1 == r:\n if s == 0:\n ... | class Solution(object):
def stoneGame(self, piles):
"""
:type piles: List[int]
:rtype: bool
"""
| None | None | None | None | None | None | 70.3 | Level 2 | Hi |
print-words-vertically | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given a string <code>s</code>. Return all the words vertically in the same order in which they appear in <code>s</code>.<br />\r\nWords are returned as a list of strings, complete with spaces when is necessary. (Tra... | 1324 | Medium | [
"Given a string s. Return all the words vertically in the same order in which they appear in s.\nWords are returned as a list of strings, complete with spaces when is necessary. (Trailing spaces are not allowed).\nEach word would be put on only one column and that in one column there will be only one word.\n\n \nEx... | [
{
"hash": -6819239365589276000,
"runtime": "12ms",
"solution": "class Solution(object):\n def printVertically(self, s):\n \"\"\"\n :type s: str\n :rtype: List[str]\n \"\"\"\n array=s.split()\n\n if len(array)==1:\n b=[]\n for i in array[... | class Solution(object):
def printVertically(self, s):
"""
:type s: str
:rtype: List[str]
"""
| None | None | None | None | None | None | 62.9 | Level 2 | Hi |
maximum-compatibility-score-sum | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is a survey that consists of <code>n</code> questions where each question's answer is either <code>0</code> (no) or <code>1</code> (yes).</p>\n\n<p>The survey was given to <code>m</code> students numbered from <code>0</c... | 1947 | Medium | [
"There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes).\n\nThe survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers of the students are represented by a 2D integer array students where students[i] is an integer ... | [
{
"hash": 8016263087254269000,
"runtime": "2420ms",
"solution": "class Solution(object):\n def maxCompatibilitySum(self, students, mentors):\n \"\"\"\n :type students: List[List[int]]\n :type mentors: List[List[int]]\n :rtype: int\n \"\"\"\n pairingPerms = pe... | class Solution(object):
def maxCompatibilitySum(self, students, mentors):
"""
:type students: List[List[int]]
:type mentors: List[List[int]]
:rtype: int
"""
| None | None | None | None | None | None | 61.8 | Level 2 | Hi |
smallest-value-of-the-rearranged-number | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an integer <code>num.</code> <strong>Rearrange</strong> the digits of <code>num</code> such that its value is <strong>minimized</strong> and it does not contain <strong>any</strong> leading zeros.</p>\n\n<p>Return <e... | 2165 | Medium | [
"You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.\n\nReturn the rearranged number with minimal value.\n\nNote that the sign of the number does not change after rearranging the digits.\n\n \nExample 1:\n\nInput: num = 310\nOutput: 1... | [
{
"hash": -1991280205770619400,
"runtime": "8ms",
"solution": "class Solution(object):\n def smallestNumber(self, num):\n if num != 0:\n digits1 = str(abs(num))\n zeros = digits1.count('0')\n if num < 0:\n return -int(''.join(sorted((x for x in d... | class Solution(object):
def smallestNumber(self, num):
"""
:type num: int
:rtype: int
"""
| None | None | None | None | None | None | 51.7 | Level 3 | Hi |
remove-all-adjacent-duplicates-in-string | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code> consisting of lowercase English letters. A <strong>duplicate removal</strong> consists of choosing two <strong>adjacent</strong> and <strong>equal</strong> letters and removing them.</p>\n\n<p... | 1047 | Easy | [
"You are given a string s consisting of lowercase English letters. A duplicate removal consists of choosing two adjacent and equal letters and removing them.\n\nWe repeatedly make duplicate removals on s until we no longer can.\n\nReturn the final string after all such duplicate removals have been made. It can be p... | [
{
"hash": -1904415273865956900,
"runtime": "57ms",
"solution": "class Solution(object):\n def removeDuplicates(self, s):\n \"\"\"\n GUNAAL M :type s: str\n :rtype: str\n \"\"\"\n l=[]\n for i in s:\n if l and l[-1]==i:\n l.pop... | class Solution(object):
def removeDuplicates(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 69.2 | Level 1 | Hi |
regions-cut-by-slashes | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>An <code>n x n</code> grid is composed of <code>1 x 1</code> squares where each <code>1 x 1</code> square consists of a <code>'/'</code>, <code>'\\'</code>, or blank space <code>' '</code>. These characters... | 959 | Medium | [
"An n x n grid is composed of 1 x 1 squares where each 1 x 1 square consists of a '/', '\\', or blank space ' '. These characters divide the square into contiguous regions.\n\nGiven the grid grid represented as a string array, return the number of regions.\n\nNote that backslash characters are escaped, so a '\\' is... | [
{
"hash": -4106066401373050000,
"runtime": "435ms",
"solution": "class Solution(object):\n def regionsBySlashes(self, grid):\n \"\"\"\n :type grid: List[str]\n :rtype: int\n \"\"\"\n n = len(grid)\n scal = 3\n\n big = [[0] * (n * scal) for i in range(n... | class Solution(object):
def regionsBySlashes(self, grid):
"""
:type grid: List[str]
:rtype: int
"""
| None | None | None | None | None | None | 69.3 | Level 2 | Hi |
groups-of-special-equivalent-strings | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given an array of strings of the same length <code>words</code>.</p>\n\n<p>In one <strong>move</strong>, you can swap any two even indexed characters or any two odd indexed characters of a string <code>words[i]</code>.</p>... | 893 | Medium | [
"You are given an array of strings of the same length words.\n\nIn one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i].\n\nTwo strings words[i] and words[j] are special-equivalent if after any number of moves, words[i] == words[j].\n\n\n\tFor example, words[... | [
{
"hash": 2523365315260897300,
"runtime": "55ms",
"solution": "class Solution(object):\n def numSpecialEquivGroups(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"\n s=[]\n for c in words:\n a=[c[i] for i in range(0,len(c),2)]... | class Solution(object):
def numSpecialEquivGroups(self, words):
"""
:type words: List[str]
:rtype: int
"""
| None | None | None | None | None | None | 71.4 | Level 2 | Hi |
maximum-path-quality-of-a-graph | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There is an <strong>undirected</strong> graph with <code>n</code> nodes numbered from <code>0</code> to <code>n - 1</code> (<strong>inclusive</strong>). You are given a <strong>0-indexed</strong> integer array <code>values</code> ... | 2065 | Hard | [
"There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. You are also given a 0-indexed 2D integer array edges, where each edges[j] = [uj, vj, timej] indicates that there is an undirected edge betwee... | [
{
"hash": 8877730513381197000,
"runtime": "1699ms",
"solution": "class Solution(object):\n def maximalPathQuality(self, values, edges, maxTime):\n \"\"\"\n :type values: List[int]\n :type edges: List[List[int]]\n :type maxTime: int\n :rtype: int\n \"\"\"\n ... | class Solution(object):
def maximalPathQuality(self, values, edges, maxTime):
"""
:type values: List[int]
:type edges: List[List[int]]
:type maxTime: int
:rtype: int
"""
| None | None | None | None | None | None | 57.8 | Level 5 | Hi |
maximum-points-after-collecting-coins-from-all-nodes | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>There exists an undirected tree rooted at node <code>0</code> with <code>n</code> nodes labeled from <code>0</code> to <code>n - 1</code>. You are given a 2D <strong>integer</strong> array <code>edges</code> of length <code>n - 1<... | 2920 | Hard | [
"There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates... | [
{
"hash": -8355527963730701000,
"runtime": "2890ms",
"solution": "# Time: O(nlogr), r = max(coins)\n# Space: O(nlogr)\n\n# dfs, memoization\nclass Solution(object):\n def maximumPoints(self, edges, coins, k):\n \"\"\"\n :type edges: List[List[int]]\n :type coins: List[int]\n ... | class Solution(object):
def maximumPoints(self, edges, coins, k):
"""
:type edges: List[List[int]]
:type coins: List[int]
:type k: int
:rtype: int
"""
| None | None | None | None | None | None | 37 | Level 5 | Hi |
construct-string-from-binary-tree | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Given the <code>root</code> of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.</p>\n\n<p>Omit all the empty parenthesis pairs that do not ... | 606 | Easy | [
"Given the root of a binary tree, construct a string consisting of parenthesis and integers from a binary tree with the preorder traversal way, and return it.\n\nOmit all the empty parenthesis pairs that do not affect the one-to-one mapping relationship between the string and the original binary tree.\n\n \nExample... | [
{
"hash": 6109509869303942000,
"runtime": "27ms",
"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 tr... | # 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 tree2str(self, root):
"""
:type root: TreeNode
:rtype: str
... | None | None | None | None | None | None | 64.9 | Level 1 | Hi |
decrypt-string-from-alphabet-to-integer-mapping | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>s</code> formed by digits and <code>'#'</code>. We want to map <code>s</code> to English lowercase characters as follows:</p>\n\n<ul>\n\t<li>Characters (<code>'a'</code> to <code>'i... | 1309 | Easy | [
"You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows:\n\n\n\tCharacters ('a' to 'i') are represented by ('1' to '9') respectively.\n\tCharacters ('j' to 'z') are represented by ('10#' to '26#') respectively.\n\n\nReturn the string formed after mapping.\n\nT... | [
{
"hash": -6144667817738436000,
"runtime": "13ms",
"solution": "class Solution(object):\n def freqAlphabets(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n # res = []\n # for i in range(len(s)):\n # if s[i] == '#':\n # del... | class Solution(object):
def freqAlphabets(self, s):
"""
:type s: str
:rtype: str
"""
| None | None | None | None | None | None | 79.6 | Level 1 | Hi |
unique-email-addresses | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>Every <strong>valid email</strong> consists of a <strong>local name</strong> and a <strong>domain name</strong>, separated by the <code>'@'</code> sign. Besides lowercase letters, the email may contain one or more <code>&#... | 929 | Easy | [
"Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.\n\n\n\tFor example, in \"alice@leetcode.com\", \"alice\" is the local name, and \"leetcode.com\" is the domain name.\n\n\nIf you add periods '.' between ... | [
{
"hash": -4527748525513302000,
"runtime": "39ms",
"solution": "class Solution(object):\n def numUniqueEmails(self, emails):\n \"\"\"\n :type emails: List[str]\n :rtype: int\n \"\"\"\n current = []\n for email in emails:\n test = email.split('@')\n... | class Solution(object):
def numUniqueEmails(self, emails):
"""
:type emails: List[str]
:rtype: int
"""
| None | None | None | None | None | None | 67 | Level 1 | Hi |
count-the-number-of-consistent-strings | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are given a string <code>allowed</code> consisting of <strong>distinct</strong> characters and an array of strings <code>words</code>. A string is <strong>consistent </strong>if all characters in the string appear in the strin... | 1684 | Easy | [
"You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.\n\nReturn the number of consistent strings in the array words.\n\n \nExample 1:\n\nInput: allowed = \"ab\", words = [\"ad\",\"bd\",\"a... | [
{
"hash": 7486008159424274000,
"runtime": "216ms",
"solution": "class Solution(object):\n def countConsistentStrings(self, allowed, words):\n \"\"\"\n :type allowed: str\n :type words: List[str]\n :rtype: int\n \"\"\"\n s=0\n for i in words:\n ... | class Solution(object):
def countConsistentStrings(self, allowed, words):
"""
:type allowed: str
:type words: List[str]
:rtype: int
"""
| None | None | None | None | None | None | 82.7 | Level 1 | Hi |
minimum-hours-of-training-to-win-a-competition | {
"data": {
"question": {
"categoryTitle": "Algorithms",
"content": "<p>You are entering a competition, and are given two <strong>positive</strong> integers <code>initialEnergy</code> and <code>initialExperience</code> denoting your initial energy and initial experience respectively.</p>\n\n<p>You are... | 2383 | Easy | [
"You are entering a competition, and are given two positive integers initialEnergy and initialExperience denoting your initial energy and initial experience respectively.\n\nYou are also given two 0-indexed integer arrays energy and experience, both of length n.\n\nYou will face n opponents in order. The energy and... | [
{
"hash": 8239331396140843000,
"runtime": "9ms",
"solution": "class Solution(object):\n def minNumberOfHours(self, initialEnergy, initialExperience, energy, experience):\n \"\"\"\n :type initialEnergy: int\n :type initialExperience: int\n :type energy: List[int]\n :... | class Solution(object):
def minNumberOfHours(self, initialEnergy, initialExperience, energy, experience):
"""
:type initialEnergy: int
:type initialExperience: int
:type energy: List[int]
:type experience: List[int]
:rtype: int
"""
| None | None | None | None | None | None | 40.9 | Level 1 | Hi |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.