task_id
stringlengths
3
79
prompt
stringlengths
255
3.9k
minimum-distance-to-the-target-element
def getMinDistance(nums: List[int], target: int, start: int) -> int: """ Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x. Return abs(i - start). It is guara...
splitting-a-string-into-descending-consecutive-values
def splitString(s: str) -> bool: """ You are given a string s that consists of only digits. Check if we can split s into two or more non-empty substrings such that the numerical values of the substrings are in descending order and the difference between numerical values of every two adjacent substrings is e...
minimum-adjacent-swaps-to-reach-the-kth-smallest-number
def getMinSwaps(num: str, k: int) -> int: """ You are given a string num, representing a large integer, and an integer k. We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful integers. However, we only care about the smalles...
minimum-interval-to-include-each-query
def minInterval(intervals: List[List[int]], queries: List[int]) -> List[int]: """ You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integers it contai...
distinct-numbers-in-each-subarray
def distinctNumbers(nums: List[int], k: int) -> List[int]: """ You are given an integer array nums of length n and an integer k. Your task is to find the number of distinct elements in every subarray of size k within nums. Return an array ans such that ans[i] is the count of distinct elements in nums[i..(i ...
maximum-population-year
def maximumPopulation(logs: List[List[int]]) -> int: """ You are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person. The population of some year x is the number of people alive during that year. The ith person is counted in year x's popu...
maximum-distance-between-a-pair-of-values
def maxDistance(nums1: List[int], nums2: List[int]) -> int: """ You are given two non-increasing 0-indexed integer arrays nums1​​​​​​ and nums2​​​​​​. A pair of indices (i, j), where 0 <= i < nums1.length and 0 <= j < nums2.length, is valid if both i <= j and nums1[i] <= nums2[j]. The distance of the pair i...
maximum-subarray-min-product
def maxSumMinProduct(nums: List[int]) -> int: """ The min-product of an array is equal to the minimum value in the array multiplied by the array's sum. For example, the array [3,2,5] (minimum value is 2) has a min-product of 2 * (3+2+5) = 2 * 10 = 20. Given an array of integers nums, return th...
largest-color-value-in-a-directed-graph
def largestPathValue(colors: str, edges: List[List[int]]) -> int: """ There is a directed graph of n colored nodes and m edges. The nodes are numbered from 0 to n - 1.\r \r You are given a string colors where colors[i] is a lowercase English letter representing the color of the ith node in this graph (0...
longest-word-with-all-prefixes
def longestWord(words: List[str]) -> str: """ Given an array of strings words, find the longest string in words such that every prefix of it is also in words. For example, let words = ["a", "app", "ap"]. The string "app" has prefixes "ap" and "a", all of which are in words. Return the string d...
sorting-the-sentence
def sortSentence(s: str) -> str: """ A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the wor...
incremental-memory-leak
def memLeak(memory1: int, memory2: int) -> List[int]: """ You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second. At the ith second (starting from 1),...
rotating-the-box
def rotateTheBox(boxGrid: List[List[str]]) -> List[List[str]]: """ You are given an m x n matrix of characters boxGrid representing a side-view of a box. Each cell of the box is one of the following: A stone '#' A stationary obstacle '*' Empty '.' The box is rotated 90 degrees clockwis...
sum-of-floored-pairs
def sumOfFlooredPairs(nums: List[int]) -> int: """ Given an integer array nums, return the sum of floor(nums[i] / nums[j]) for all pairs of indices 0 <= i, j < nums.length in the array. Since the answer may be too large, return it modulo 109 + 7. The floor() function returns the integer part of the division...
sum-of-all-subset-xor-totals
def subsetXORSum(nums: List[int]) -> int: """ The XOR total of an array is defined as the bitwise XOR of all its elements, or 0 if the array is empty. For example, the XOR total of the array [2,5,6] is 2 XOR 5 XOR 6 = 1. Given an array nums, return the sum of all XOR totals for every subset of...
minimum-number-of-swaps-to-make-the-binary-string-alternating
def minSwaps(s: str) -> int: """ Given a binary string s, return the minimum number of character swaps to make it alternating, or -1 if it is impossible. The string is called alternating if no two adjacent characters are equal. For example, the strings "010" and "1010" are alternating, while the string "010...
number-of-ways-to-rearrange-sticks-with-k-sticks-visible
def rearrangeSticks(n: int, k: int) -> int: """ There are n uniquely-sized sticks whose lengths are integers from 1 to n. You want to arrange the sticks such that exactly k sticks are visible from the left. A stick is visible from the left if there are no longer sticks to the left of it. For example, i...
product-of-two-run-length-encoded-arrays
def findRLEArray(encoded1: List[List[int]], encoded2: List[List[int]]) -> List[List[int]]: """ Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [v...
longer-contiguous-segments-of-ones-than-zeros
def checkZeroOnes(s: str) -> bool: """ Given a binary string s, return true if the longest contiguous segment of 1's is strictly longer than the longest contiguous segment of 0's in s, or return false otherwise. For example, in s = "110100010" the longest continuous segment of 1s has length 2, and the ...
minimum-speed-to-arrive-on-time
def minSpeedOnTime(dist: List[int], hour: float) -> int: """ You are given a floating-point number hour, representing the amount of time you have to reach the office. To commute to the office, you must take n trains in sequential order. You are also given an integer array dist of length n, where dist[i] describ...
jump-game-vii
def canReach(s: str, minJump: int, maxJump: int) -> bool: """ You are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. You can move from index i to index j if the following conditions are fulfilled: i + minJump...
stone-game-viii
def stoneGameVIII(stones: List[int]) -> int: """ Alice and Bob take turns playing a game, with Alice starting first.\r \r There are n stones arranged in a row. On each player's turn, while the number of stones is more than one, they will do the following:\r \r \r Choose an integer x > 1, an...
minimize-product-sum-of-two-arrays
def minProductSum(nums1: List[int], nums2: List[int]) -> int: """ The product sum of two equal-length arrays a and b is equal to the sum of a[i] * b[i] for all 0 <= i < a.length (0-indexed).\r \r \r For example, if a = [1,2,3,4] and b = [5,2,3,1], the product sum would be 1*5 + 2*2 + 3*3 + 4*1 = 22...
substrings-of-size-three-with-distinct-characters
def countGoodSubstrings(s: str) -> int: """ A string is good if there are no repeated characters. Given a string s​​​​​, return the number of good substrings of length three in s​​​​​​. Note that if there are multiple occurrences of the same substring, every occurrence should be counted. A substring...
minimize-maximum-pair-sum-in-array
def minPairSum(nums: List[int]) -> int: """ The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs.\r \r \r For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8.\r \r ...
get-biggest-three-rhombus-sums-in-a-grid
def getBiggestThree(grid: List[List[int]]) -> List[int]: """ You are given an m x n integer matrix grid​​​. A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid​​​. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in...
minimum-xor-sum-of-two-arrays
def minimumXORSum(nums1: List[int], nums2: List[int]) -> int: """ You are given two integer arrays nums1 and nums2 of length n. The XOR sum of the two integer arrays is (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]) (0-indexed). For example, the XOR sum of...
check-if-word-equals-summation-of-two-words
def isSumEqual(firstWord: str, secondWord: str, targetWord: str) -> bool: """ The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.). The numerical value of some string of lowercase English letters s is the concatenation of the letter values of...
maximum-value-after-insertion
def maxValue(n: str, x: int) -> str: """ You are given a very large integer n, represented as a string,​​​​​​ and an integer digit x. The digits in n and the digit x are in the inclusive range [1, 9], and n may represent a negative number. You want to maximize n's numerical value by inserting x anywhere in ...
process-tasks-using-servers
def assignTasks(servers: List[int], tasks: List[int]) -> List[int]: """ You are given two 0-indexed integer arrays servers and tasks of lengths n​​​​​​ and m​​​​​​ respectively. servers[i] is the weight of the i​​​​​​th​​​​ server, and tasks[j] is the time needed to process the j​​​​​​th​​​​ task in seconds. ...
minimum-skips-to-arrive-at-meeting-on-time
def minSkips(dist: List[int], speed: int, hoursBefore: int) -> int: """ You are given an integer hoursBefore, the number of hours you have to travel to your meeting. To arrive at your meeting, you have to travel through n roads. The road lengths are given as an integer array dist of length n, where dist[i] desc...
egg-drop-with-2-eggs-and-n-floors
def twoEggDrop(n: int) -> int: """ You are given two identical eggs and you have access to a building with n floors labeled from 1 to n. You know that there exists a floor f where 0 <= f <= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not brea...
count-pairs-in-two-arrays
def countPairs(nums1: List[int], nums2: List[int]) -> int: """ Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j]. Return the number of pairs satisfying the condition. Example 1: >>> countPai...
determine-whether-matrix-can-be-obtained-by-rotation
def findRotation(mat: List[List[int]], target: List[List[int]]) -> bool: """ Given two n x n binary matrices mat and target, return true if it is possible to make mat equal to target by rotating mat in 90-degree increments, or false otherwise. Example 1: >>> findRotation(mat = [[0,1],[1,0...
reduction-operations-to-make-the-array-elements-equal
def reductionOperations(nums: List[int]) -> int: """ Given an integer array nums, your goal is to make all elements in nums equal. To complete one operation, follow these steps: Find the largest value in nums. Let its index be i (0-indexed) and its value be largest. If there are multiple elements with ...
minimum-number-of-flips-to-make-the-binary-string-alternating
def minFlips(s: str) -> int: """ You are given a binary string s. You are allowed to perform two types of operations on the string in any sequence: Type-1: Remove the character at the start of the string s and append it to the end of the string. Type-2: Pick any character in s and flip its value, i...
minimum-space-wasted-from-packaging
def minWastedSpace(packages: List[int], boxes: List[List[int]]) -> int: """ You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size of the package is ...
cutting-ribbons
def maxLength(ribbons: List[int], k: int) -> int: """ You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or perform no cuts at all. For example, if yo...
check-if-all-the-integers-in-a-range-are-covered
def isCovered(ranges: List[List[int]], left: int, right: int) -> bool: """ You are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between starti and endi. Return true if each integer in the inclusive range [left, right] is co...
find-the-student-that-will-replace-the-chalk
def chalkReplacer(chalk: List[int], k: int) -> int: """ There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will...
largest-magic-square
def largestMagicSquare(grid: List[List[int]]) -> int: """ A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid is trivially a magic square. Give...
minimum-cost-to-change-the-final-value-of-expression
def minOperationsToFlip(expression: str) -> int: """ You are given a valid boolean expression as a string expression consisting of the characters '1','0','&' (bitwise AND operator),'|' (bitwise OR operator),'(', and ')'. For example, "()1|1" and "(1)&()" are not valid while "1", "(((1))|(0))", and "1|(...
redistribute-characters-to-make-all-strings-equal
def makeEqual(words: List[str]) -> bool: """ You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return true if you can make every string in words...
maximum-number-of-removable-characters
def maximumRemovals(s: str, p: str, removable: List[int]) -> int: """ You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed). You want to choose an integer k (0 <= k <= removab...
merge-triplets-to-form-target-triplet
def mergeTriplets(triplets: List[List[int]], target: List[int]) -> bool: """ A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the triplet you want ...
the-earliest-and-latest-rounds-where-players-compete
def earliestAndLatest(n: int, firstPlayer: int, secondPlayer: int) -> List[int]: """ There is a tournament where n players are participating. The players are standing in a single row and are numbered from 1 to n based on their initial standing position (player 1 is the first player in the row, player 2 is the s...
find-a-peak-element-ii
def findPeakGrid(mat: List[List[int]]) -> List[int]: """ A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom. Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find any peak element mat[i][j] and re...
depth-of-bst-given-insertion-order
def maxDepthBST(order: List[int]) -> int: """ You are given a 0-indexed integer array order of length n, a permutation of integers from 1 to n representing the order of insertion into a binary search tree. A binary search tree is defined as follows: The left subtree of a node contains only nodes wi...
largest-odd-number-in-string
def largestOddNumber(num: str) -> str: """ You are given a string num, representing a large integer. Return the largest-valued odd integer (as a string) that is a non-empty substring of num, or an empty string "" if no odd integer exists. A substring is a contiguous sequence of characters within a string. ...
the-number-of-full-rounds-you-have-played
def numberOfRounds(loginTime: str, logoutTime: str) -> int: """ 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. For example, the second round starts at 0...
count-sub-islands
def countSubIslands(grid1: List[List[int]], grid2: List[List[int]]) -> int: """ You are given two m x n binary matrices grid1 and grid2 containing only 0's (representing water) and 1's (representing land). An island is a group of 1's connected 4-directionally (horizontal or vertical). Any cells outside of the g...
minimum-absolute-difference-queries
def minDifference(nums: List[int], queries: List[List[int]]) -> List[int]: """ The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1. For exam...
game-of-nim
def nimGame(piles: List[int]) -> bool: """ Alice and Bob take turns playing a game with Alice starting first. In this game, there are n piles of stones. On each player's turn, the player should remove any positive number of stones from a non-empty pile of his or her choice. The first player who cannot make ...
remove-one-element-to-make-the-array-strictly-increasing
def canBeIncreasing(nums: List[int]) -> bool: """ Given a 0-indexed integer array nums, return true if it can be made strictly increasing after removing exactly one element, or false otherwise. If the array is already strictly increasing, return true. The array nums is strictly increasing if nums[i - 1] < n...
remove-all-occurrences-of-a-substring
def removeOccurrences(s: str, part: str) -> str: """ Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed: Find the leftmost occurrence of the substring part and remove it from s. Return s after removing all occurrences of p...
maximum-alternating-subsequence-sum
def maxAlternatingSum(nums: List[int]) -> int: """ The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices.\r \r \r For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4.\r \r \r Given a...
maximum-product-difference-between-two-pairs
def maxProductDifference(nums: List[int]) -> int: """ The product difference between two pairs (a, b) and (c, d) is defined as (a * b) - (c * d).\r \r \r For example, the product difference between (5, 6) and (2, 7) is (5 * 6) - (2 * 7) = 16.\r \r \r Given an integer array nums, choose ...
cyclically-rotating-a-grid
def rotateGrid(grid: List[List[int]], k: int) -> List[List[int]]: """ You are given an m x n integer matrix grid​​​, where m and n are both even integers, and an integer k.\r \r The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:\r \r \...
number-of-wonderful-substrings
def wonderfulSubstrings(word: str) -> int: """ A wonderful string is a string where at most one letter appears an odd number of times.\r \r \r For example, "ccjjc" and "abab" are wonderful, but "ab" is not.\r \r \r Given a string word that consists of the first ten lowercase English let...
count-ways-to-build-rooms-in-an-ant-colony
def waysToBuildRooms(prevRoom: List[int]) -> int: """ You are an ant tasked with adding n new rooms numbered 0 to n-1 to your colony. You are given the expansion plan as a 0-indexed integer array of length n, prevRoom, where prevRoom[i] indicates that you must build room prevRoom[i] before building room i, and ...
kth-smallest-subarray-sum
def kthSmallestSubarraySum(nums: List[int], k: int) -> int: """ Given an integer array nums of length n and an integer k, return the kth smallest subarray sum. A subarray is defined as a non-empty contiguous sequence of elements in an array. A subarray sum is the sum of all elements in the subarray. ...
build-array-from-permutation
def buildArray(nums: List[int]) -> List[int]: """ Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. A zero-based permutation nums is an array of distinct integers from 0 to nums.length - 1 (inclusi...
eliminate-maximum-number-of-monsters
def eliminateMaximum(dist: List[int], speed: List[int]) -> int: """ You are playing a video game where you are defending your city from a group of n monsters. You are given a 0-indexed integer array dist of size n, where dist[i] is the initial distance in kilometers of the ith monster from the city. The mon...
count-good-numbers
def countGoodNumbers(n: int) -> int: """ A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7). For example, "2582" is good because the digits (2 and 8) at even positions are even and the digits (5 and 2) at odd positions are p...
longest-common-subpath
def longestCommonSubpath(n: int, paths: List[List[int]]) -> int: """ There is a country of n cities numbered from 0 to n - 1. In this country, there is a road connecting every pair of cities. There are m friends numbered from 0 to m - 1 who are traveling through the country. Each one of them will take a pat...
erect-the-fence-ii
def outerTrees(trees: List[List[int]]) -> List[float]: """ You are given a 2D integer array trees where trees[i] = [xi, yi] represents the location of the ith tree in the garden. You are asked to fence the entire garden using the minimum length of rope possible. The garden is well-fenced only if all the tre...
count-square-sum-triples
def countTriples(n: int) -> int: """ A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2. Given an integer n, return the number of square triples such that 1 <= a, b, c <= n. Example 1: >>> countTriples(n = 5) >>> 2 Explanation: The square triples ar...
nearest-exit-from-entrance-in-maze
def nearestExit(maze: List[List[str]], entrance: List[int]) -> int: """ You are given an m x n matrix maze (0-indexed) with empty cells (represented as '.') and walls (represented as '+'). You are also given the entrance of the maze, where entrance = [entrancerow, entrancecol] denotes the row and column of the ...
sum-game
def sumGame(num: str) -> bool: """ Alice and Bob take turns playing a game, with Alice starting first. You are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if there is still at least one '?' in num: Choose an index i where n...
minimum-cost-to-reach-destination-in-time
def minCost(maxTime: int, edges: List[List[int]], passingFees: List[int]) -> int: """ There is a country of n cities numbered from 0 to n - 1 where all the cities are connected by bi-directional roads. The roads are represented as a 2D integer array edges where edges[i] = [xi, yi, timei] denotes a road between ...
concatenation-of-array
def getConcatenation(nums: List[int]) -> List[int]: """ Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays. Return the array ans. ...
unique-length-3-palindromic-subsequences
def countPalindromicSubsequence(s: str) -> int: """ Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a string that reads the same...
painting-a-grid-with-three-different-colors
def colorTheGrid(m: int, n: int) -> int: """ You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted. Return the number of ways to color the grid with no two adjacent cells having the same color. Si...
check-if-string-is-decomposable-into-value-equal-substrings
def isDecomposable(s: str) -> bool: """ A value-equal string is a string where all characters are the same. For example, "1111" and "33" are value-equal strings. In contrast, "123" is not a value-equal string. Given a digit string s, decompose the string into some number of consecutive val...
maximum-number-of-words-you-can-type
def canBeTypedWords(text: str, brokenLetters: str) -> int: """ There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly. Given a string text of words separated by a single space (no leading or trailing spaces) and a string brokenLetters of all disti...
add-minimum-number-of-rungs
def addRungs(rungs: List[int], dist: int) -> int: """ You are given a strictly increasing integer array rungs that represents the height of rungs on a ladder. You are currently on the floor at height 0, and you want to reach the last rung. You are also given an integer dist. You can only climb to the next h...
maximum-number-of-points-with-cost
def maxPoints(points: List[List[int]]) -> int: """ You are given an m x n integer matrix points (0-indexed). Starting with 0 points, you want to maximize the number of points you can get from the matrix. To gain points, you must pick one cell in each row. Picking the cell at coordinates (r, c) will add poin...
maximum-genetic-difference-query
def maxGeneticDifference(parents: List[int], queries: List[List[int]]) -> List[int]: """ There is a rooted tree consisting of n nodes numbered 0 to n - 1. Each node's number denotes its unique genetic value (i.e. the genetic value of node x is x). The genetic difference between two genetic values is defined as ...
longest-common-subsequence-between-sorted-arrays
def longestCommonSubsequence(arrays: List[List[int]]) -> List[int]: """ Given an array of integer arrays arrays where each arrays[i] is sorted in strictly increasing order, return an integer array representing the longest common subsequence among all the arrays. A subsequence is a sequence that can be deriv...
check-if-all-characters-have-equal-number-of-occurrences
def areOccurrencesEqual(s: str) -> bool: """ Given a string s, return true if s is a good string, or false otherwise. A string s is good if all the characters that appear in s have the same number of occurrences (i.e., the same frequency). Example 1: >>> areOccurrencesEqual(s = "abacbc") ...
the-number-of-the-smallest-unoccupied-chair
def smallestChair(times: List[List[int]], targetFriend: int) -> int: """ There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the unoccupied chair with th...
describe-the-painting
def splitPainting(segments: List[List[int]]) -> List[List[int]]: """ There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer array segments, where segmen...
number-of-visible-people-in-a-queue
def canSeePersonsCount(heights: List[int]) -> List[int]: """ There are n people standing in a queue, and they numbered from 0 to n - 1 in left to right order. You are given an array heights of distinct integers where heights[i] represents the height of the ith person. A person can see another person to thei...
sum-of-digits-of-string-after-convert
def getLucky(s: str, k: int) -> int: """ You are given a string s consisting of lowercase English letters, and an integer k. Your task is to convert the string into an integer by a special process, and then transform it by summing its digits repeatedly k times. More specifically, perform the following steps: ...
largest-number-after-mutating-substring
def maximumNumber(num: str, change: List[int]) -> str: """ You are given a string num, which represents a large integer. You are also given a 0-indexed integer array change of length 10 that maps each digit 0-9 to another digit. More formally, digit d maps to digit change[d]. You may choose to mutate a sing...
maximum-compatibility-score-sum
def maxCompatibilitySum(students: List[List[int]], mentors: List[List[int]]) -> int: """ There is a survey that consists of n questions where each question's answer is either 0 (no) or 1 (yes). The survey was given to m students numbered from 0 to m - 1 and m mentors numbered from 0 to m - 1. The answers of...
delete-duplicate-folders-in-system
def deleteDuplicateFolder(paths: List[List[str]]) -> List[List[str]]: """ Due to a bug, there are many duplicate folders in a file system. You are given a 2D array paths, where paths[i] is an array representing an absolute path to the ith folder in the file system. For example, ["one", "two", "three"] ...
maximum-of-minimum-values-in-all-subarrays
def findMaximums(nums: List[int]) -> List[int]: """ You are given an integer array nums of size n. You are asked to solve n queries for each integer i in the range 0 <= i < n. To solve the ith query: Find the minimum value in each possible subarray of size i + 1 of the array nums. Find the maxi...
three-divisors
def isThree(n: int) -> bool: """ Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false. An integer m is a divisor of n if there exists an integer k such that n = k * m. Example 1: >>> isThree(n = 2) >>> false Explantion: 2 has only two di...
maximum-number-of-weeks-for-which-you-can-work
def numberOfWeeks(milestones: List[int]) -> int: """ There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith project has. You can work on the projects following these two rules: Every week, you will f...
minimum-garden-perimeter-to-collect-enough-apples
def minimumPerimeter(neededApples: int) -> int: """ In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j) has |i| + |j| apples growing on it. You will buy an axis-aligned square plot of land that is ...
count-number-of-special-subsequences
def countSpecialSubsequences(nums: List[int]) -> int: """ A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s. For example, [0,1,2] and [0,0,1,1,1,2] are special. In contrast, [2,1,0], [1], and [0,1,2,0] are not special....
minimum-time-for-k-virus-variants-to-spread
def minDayskVariants(points: List[List[int]], k: int) -> int: """ There are n unique virus variants in an infinite 2D grid. You are given a 2D array points, where points[i] = [xi, yi] represents a virus originating at (xi, yi) on day 0. Note that it is possible for multiple virus variants to originate at the sa...
delete-characters-to-make-fancy-string
def makeFancyString(s: str) -> str: """ A fancy string is a string where no three consecutive characters are equal. Given a string s, delete the minimum possible number of characters from s to make it fancy. Return the final string after the deletion. It can be shown that the answer will always be uniqu...
check-if-move-is-legal
def checkMove(board: List[List[str]], rMove: int, cMove: int, color: str) -> bool: """ You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board. On the board, free cells are represented by '.', white cells are represented by 'W', and black cells are represented by...
minimum-total-space-wasted-with-k-resizing-operations
def minSpaceWastedKResizing(nums: List[int], k: int) -> int: """ 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 re...
maximum-product-of-the-length-of-two-palindromic-substrings
def maxProduct(s: str) -> int: """ You are given a 0-indexed string s and are tasked with finding two non-intersecting palindromic substrings of odd length such that the product of their lengths is maximized. More formally, you want to choose four integers i, j, k, l such that 0 <= i <= j < k <= l < s.lengt...
check-if-string-is-a-prefix-of-array
def isPrefixString(s: str, words: List[str]) -> bool: """ Given a string s and an array of strings words, determine whether s is a prefix string of words. A string s is a prefix string of words if s can be made by concatenating the first k strings in words for some positive k no larger than words.length. ...
remove-stones-to-minimize-the-total
def minStoneSum(piles: List[int], k: int) -> int: """ You are given a 0-indexed integer array piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remove floor(piles[i] / 2) stones from...
minimum-number-of-swaps-to-make-the-string-balanced
def minSwaps(s: str) -> int: """ You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'. A string is called balanced if and only if: It is the empty string, or It can be written as AB, where both A and B are ...