task_id stringlengths 3 79 | prompt stringlengths 255 3.9k |
|---|---|
minimum-area-rectangle-ii | def minAreaFreeRect(points: List[List[int]]) -> float:
"""
You are given an array of points in the X-Y plane points where points[i] = [xi, yi].
Return the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the X and Y axes. If there is not any such rectangle, retu... |
least-operators-to-express-number | def leastOpsExpressTarget(x: int, target: int) -> int:
"""
Given a single positive integer x, we will write an expression of the form x (op1) x (op2) x (op3) x ... where each operator op1, op2, etc. is either addition, subtraction, multiplication, or division (+, -, *, or /). For example, with x = 3, we might w... |
univalued-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isUnivalTree(root: Optional[TreeNode]) -> bool:
"""
A binary tree is uni-valued if every node in the tree has the same value.
Given the... |
vowel-spellchecker | def spellchecker(wordlist: List[str], queries: List[str]) -> List[str]:
"""
Given a wordlist, we want to implement a spellchecker that converts a query word into a correct word.
For a given query word, the spell checker handles two categories of spelling mistakes:
Capitalization: If the query match... |
numbers-with-same-consecutive-differences | def numsSameConsecDiff(n: int, k: int) -> List[int]:
"""
Given two integers n and k, return an array of all the integers of length n where the difference between every two consecutive digits is k. You may return the answer in any order.
Note that the integers should not have leading zeros. Integers as 02 an... |
binary-tree-cameras | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def minCameraCover(root: Optional[TreeNode]) -> int:
"""
You are given the root of a binary tree. We install cameras on the tree nodes where ea... |
pancake-sorting | def pancakeSort(arr: List[int]) -> List[int]:
"""
Given an array of integers arr, sort the array by performing a series of pancake flips.
In one pancake flip we do the following steps:
Choose an integer k where 1 <= k <= arr.length.
Reverse the sub-array arr[0...k-1] (0-indexed).
For e... |
powerful-integers | def powerfulIntegers(x: int, y: int, bound: int) -> List[int]:
"""
Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.
An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.
You may retur... |
flip-binary-tree-to-match-preorder-traversal | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def flipMatchVoyage(root: Optional[TreeNode], voyage: List[int]) -> List[int]:
"""
You are given the root of a binary tree with n nodes, where ... |
equal-rational-numbers | def isRationalEqual(s: str, t: str) -> bool:
"""
Given two strings s and t, each of which represents a non-negative rational number, return true if and only if they represent the same number. The strings may use parentheses to denote the repeating part of the rational number.
A rational number can be repres... |
k-closest-points-to-origin | def kClosest(points: List[List[int]], k: int) -> List[List[int]]:
"""
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).
The distance between two points on the X-Y plane is the Euclidean distance (i.e., ... |
subarray-sums-divisible-by-k | def subarraysDivByK(nums: List[int], k: int) -> int:
"""
Given an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k.
A subarray is a contiguous part of an array.
Example 1:
>>> subarraysDivByK(nums = [4,5,0,-2,-3,1], k = 5)
>>>... |
odd-even-jump | def oddEvenJumps(arr: List[int]) -> int:
"""
You are given an integer array arr. From some starting index, you can make a series of jumps. The (1st, 3rd, 5th, ...) jumps in the series are called odd-numbered jumps, and the (2nd, 4th, 6th, ...) jumps in the series are called even-numbered jumps. Note that the ju... |
largest-perimeter-triangle | def largestPerimeter(nums: List[int]) -> int:
"""
Given an integer array nums, return the largest perimeter of a triangle with a non-zero area, formed from three of these lengths. If it is impossible to form any triangle of a non-zero area, return 0.
Example 1:
>>> largestPerimeter(nums = [2,1... |
squares-of-a-sorted-array | def sortedSquares(nums: List[int]) -> List[int]:
"""
Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
Example 1:
>>> sortedSquares(nums = [-4,-1,0,3,10])
>>> [0,1,9,16,100]
Explanation: After squar... |
longest-turbulent-subarray | def maxTurbulenceSize(arr: List[int]) -> int:
"""
Given an integer array arr, return the length of a maximum size turbulent subarray of arr.
A subarray is turbulent if the comparison sign flips between each adjacent pair of elements in the subarray.
More formally, a subarray [arr[i], arr[i + 1], ..., ar... |
distribute-coins-in-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def distributeCoins(root: Optional[TreeNode]) -> int:
"""
You are given the root of a binary tree with n nodes where each node in the tree has ... |
unique-paths-iii | def uniquePathsIII(grid: List[List[int]]) -> int:
"""
You are given an m x n integer array grid where grid[i][j] could be:
1 representing the starting square. There is exactly one starting square.
2 representing the ending square. There is exactly one ending square.
0 representing empty squares... |
triples-with-bitwise-and-equal-to-zero | def countTriplets(nums: List[int]) -> int:
"""
Given an integer array nums, return the number of AND triples.
An AND triple is a triple of indices (i, j, k) such that:
0 <= i < nums.length
0 <= j < nums.length
0 <= k < nums.length
nums[i] & nums[j] & nums[k] == 0, where & represents the... |
minimum-cost-for-tickets | def mincostTickets(days: List[int], costs: List[int]) -> int:
"""
You have planned some train traveling one year in advance. The days of the year in which you will travel are given as an integer array days. Each day is an integer from 1 to 365.
Train tickets are sold in three different ways:
a 1-da... |
string-without-aaa-or-bbb | def strWithout3a3b(a: int, b: int) -> str:
"""
Given two integers a and b, return any string s such that:
s has length a + b and contains exactly a 'a' letters, and exactly b 'b' letters,
The substring 'aaa' does not occur in s, and
The substring 'bbb' does not occur in s.
Example... |
sum-of-even-numbers-after-queries | def sumEvenAfterQueries(nums: List[int], queries: List[List[int]]) -> List[int]:
"""
You are given an integer array nums and an array queries where queries[i] = [vali, indexi].
For each query i, first, apply nums[indexi] = nums[indexi] + vali, then print the sum of the even values of nums.
Return an int... |
interval-list-intersections | def intervalIntersection(firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]:
"""
You are given two lists of closed intervals, firstList and secondList, where firstList[i] = [starti, endi] and secondList[j] = [startj, endj]. Each list of intervals is pairwise disjoint and in sorted order... |
vertical-order-traversal-of-a-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def verticalTraversal(root: Optional[TreeNode]) -> List[List[int]]:
"""
Given the root of a binary tree, calculate the vertical order traversal... |
smallest-string-starting-from-leaf | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def smallestFromLeaf(root: Optional[TreeNode]) -> str:
"""
You are given the root of a binary tree where each node has a value in the range [0,... |
add-to-array-form-of-integer | def addToArrayForm(num: List[int], k: int) -> List[int]:
"""
The array-form of an integer num is an array representing its digits in left to right order.
For example, for num = 1321, the array form is [1,3,2,1].
Given num, the array-form of an integer, and an integer k, return the array-form o... |
satisfiability-of-equality-equations | def equationsPossible(equations: List[str]) -> bool:
"""
You are given an array of strings equations that represent relationships between variables where each string equations[i] is of length 4 and takes one of two different forms: "xi==yi" or "xi!=yi".Here, xi and yi are lowercase letters (not necessarily diff... |
broken-calculator | def brokenCalc(startValue: int, target: int) -> int:
"""
There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:
multiply the number on display by 2, or
subtract 1 from the number on display.
Given two integers startValue and target... |
subarrays-with-k-different-integers | def subarraysWithKDistinct(nums: List[int], k: int) -> int:
"""
Given an integer array nums and an integer k, return the number of good subarrays of nums.
A good array is an array where the number of different integers in that array is exactly k.
For example, [1,2,3,1,2] has 3 different integers: 1... |
cousins-in-binary-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isCousins(root: Optional[TreeNode], x: int, y: int) -> bool:
"""
Given the root of a binary tree with unique values and the values of two d... |
rotting-oranges | def orangesRotting(grid: List[List[int]]) -> int:
"""
You are given an m x n grid where each cell can have one of three values:
0 representing an empty cell,
1 representing a fresh orange, or
2 representing a rotten orange.
Every minute, any fresh orange that is 4-directionally adjacen... |
minimum-number-of-k-consecutive-bit-flips | def minKBitFlips(nums: List[int], k: int) -> int:
"""
You are given a binary array nums and an integer k.
A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of k-bit flips require... |
number-of-squareful-arrays | def numSquarefulPerms(nums: List[int]) -> int:
"""
An array is squareful if the sum of every pair of adjacent elements is a perfect square.
Given an integer array nums, return the number of permutations of nums that are squareful.
Two permutations perm1 and perm2 are different if there is some index i s... |
find-the-town-judge | def findJudge(n: int, trust: List[List[int]]) -> int:
"""
In a town, there are n people labeled from 1 to n. There is a rumor that one of these people is secretly the town judge.
If the town judge exists, then:
The town judge trusts nobody.
Everybody (except for the town judge) trusts the town ... |
maximum-binary-tree-ii | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def insertIntoMaxTree(root: Optional[TreeNode], val: int) -> Optional[TreeNode]:
"""
A maximum tree is a tree where every node has a value grea... |
available-captures-for-rook | def numRookCaptures(board: List[List[str]]) -> int:
"""
You are given an 8 x 8 matrix representing a chessboard. There is exactly one white rook represented by 'R', some number of white bishops 'B', and some number of black pawns 'p'. Empty squares are represented by '.'.
A rook can move any number of squar... |
minimum-cost-to-merge-stones | def mergeStones(stones: List[int], k: int) -> int:
"""
There are n piles of stones arranged in a row. The ith pile has stones[i] stones.
A move consists of merging exactly k consecutive piles into one pile, and the cost of this move is equal to the total number of stones in these k piles.
Return the min... |
grid-illumination | def gridIllumination(n: int, lamps: List[List[int]], queries: List[List[int]]) -> List[int]:
"""
There is a 2D grid of size n x n where each cell of this grid has a lamp that is initially turned off.
You are given a 2D array of lamp positions lamps, where lamps[i] = [rowi, coli] indicates that the lamp at g... |
find-common-characters | def commonChars(words: List[str]) -> List[str]:
"""
Given a string array words, return an array of all characters that show up in all strings within the words (including duplicates). You may return the answer in any order.
Example 1:
>>> commonChars(words = ["bella","label","roller"])
>>> ["e",... |
check-if-word-is-valid-after-substitutions | def isValid(s: str) -> bool:
"""
Given a string s, determine if it is valid.
A string s is valid if, starting with an empty string t = "", you can transform t into s after performing the following operation any number of times:
Insert string "abc" into any position in t. More formally, t becomes tl... |
max-consecutive-ones-iii | def longestOnes(nums: List[int], k: int) -> int:
"""
Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.
Example 1:
>>> longestOnes(nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2)
>>> 6
Explanation: [1,1,1,0,0,1,1,... |
maximize-sum-of-array-after-k-negations | def largestSumAfterKNegations(nums: List[int], k: int) -> int:
"""
Given an integer array nums and an integer k, modify the array in the following way:
choose an index i and replace nums[i] with -nums[i].
You should apply this process exactly k times. You may choose the same index i multiple t... |
clumsy-factorial | def clumsy(n: int) -> int:
"""
The factorial of a positive integer n is the product of all positive integers less than or equal to n.
For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.
We make a clumsy factorial using the integers in decreasing order by swapping out the multi... |
minimum-domino-rotations-for-equal-row | def minDominoRotations(tops: List[int], bottoms: List[int]) -> int:
"""
In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)
We may rotate the ith domino, so that tops[i] and bott... |
construct-binary-search-tree-from-preorder-traversal | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def bstFromPreorder(preorder: List[int]) -> Optional[TreeNode]:
"""
Given an array of integers preorder, which represents the preorder traversa... |
complement-of-base-10-integer | def bitwiseComplement(n: int) -> int:
"""
The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.
For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2.
Given an integer... |
pairs-of-songs-with-total-durations-divisible-by-60 | def numPairsDivisibleBy60(time: List[int]) -> int:
"""
You are given a list of songs where the ith song has a duration of time[i] seconds.
Return 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... |
capacity-to-ship-packages-within-d-days | def shipWithinDays(weights: List[int], days: int) -> int:
"""
A conveyor belt has packages that must be shipped from one port to another within days days.
The ith package on the conveyor belt has a weight of weights[i]. Each day, we load the ship with packages on the conveyor belt (in the order given by wei... |
numbers-with-repeated-digits | def numDupDigitsAtMostN(n: int) -> int:
"""
Given an integer n, return the number of positive integers in the range [1, n] that have at least one repeated digit.
Example 1:
>>> numDupDigitsAtMostN(n = 20)
>>> 1
Explanation: The only positive number (<= 20) with at least 1 repeated digi... |
partition-array-into-three-parts-with-equal-sum | def canThreePartsEqualSum(arr: List[int]) -> bool:
"""
Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... + arr[i] == arr[i + 1] + arr[i + 2] +... |
best-sightseeing-pair | def maxScoreSightseeingPair(values: List[int]) -> int:
"""
You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them.
The score of a pair (i < j) of sightseeing spots is values[i] + values[j] + i -... |
smallest-integer-divisible-by-k | def smallestRepunitDivByK(k: int) -> int:
"""
Given a positive integer k, you need to find the length of the smallest positive integer n such that n is divisible by k, and n only contains the digit 1.
Return the length of n. If there is no such n, return -1.
Note: n may not fit in a 64-bit signed intege... |
binary-string-with-substrings-representing-1-to-n | def queryString(s: str, n: int) -> bool:
"""
Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.
A substring is a contiguous sequence of characters within a string.
Example 1:
... |
convert-to-base-2 | def baseNeg2(n: int) -> str:
"""
Given an integer n, return a binary string representing its representation in base -2.
Note that the returned string should not have leading zeros unless the string is "0".
Example 1:
>>> baseNeg2(n = 2)
>>> "110"
Explantion: (-2)2 + (-2)1 = 2
... |
binary-prefix-divisible-by-5 | def prefixesDivBy5(nums: List[int]) -> List[bool]:
"""
You are given a binary array nums (0-indexed).
We define xi as the number whose binary representation is the subarray nums[0..i] (from most-significant-bit to least-significant-bit).
For example, if nums = [1,0,1], then x0 = 1, x1 = 2, and x2 =... |
next-greater-node-in-linked-list | # class ListNode:
# def __init__(val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def nextLargerNodes(head: Optional[ListNode]) -> List[int]:
"""
You are given the head of a linked list with n nodes.
For each node in the list, find the value of the next greater ... |
number-of-enclaves | def numEnclaves(grid: List[List[int]]) -> int:
"""
You are given an m x n binary matrix grid, where 0 represents a sea cell and 1 represents a land cell.
A move consists of walking from one land cell to another adjacent (4-directionally) land cell or walking off the boundary of the grid.
Return the numb... |
remove-outermost-parentheses | def removeOuterParentheses(s: str) -> str:
"""
A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation.
For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings.
A valid ... |
sum-of-root-to-leaf-binary-numbers | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def sumRootToLeaf(root: Optional[TreeNode]) -> int:
"""
You are given the root of a binary tree where each node has a value 0 or 1. Each root-t... |
camelcase-matching | def camelMatch(queries: List[str], pattern: str) -> List[bool]:
"""
Given an array of strings queries and a string pattern, return a boolean array answer where answer[i] is true if queries[i] matches pattern, and false otherwise.
A query word queries[i] matches pattern if you can insert lowercase English le... |
video-stitching | def videoStitching(clips: List[List[int]], time: int) -> int:
"""
You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths.
Each video clip is described by an array clips where clips[i] = [starti, endi... |
divisor-game | def divisorGame(n: int) -> bool:
"""
Alice and Bob take turns playing a game, with Alice starting first.
Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:
Choosing any x with 0 < x < n and n % x == 0.
Replacing the number n on the c... |
maximum-difference-between-node-and-ancestor | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def maxAncestorDiff(root: Optional[TreeNode]) -> int:
"""
Given the root of a binary tree, find the maximum value v for which there exist diffe... |
longest-arithmetic-subsequence | def longestArithSeqLength(nums: List[int]) -> int:
"""
Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.
Note that:
A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the rema... |
recover-a-tree-from-preorder-traversal | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def recoverFromPreorder(traversal: str) -> Optional[TreeNode]:
"""
We run a preorder depth-first search (DFS) on the root of a binary tree.
... |
two-city-scheduling | def twoCitySchedCost(costs: List[List[int]]) -> int:
"""
A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.
Return the minimum cost to fly eve... |
matrix-cells-in-distance-order | def allCellsDistOrder(rows: int, cols: int, rCenter: int, cCenter: int) -> List[List[int]]:
"""
You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).
Return the coordinates of all cells in the matrix, sorte... |
maximum-sum-of-two-non-overlapping-subarrays | def maxSumTwoNoOverlap(nums: List[int], firstLen: int, secondLen: int) -> int:
"""
Given an integer array nums and two integers firstLen and secondLen, return the maximum sum of elements in two non-overlapping subarrays with lengths firstLen and secondLen.
The array with length firstLen could occur before o... |
moving-stones-until-consecutive | def numMovesStones(a: int, b: int, c: int) -> List[int]:
"""
There are three stones in different positions on the X-axis. You are given three integers a, b, and c, the positions of the stones.
In one move, you pick up a stone at an endpoint (i.e., either the lowest or highest position stone), and move it to... |
coloring-a-border | def colorBorder(grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:
"""
You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.
Two squares are called adjacent if they are next... |
uncrossed-lines | def maxUncrossedLines(nums1: List[int], nums2: List[int]) -> int:
"""
You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines.
We may draw connecting lines: a straight line connecting two numbers nums1[i] and n... |
escape-a-large-maze | def isEscapePossible(blocked: List[List[int]], source: List[int], target: List[int]) -> bool:
"""
There is a 1 million by 1 million grid on an XY-plane, and the coordinates of each grid square are (x, y).
We start at the source = [sx, sy] square and want to reach the target = [tx, ty] square. There is also ... |
valid-boomerang | def isBoomerang(points: List[List[int]]) -> bool:
"""
Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.
A boomerang is a set of three points that are all distinct and not in a straight line.
Example 1:
>>> isBoomer... |
binary-search-tree-to-greater-sum-tree | # class TreeNode:
# def __init__(val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def bstToGst(root: Optional[TreeNode]) -> Optional[TreeNode]:
"""
Given the root of a Binary Search Tree (BST), convert it to a Greater Tree su... |
minimum-score-triangulation-of-polygon | def minScoreTriangulation(values: List[int]) -> int:
"""
You have a convex n-sided polygon where each vertex has an integer value. You are given an integer array values where values[i] is the value of the ith vertex in clockwise order.
Polygon triangulation is a process where you divide a polygon into a set... |
moving-stones-until-consecutive-ii | def numMovesStonesII(stones: List[int]) -> List[int]:
"""
There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones.
Call a stone an endpoint stone if it has the smallest or largest position. In one move, you pick up an endpoint stone and ... |
robot-bounded-in-circle | def isRobotBounded(instructions: str) -> bool:
"""
On an infinite plane, a robot initially stands at (0, 0) and faces north. Note that:
The north direction is the positive direction of the y-axis.
The south direction is the negative direction of the y-axis.
The east direction is the positive di... |
flower-planting-with-no-adjacent | def gardenNoAdj(n: int, paths: List[List[int]]) -> List[int]:
"""
You have n gardens, labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi to garden yi. In each garden, you want to plant one of 4 types of flowers.
All gardens have at most 3 paths... |
partition-array-for-maximum-sum | def maxSumAfterPartitioning(arr: List[int], k: int) -> int:
"""
Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.
Return the largest sum of the given array ... |
longest-duplicate-substring | def longestDupSubstring(s: str) -> str:
"""
Given a string s, consider all duplicated substrings: (contiguous) substrings of s that occur 2 or more times. The occurrences may overlap.
Return any duplicated substring that has the longest possible length. If s does not have a duplicated substring, the answer ... |
last-stone-weight | def lastStoneWeight(stones: List[int]) -> int:
"""
You are given an array of integers stones where stones[i] is the weight of the ith stone.
We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weights x and y wi... |
remove-all-adjacent-duplicates-in-string | def removeDuplicates(s: str) -> str:
"""
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.
We repeatedly make duplicate removals on s until we no longer can.
Return the final string after all such ... |
longest-string-chain | def longestStrChain(words: List[str]) -> int:
"""
You are given an array of words where each word consists of lowercase English letters.
wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to make it equal to wo... |
last-stone-weight-ii | def lastStoneWeightII(stones: List[int]) -> int:
"""
You are given an array of integers stones where stones[i] is the weight of the ith stone.
We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The resul... |
height-checker | def heightChecker(heights: List[int]) -> int:
"""
A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of th... |
grumpy-bookstore-owner | def maxSatisfied(customers: List[int], grumpy: List[int], minutes: int) -> int:
"""
There is a bookstore owner that has a store open for n minutes. You are given an integer array customers of length n where customers[i] is the number of the customers that enter the store at the start of the ith minute and all t... |
previous-permutation-with-one-swap | def prevPermOpt1(arr: List[int]) -> List[int]:
"""
Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return the same array.
Note that a swap exchang... |
distant-barcodes | def rearrangeBarcodes(barcodes: List[int]) -> List[int]:
"""
In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].
Rearrange the barcodes so that no two adjacent barcodes are equal. You may return any answer, and it is guaranteed an answer exists.
Example 1:
>>> rear... |
shortest-way-to-form-string | def shortestWay(source: str, target: str) -> int:
"""
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is ... |
confusing-number | def confusingNumber(n: int) -> bool:
"""
A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.
We can rotate digits of a number by 180 degrees to form new digits.
When 0, 1, 6, 8, and 9 are rotated 180 degrees, they become 0, 1, 9, 8, and 6 r... |
campus-bikes | def assignBikes(workers: List[List[int]], bikes: List[List[int]]) -> List[int]:
"""
On a campus represented on the X-Y plane, there are n workers and m bikes, with n <= m.
You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an array bi... |
minimize-rounding-error-to-meet-target | def minimizeError(prices: List[str], target: int) -> str:
"""
Given an array of prices [p1,p2...,pn] and a target, round each price pi to Roundi(pi) so that the rounded array [Round1(p1),Round2(p2)...,Roundn(pn)] sums to the given target. Each operation Roundi(pi) could be either Floor(pi) or Ceil(pi).
Retu... |
all-paths-from-source-lead-to-destination | def leadsToDestination(n: int, edges: List[List[int]], source: int, destination: int) -> bool:
"""
Given the edges of a directed graph where edges[i] = [ai, bi] indicates there is an edge between nodes ai and bi, and two nodes source and destination of this graph, determine whether or not all paths starting fro... |
missing-element-in-sorted-array | def missingElement(nums: List[int], k: int) -> int:
"""
Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.
Example 1:
>>> missingElement(num... |
lexicographically-smallest-equivalent-string | def smallestEquivalentString(s1: str, s2: str, baseStr: str) -> str:
"""
You are given two strings of the same length s1 and s2 and a string baseStr.
We say s1[i] and s2[i] are equivalent characters.
For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.
... |
longest-repeating-substring | def longestRepeatingSubstring(s: str) -> int:
"""
Given a string s, return the length of the longest repeating substrings. If no repeating substring exists, return 0.
Example 1:
>>> longestRepeatingSubstring(s = "abcd")
>>> 0
Explanation: There is no repeating substring.
Examp... |
number-of-valid-subarrays | def validSubarrays(nums: List[int]) -> int:
"""
Given an integer array nums, return the number of non-empty subarrays with the leftmost element of the subarray not larger than other elements in the subarray.
A subarray is a contiguous part of an array.
Example 1:
>>> validSubarrays(nums = ... |
fixed-point | def fixedPoint(arr: List[int]) -> int:
"""
Given an array of distinct integers arr, where arr is sorted in ascending order, return the smallest index i that satisfies arr[i] == i. If there is no such index, return -1.
Example 1:
>>> fixedPoint(arr = [-10,-5,0,3,7])
>>> 3
Explanation: F... |
index-pairs-of-a-string | def indexPairs(text: str, words: List[str]) -> List[List[int]]:
"""
Given a string text and an array of strings words, return an array of all index pairs [i, j] so that the substring text[i...j] is in words.
Return the pairs [i, j] in sorted order (i.e., sort them by their first coordinate, and in case of t... |
campus-bikes-ii | def assignBikes(workers: List[List[int]], bikes: List[List[int]]) -> int:
"""
On a campus represented as a 2D grid, there are n workers and m bikes, with n <= m. Each worker and bike is a 2D coordinate on this grid.
We assign one unique bike to each worker so that the sum of the Manhattan distances between ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.