task_id
stringlengths
3
79
prompt
stringlengths
255
3.93k
swapping-nodes-in-a-linked-list
from typing import Optional class ListNode: def __init__(val=0, next=None): self.val = val self.next = next def swapNodes(head: Optional[ListNode], k: int) -> Optional[ListNode]: """ You are given the head of a linked list, and an integer k. Return the head of the linked list after swapping the valu...
minimize-hamming-distance-after-swap-operations
from typing import List def minimumHammingDistance(source: List[int], target: List[int], allowedSwaps: List[List[int]]) -> int: """ You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed...
find-minimum-time-to-finish-all-jobs
from typing import List def minimumTimeRequired(jobs: List[int], k: int) -> int: """ You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job. There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time...
number-of-rectangles-that-can-form-the-largest-square
from typing import List def countGoodRectangles(rectangles: List[List[int]]) -> int: """ You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle of length li and width wi.\r \r You can cut the ith rectangle to form a square with a side length of k if both k <= li an...
tuple-with-same-product
from typing import List def tupleSameProduct(nums: List[int]) -> int: """ Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d. Example 1: >>> tupleSameProduct(nums = ...
largest-submatrix-with-rearrangements
from typing import List def largestSubmatrix(matrix: List[List[int]]) -> int: """ 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. Return the area of the largest submatrix within matrix where every element of the submatrix is 1 afte...
cat-and-mouse-ii
from typing import List def canMouseWin(grid: List[str], catJump: int, mouseJump: int) -> bool: """ A game is played by a cat and a mouse named Cat and Mouse. The environment is represented by a grid of size rows x cols, where each element is a wall, floor, player (Cat, Mouse), or food. Players are...
shortest-path-to-get-food
from typing import List def getFood(grid: List[List[str]]) -> int: """ You are starving and you want to eat food as quickly as possible. You want to find the shortest path to arrive at any food cell. You are given an m x n character matrix, grid, of these different types of cells: '*' is your locat...
find-the-highest-altitude
from typing import List def largestAltitude(gain: List[int]) -> int: """ There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0. You are given an integer array gain of length n where gain[i] is the net ...
minimum-number-of-people-to-teach
from typing import List def minimumTeachings(n: int, languages: List[List[int]], friendships: List[List[int]]) -> int: """ On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer n, an ar...
decode-xored-permutation
from typing import List def decode(encoded: List[int]) -> List[int]: """ There is an integer array perm that is a permutation of the first n positive integers, where n is always odd. It was encoded into another integer array encoded of length n - 1, such that encoded[i] = perm[i] XOR perm[i + 1]. For exampl...
latest-time-by-replacing-hidden-digits
def maximumTime(time: str) -> str: """ You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?). The valid times are those inclusively between 00:00 and 23:59. Return the latest valid time you can get from time by replacing the hidden digits...
change-minimum-characters-to-satisfy-one-of-three-conditions
def minCharacters(a: str, b: str) -> int: """ You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter. Your goal is to satisfy one of the following three conditions: Every letter in a is strictly less than...
find-kth-largest-xor-coordinate-value
from typing import List def kthLargestValue(matrix: List[List[int]], k: int) -> int: """ You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k. The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <= j...
building-boxes
def minimumBoxes(n: int) -> int: """ You have a cubic storeroom where the width, length, and height of the room are all equal to n units. You are asked to place n boxes in this room where each box is a cube of unit side length. There are however some rules to placing the boxes: You can place the boxes ...
find-distance-in-a-binary-tree
from typing import Optional class TreeNode: def __init__(val=0, left=None, right=None): self.val = val self.left = left self.right = right def findDistance(root: Optional[TreeNode], p: int, q: int) -> int: """ Given the root of a binary tree and two integers p and q, return the distance betw...
maximum-number-of-balls-in-a-box
def countBalls(lowLimit: int, highLimit: int) -> int: """ You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity. Your job at this factory is to put each ball...
restore-the-array-from-adjacent-pairs
from typing import List def restoreArray(adjacentPairs: List[List[int]]) -> List[int]: """ There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums. You are given a 2D integer array adjacentPairs of size n ...
can-you-eat-your-favorite-candy-on-your-favorite-day
from typing import List def canEat(candiesCount: List[int], queries: List[List[int]]) -> List[bool]: """ You are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the ith type you have. You are also given a 2D array queries where queries[i] = [...
palindrome-partitioning-iv
def checkPartitioning(s: str) -> bool: """ Given a string s, return true if it is possible to split the string s into three non-empty palindromic substrings. Otherwise, return false.​​​​​ A string is said to be palindrome if it the same string when reversed. Example 1: >>> checkPartitionin...
maximum-subarray-sum-after-one-operation
from typing import List def maxSumAfterOperation(nums: List[int]) -> int: """ You are given an integer array nums. You must perform exactly one operation where you can replace one element nums[i] with nums[i] * nums[i]. \r \r Return the maximum possible subarray sum after exactly one operation. The suba...
sum-of-unique-elements
from typing import List def sumOfUnique(nums: List[int]) -> int: """ You are given an integer array nums. The unique elements of an array are the elements that appear exactly once in the array. Return the sum of all the unique elements of nums. Example 1: >>> sumOfUnique(nums = [1,2,3,2]) ...
maximum-absolute-sum-of-any-subarray
from typing import List def maxAbsoluteSum(nums: List[int]) -> int: """ You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr). Return the maximum absolute sum of any (possibly empty) subarray of nums. Not...
minimum-length-of-string-after-deleting-similar-ends
def minimumLength(s: str) -> int: """ 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: Pick a non-empty prefix from the string s where all the characters in the prefix are equal. Pick a non-empty suff...
maximum-number-of-events-that-can-be-attended-ii
from typing import List def maxValue(events: List[List[int]], k: int) -> int: """ You are given an array of events where events[i] = [startDayi, endDayi, valuei]. The ith event starts at startDayi and ends at endDayi, and if you attend this event, you will receive a value of valuei. You are also given an intege...
check-if-array-is-sorted-and-rotated
from typing import List def check(nums: List[int]) -> bool: """ Given an array nums, return true if the array was originally sorted in non-decreasing order, then rotated some number of positions (including zero). Otherwise, return false. There may be duplicates in the original array. Note: An array A ro...
maximum-score-from-removing-stones
def maximumScore(a: int, b: int, c: int) -> int: """ You are playing a solitaire game with three piles of stones of sizes a​​​​​​, b,​​​​​​ and c​​​​​​ respectively. Each turn you choose two different non-empty piles, take one stone from each, and add 1 point to your score. The game stops when there are fewer t...
largest-merge-of-two-strings
def largestMerge(word1: str, word2: str) -> str: """ You are given two strings word1 and word2. You want to construct a string merge in the following way: while either word1 or word2 are non-empty, choose one of the following options: If word1 is non-empty, append the first character in word1 to merge ...
closest-subsequence-sum
from typing import List def minAbsDifference(nums: List[int], goal: int) -> int: """ You are given an integer array nums and an integer goal. You 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, ...
minimum-changes-to-make-alternating-binary-string
def minOperations(s: str) -> int: """ You are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa. The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the strin...
count-number-of-homogenous-substrings
def countHomogenous(s: str) -> int: """ Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7. A string is homogenous if all the characters of the string are the same. A substring is a contiguous sequence of characters within a str...
minimum-limit-of-balls-in-a-bag
from typing import List def minimumSize(nums: List[int], maxOperations: int) -> int: """ You are given an integer array nums where the ith bag contains nums[i] balls. You are also given an integer maxOperations. You can perform the following operation at most maxOperations times: Take any bag of ba...
minimum-degree-of-a-connected-trio-in-a-graph
from typing import List def minTrioDegree(n: int, edges: List[List[int]]) -> int: """ You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi. A con...
buildings-with-an-ocean-view
from typing import List def findBuildings(heights: List[int]) -> List[int]: """ There are n buildings in a line. You are given an integer array heights of size n that represents the heights of the buildings in the line. The ocean is to the right of the buildings. A building has an ocean view if the building...
longest-nice-substring
def longestNiceSubstring(s: str) -> str: """ A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is not because 'b' appears, but 'B' does not. Give...
form-array-by-concatenating-subarrays-of-another-array
from typing import List def canChoose(groups: List[List[int]], nums: List[int]) -> bool: """ You are given a 2D integer array groups of length n. You are also given an integer array nums. You are asked if you can choose n disjoint subarrays from the array nums such that the ith subarray is equal to groups[i...
map-of-highest-peak
from typing import Any, List def highestPeak(isWater: List[List[int]]) -> List[List[int]]: """ You are given an integer matrix isWater of size m x n that represents a map of land and water cells. If isWater[i][j] == 0, cell (i, j) is a land cell. If isWater[i][j] == 1, cell (i, j) is a water cell. ...
tree-of-coprimes
from typing import List def getCoprimes(nums: List[int], edges: List[List[int]]) -> List[int]: """ There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree i...
merge-strings-alternately
def mergeAlternately(word1: str, word2: str) -> str: """ You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged string.\r \r Return the merged...
minimum-number-of-operations-to-move-all-balls-to-each-box
from typing import List def minOperations(boxes: str) -> List[int]: """ You have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In one operation, you can move one ball from a box to an adjacent box. Box i is adjacent ...
maximum-score-from-performing-multiplication-operations
from typing import List def maximumScore(nums: List[int], multipliers: List[int]) -> int: """ You are given two 0-indexed integer arrays nums and multipliers of size n and m respectively, where n >= m. You begin with a score of 0. You want to perform exactly m operations. On the ith operation (0-indexed) yo...
maximize-palindrome-length-from-subsequences
def longestPalindrome(word1: str, word2: str) -> int: """ You are given two strings, word1 and word2. You want to construct a string in the following manner: Choose some non-empty subsequence subsequence1 from word1. Choose some non-empty subsequence subsequence2 from word2. Concatenate the sub...
sort-features-by-popularity
from typing import List def sortFeatures(features: List[str], responses: List[str]) -> List[str]: """ You are given a string array features where features[i] is a single word that represents the name of a feature of the latest product you are working on. You have made a survey where users have reported which fe...
count-items-matching-a-rule
from typing import List def countMatches(items: List[List[str]], ruleKey: str, ruleValue: str) -> int: """ You are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the ith item. You are also given a rule represented by two strings, ruleKey and ruleValue. ...
closest-dessert-cost
from typing import List def closestCost(baseCosts: List[int], toppingCosts: List[int], target: int) -> int: """ You would like to make dessert and are preparing to buy the ingredients. You have n ice cream base flavors and m types of toppings to choose from. You must follow these rules when making your dessert:...
equal-sum-arrays-with-minimum-number-of-operations
from typing import List def minOperations(nums1: List[int], nums2: List[int]) -> int: """ You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive. In one operation, you can change any integer's value in any of the arrays to...
car-fleet-ii
from typing import List def getCollisionTimes(cars: List[List[int]]) -> List[float]: """ There are n cars traveling at different speeds in the same direction along a one-lane road. You are given an array cars of length n, where cars[i] = [positioni, speedi] represents: positioni is the distance between...
find-nearest-point-that-has-the-same-x-or-y-coordinate
from typing import List def nearestValidPoint(x: int, y: int, points: List[List[int]]) -> int: """ You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi)...
check-if-number-is-a-sum-of-powers-of-three
def checkPowersOfThree(n: int) -> bool: """ Given an integer n, return true if it is possible to represent n as the sum of distinct powers of three. Otherwise, return false. An integer y is a power of three if there exists an integer x such that y == 3x. Example 1: >>> checkPowersOfThree(n...
sum-of-beauty-of-all-substrings
def beautySum(s: str) -> int: """ The beauty of a string is the difference in frequencies between the most frequent and least frequent characters. For example, the beauty of "abaacc" is 3 - 1 = 2. Given a string s, return the sum of beauty of all of its substrings. Example 1: ...
count-pairs-of-nodes
from typing import List def countPairs(n: int, edges: List[List[int]], queries: List[int]) -> List[int]: """ You are given an undirected graph defined by an integer n, the number of nodes, and a 2D integer array edges, the edges in the graph, where edges[i] = [ui, vi] indicates that there is an undirected edge ...
check-if-binary-string-has-at-most-one-segment-of-ones
def checkOnesSegment(s: str) -> bool: """ Given a binary string s ​​​​​without leading zeros, return true​​​ if s contains at most one contiguous segment of ones. Otherwise, return false. Example 1: >>> checkOnesSegment(s = "1001") >>> false Explanation: The ones do not form a contiguo...
minimum-elements-to-add-to-form-a-given-sum
from typing import List def minElements(nums: List[int], limit: int, goal: int) -> int: """ You are given an integer array nums and two integers limit and goal. The array nums has an interesting property that abs(nums[i]) <= limit. Return the minimum number of elements you need to add to make the sum of the...
number-of-restricted-paths-from-first-to-last-node
from typing import List def countRestrictedPaths(n: int, edges: List[List[int]]) -> int: """ There is an undirected weighted connected graph. You are given a positive integer n which denotes that the graph has n nodes labeled from 1 to n, and an array edges where each edges[i] = [ui, vi, weighti] denotes that t...
make-the-xor-of-all-segments-equal-to-zero
from typing import List def minChanges(nums: List[int], k: int) -> int: """ You are given an array nums​​​ and an integer k​​​​​. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] XOR ... XOR nums[rig...
maximize-the-beauty-of-the-garden
from typing import List def maximumBeauty(flowers: List[int]) -> int: """ There is a garden of n flowers, and each flower has an integer beauty value. The flowers are arranged in a line. You are given an integer array flowers of size n and each flowers[i] represents the beauty of the ith flower.\r \r A ...
check-if-one-string-swap-can-make-strings-equal
def areAlmostEqual(s1: str, s2: str) -> bool: """ 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. Return true if it is possible to make both strings equal by perf...
find-center-of-star-graph
from typing import List def findCenter(edges: List[List[int]]) -> int: """ 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. You are given a 2D intege...
maximum-average-pass-ratio
from typing import List def maxAverageRatio(classes: List[List[int]], extraStudents: int) -> float: """ There is a school that has classes of students and each class will be having a final exam. You are given a 2D integer array classes, where classes[i] = [passi, totali]. You know beforehand that in the ith cla...
maximum-score-of-a-good-subarray
from typing import List def maximumScore(nums: List[int], k: int) -> int: """ You are given an array of integers nums (0-indexed) and an integer k. The score of a subarray (i, j) is defined as min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1). A good subarray is a subarray where i <= k <= j. Return th...
count-pairs-of-equal-substrings-with-minimum-difference
def countQuadruples(firstString: str, secondString: str) -> int: """ You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions: 0 <= i <= j < firstString.l...
second-largest-digit-in-a-string
def secondHighest(s: str) -> int: """ Given an alphanumeric string s, return the second largest numerical digit that appears in s, or -1 if it does not exist. An alphanumeric string is a string consisting of lowercase English letters and digits. Example 1: >>> secondHighest(s = "dfa12321af...
maximum-number-of-consecutive-values-you-can-make
from typing import List def getMaximumConsecutive(coins: List[int]) -> int: """ 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. ...
maximum-ascending-subarray-sum
from typing import List def maxAscendingSum(nums: List[int]) -> int: """ Given an array of positive integers nums, return the maximum possible sum of an strictly increasing subarray in nums. A subarray is defined as a contiguous sequence of numbers in an array. Example 1: >>> maxAscendingS...
number-of-orders-in-the-backlog
from typing import List def getNumberOfBacklogOrders(orders: List[List[int]]) -> int: """ 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:\r \r \r 0 i...
maximum-value-at-a-given-index-in-a-bounded-array
def maxValue(n: int, index: int, maxSum: int) -> int: """ You are given three positive integers: n, index, and maxSum. You want to construct an array nums (0-indexed) that satisfies the following conditions: nums.length == n nums[i] is a positive integer where 0 <= i < n. abs(nums[i] - nums[i+1...
count-pairs-with-xor-in-a-range
from typing import List def countPairs(nums: List[int], low: int, high: int) -> int: """ Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.\r \r A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.\r ...
number-of-different-integers-in-a-string
def numDifferentIntegers(word: str) -> int: """ You are given a string word that consists of digits and lowercase English letters. You will replace every non-digit character with a space. For example, "a123bc34d8ef34" will become " 123  34 8  34". Notice that you are left with some integers that are separat...
minimum-number-of-operations-to-reinitialize-a-permutation
def reinitializePermutation(n: int) -> int: """ You are given an even integer n​​​​​​. You initially have a permutation perm of size n​​ where perm[i] == i​ (0-indexed)​​​​. In one operation, you will create a new array arr, and for each i: If i % 2 == 0, then arr[i] = perm[i / 2]. If i % 2 == ...
evaluate-the-bracket-pairs-of-a-string
from typing import List def evaluate(s: str, knowledge: List[List[str]]) -> str: """ You are given a string s that contains some bracket pairs, with each pair containing a non-empty key. For example, in the string "(name)is(age)yearsold", there are two bracket pairs that contain the keys "name" and "ag...
maximize-number-of-nice-divisors
def maxNiceDivisors(primeFactors: int) -> int: """ You are given a positive integer primeFactors. You are asked to construct a positive integer n that satisfies the following conditions:\r \r \r The number of prime factors of n (not necessarily distinct) is at most primeFactors.\r The number...
determine-color-of-a-chessboard-square
def squareIsWhite(coordinates: str) -> bool: """ You are given coordinates, a string that represents the coordinates of a square of the chessboard. Below is a chessboard for your reference. Return true if the square is white, and false if the square is black. The coordinate will always represent a ...
sentence-similarity-iii
def areSentencesSimilar(sentence1: str, sentence2: str) -> bool: """ You are given two strings sentence1 and sentence2, each representing a sentence composed of words. A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of only uppercase and ...
count-nice-pairs-in-an-array
from typing import List def countNicePairs(nums: List[int]) -> int: """ You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice if it satisfies all of t...
maximum-number-of-groups-getting-fresh-donuts
from typing import List def maxHappyGroups(batchSize: int, groups: List[int]) -> int: """ There is a donuts shop that bakes donuts in batches of batchSize. They have a rule where they must serve all of the donuts of a batch before serving any donuts of the next batch. You are given an integer batchSize and an i...
truncate-sentence
def truncateSentence(s: str, k: int) -> str: """ A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation). For example, "Hello World", "HELLO", and "hello world hell...
finding-the-users-active-minutes
from typing import List def findingUsersActiveMinutes(logs: List[List[int]], k: int) -> List[int]: """ You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [IDi, timei] indicates that the user with IDi performed an acti...
minimum-absolute-sum-difference
from typing import List def minAbsoluteSumDiff(nums1: List[int], nums2: List[int]) -> int: """ You are given two positive integer arrays nums1 and nums2, both of length n. The absolute sum difference of arrays nums1 and nums2 is defined as the sum of |nums1[i] - nums2[i]| for each 0 <= i < n (0-indexed). ...
number-of-different-subsequences-gcds
from typing import List def countDifferentSubsequenceGCDs(nums: List[int]) -> int: """ You are given an array nums that consists of positive integers. The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly. For example, the GCD of the...
maximum-number-of-accepted-invitations
from typing import List def maximumInvitations(grid: List[List[int]]) -> int: """ There are m boys and n girls in a class attending an upcoming party. You are given an m x n integer matrix grid, where grid[i][j] equals 0 or 1. If grid[i][j] == 1, then that means the ith boy can invite the jth girl to the pa...
sign-of-the-product-of-an-array
from typing import List def arraySign(nums: List[int]) -> int: """ Implement a function signFunc(x) that returns: 1 if x is positive. -1 if x is negative. 0 if x is equal to 0. You are given an integer array nums. Let product be the product of all values in the array nums. Return s...
find-the-winner-of-the-circular-game
def findTheWinner(n: int, k: int) -> int: """ There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth f...
minimum-sideway-jumps
from typing import List def minSideJumps(obstacles: List[int]) -> int: """ There is a 3 lane road of length n that consists of n + 1 points labeled from 0 to n. A frog starts at point 0 in the second lane and wants to jump to point n. However, there could be obstacles along the way. You are given an array o...
faulty-sensor
from typing import List def badSensor(sensor1: List[int], sensor2: List[int]) -> int: """ An experiment is being conducted in a lab. To ensure accuracy, there are two sensors collecting data simultaneously. You are given two arrays sensor1 and sensor2, where sensor1[i] and sensor2[i] are the ith data points col...
minimum-operations-to-make-the-array-increasing
from typing import List def minOperations(nums: List[int]) -> int: """ You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1.\r \r \r For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3,3]....
queries-on-number-of-points-inside-a-circle
from typing import List def countPoints(points: List[List[int]], queries: List[List[int]]) -> List[int]: """ You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates. You are also given an array queries where qu...
maximum-xor-for-each-query
from typing import List def getMaximumXor(nums: List[int], maximumBit: int) -> List[int]: """ You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times: Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1...
check-if-the-sentence-is-pangram
def checkIfPangram(sentence: str) -> bool: """ A pangram is a sentence where every letter of the English alphabet appears at least once. Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise. Example 1: >>> checkIfPangra...
maximum-ice-cream-bars
from typing import List def maxIceCream(costs: List[int], coins: int) -> int: """ It is a sweltering summer day, and a boy wants to buy some ice cream bars. At 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 ...
single-threaded-cpu
from typing import List def getOrder(tasks: List[List[int]]) -> List[int]: """ You are given n​​​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTimei and will tak...
find-xor-sum-of-all-pairs-bitwise-and
from typing import List def getXORSum(arr1: List[int], arr2: List[int]) -> int: """ The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element. For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 ...
remove-duplicates-from-an-unsorted-linked-list
from typing import Optional class ListNode: def __init__(val=0, next=None): self.val = val self.next = next def deleteDuplicatesUnsorted(head: Optional[ListNode]) -> Optional[ListNode]: """ Given the head of a linked list, find all the values that appear more than once in the list and delete the nod...
sum-of-digits-in-base-k
def sumBase(n: int, k: int) -> int: """ Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k. After converting, each digit should be interpreted as a base 10 number, and the sum should be returned in base 10. Example 1: >...
frequency-of-the-most-frequent-element
from typing import List def maxFrequency(nums: List[int], k: int) -> int: """ The frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you can choose an index of nums and increment the element at that index by 1. Re...
longest-substring-of-all-vowels-in-order
def longestBeautifulSubstring(word: str) -> int: """ A string is considered beautiful if it satisfies the following conditions: Each of the 5 English vowels ('a', 'e', 'i', 'o', 'u') must appear at least once in it. The letters must be sorted in alphabetical order (i.e. all 'a's before 'e's, all 'e...
maximum-building-height
from typing import List def maxBuilding(n: int, restrictions: List[List[int]]) -> int: """ You want to build n new buildings in a city. The new buildings will be built in a line and are labeled from 1 to n. However, there are city restrictions on the heights of the new buildings: The height of each...
next-palindrome-using-same-digits
def nextPalindrome(num: str) -> str: """ You are given a numeric string num, representing a very large palindrome. Return the smallest palindrome larger than num that can be created by rearranging its digits. If no such palindrome exists, return an empty string "". A palindrome is a number that reads th...
replace-all-digits-with-characters
def replaceDigits(s: str) -> str: """ You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices. You must perform an operation shift(c, x), where c is a character and x is a digit, that returns the xth character after c. For example, shi...
maximum-element-after-decreasing-and-rearranging
from typing import List def maximumElementAfterDecrementingAndRearranging(arr: List[int]) -> int: """ You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions: The value of the first element in arr must be 1. The absolute ...
closest-room
from typing import List def closestRoom(rooms: List[List[int]], queries: List[List[int]]) -> List[int]: """ There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each r...