task_id
stringlengths
3
79
prompt
stringlengths
255
3.9k
find-the-longest-valid-obstacle-course-at-each-position
def longestObstacleCourseAtEachPosition(obstacles: List[int]) -> List[int]: """ You want to build some obstacle courses. You are given a 0-indexed integer array obstacles of length n, where obstacles[i] describes the height of the ith obstacle. For every index i between 0 and n - 1 (inclusive), find the len...
binary-searchable-numbers-in-an-unsorted-array
def binarySearchableNumbers(nums: List[int]) -> int: """ Consider a function that implements an algorithm similar to Binary Search. The function has two input parameters: sequence is a sequence of integers, and target is an integer value. The purpose of the function is to find if the target exists in the sequen...
number-of-strings-that-appear-as-substrings-in-word
def numOfStrings(patterns: List[str], word: str) -> int: """ Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word. A substring is a contiguous sequence of characters within a string. Example 1: >>> numOfStrings(pat...
array-with-elements-not-equal-to-average-of-neighbors
def rearrangeArray(nums: List[int]) -> List[int]: """ You are given a 0-indexed array nums of distinct integers. You want to rearrange the elements in the array such that every element in the rearranged array is not equal to the average of its neighbors. More formally, the rearranged array should have the p...
last-day-where-you-can-still-cross
def latestDayToCross(row: int, col: int, cells: List[List[int]]) -> int: """ There is a 1-based binary matrix where 0 represents land and 1 represents water. You are given integers row and col representing the number of rows and columns in the matrix, respectively. Initially on day 0, the entire matrix is l...
find-if-path-exists-in-graph
def validPath(n: int, edges: List[List[int]], source: int, destination: int) -> bool: """ There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a bi-dir...
count-nodes-equal-to-sum-of-descendants
# class TreeNode: # def __init__(val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def equalToDescendants(root: Optional[TreeNode]) -> int: """ Given the root of a binary tree, return the number of nodes where the value of the...
minimum-time-to-type-word-using-special-typewriter
def minTimeToType(word: str) -> int: """ There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointing to the character 'a'. Each second, you may ...
maximum-matrix-sum
def maxMatrixSum(matrix: List[List[int]]) -> int: """ You are given an n x n integer matrix. You can do the following operation any number of times: Choose any two adjacent elements of matrix and multiply each of them by -1. Two elements are considered adjacent if and only if they share a bord...
number-of-ways-to-arrive-at-destination
def countPaths(n: int, roads: List[List[int]]) -> int: """ You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other intersection and that there is at most one...
number-of-ways-to-separate-numbers
def numberOfCombinations(num: str) -> int: """ You wrote down many positive integers in a string called num. However, you realized that you forgot to add commas to seperate the different numbers. You remember that the list of integers was non-decreasing and that no integer had leading zeros. Return the numb...
find-greatest-common-divisor-of-array
def findGCD(nums: List[int]) -> int: """ Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums. The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers. Example 1: >>> findGCD(nu...
find-unique-binary-string
def findDifferentBinaryString(nums: List[str]) -> str: """ Given an array of strings nums containing n unique binary strings each of length n, return a binary string of length n that does not appear in nums. If there are multiple answers, you may return any of them. Example 1: >>> findDifferen...
minimize-the-difference-between-target-and-chosen-elements
def minimizeTheDifference(mat: List[List[int]], target: int) -> int: """ You are given an m x n integer matrix mat and an integer target. Choose one integer from each row in the matrix such that the absolute difference between target and the sum of the chosen elements is minimized. Return the minimum ab...
find-array-given-subset-sums
def recoverArray(n: int, sums: List[int]) -> List[int]: """ You are given an integer n representing the length of an unknown array that you are trying to recover. You are also given an array sums containing the values of all 2n subset sums of the unknown array (in no particular order). Return the array ans ...
widest-pair-of-indices-with-equal-range-sum
def widestPairOfIndices(nums1: List[int], nums2: List[int]) -> int: """ You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]. The widest pair of indices is the p...
minimum-difference-between-highest-and-lowest-of-k-scores
def minimumDifference(nums: List[int], k: int) -> int: """ You are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student. You are also given an integer k. Pick the scores of any k students from the array so that the difference between the highest and the lowest of the k...
find-the-kth-largest-integer-in-the-array
def kthLargestNumber(nums: List[str], k: int) -> str: """ You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros. Return the string that represents the kth largest integer in nums. Note: Duplicate numbers should be counted distinctly. For...
minimum-number-of-work-sessions-to-finish-the-tasks
def minSessions(tasks: List[int], sessionTime: int) -> int: """ There are n tasks assigned to you. The task times are represented as an integer array tasks of length n, where the ith task takes tasks[i] hours to finish. A work session is when you work for at most sessionTime consecutive hours and then take a br...
number-of-unique-good-subsequences
def numberOfUniqueGoodSubsequences(binary: str) -> int: """ You are given a binary string binary. A subsequence of binary is considered good if it is not empty and has no leading zeros (with the exception of "0"). Find the number of unique good subsequences of binary. For example, if binary = "001"...
maximum-number-of-people-that-can-be-caught-in-tag
def catchMaximumAmountofPeople(team: List[int], dist: int) -> int: """ You are playing a game of tag with your friends. In tag, people are divided into two teams: people who are "it", and people who are not "it". The people who are "it" want to catch as many people as possible who are not "it". You are give...
find-the-middle-index-in-array
def findMiddleIndex(nums: List[int]) -> int: """ Given a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones). A middleIndex is an index where nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + nums[num...
find-all-groups-of-farmland
def findFarmland(land: List[List[int]]) -> List[List[int]]: """ You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland. To keep the land organized, there are designated rectangular areas of hectares that consist entirely of...
the-number-of-good-subsets
def numberOfGoodSubsets(nums: List[int]) -> int: """ You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers. For example, if nums = [1, 2, 3, 4]: [2, 3], [1, 2, 3], and [1, 3] are good subsets...
count-special-quadruplets
def countQuadruplets(nums: List[int]) -> int: """ Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that: nums[a] + nums[b] + nums[c] == nums[d], and a < b < c < d Example 1: >>> countQuadruplets(nums = [1,2,3,6]) >>> 1 ...
the-number-of-weak-characters-in-the-game
def numberOfWeakCharacters(properties: List[List[int]]) -> int: """ You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] represents the properties of...
first-day-where-you-have-been-in-all-the-rooms
def firstDayBeenInAllRooms(nextVisit: List[int]) -> int: """ There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day. Initially on day 0, you visit room 0. The order you visit the rooms for the coming days is determined by t...
gcd-sort-of-an-array
def gcdSort(nums: List[int]) -> bool: """ You are given an integer array nums, and you can perform the following operation any number of times on nums: Swap the positions of two elements nums[i] and nums[j] if gcd(nums[i], nums[j]) > 1 where gcd(nums[i], nums[j]) is the greatest common divisor of nums[...
smallest-greater-multiple-made-of-two-digits
def findInteger(k: int, digit1: int, digit2: int) -> int: """ Given three integers, k, digit1, and digit2, you want to find the smallest integer that is: Larger than k, A multiple of k, and Comprised of only the digits digit1 and/or digit2. Return the smallest such integer. If no such ...
reverse-prefix-of-word
def reversePrefix(word: str, ch: str) -> str: """ Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing. For example, if word = "abcdefd...
number-of-pairs-of-interchangeable-rectangles
def interchangeableRectangles(rectangles: List[List[int]]) -> int: """ You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle. Two rectangles i and j (i < j) are considered interchangeable i...
maximum-product-of-the-length-of-two-palindromic-subsequences
def maxProduct(s: str) -> int: """ Given a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index. Return the maximum possible product of the lengths of the two pa...
smallest-missing-genetic-value-in-each-subtree
def smallestMissingValueSubtree(parents: List[int], nums: List[int]) -> List[int]: """ There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent for node i. Since node 0 is the root, parents[0] == -1. There a...
subtree-removal-game-with-fibonacci-tree
def findGameWinner(n: int) -> bool: """ A Fibonacci tree is a binary tree created using the order function order(n): order(0) is the empty tree. order(1) is a binary tree with only one node. order(n) is a binary tree that consists of a root node with the left subtree as order(n - 2) and the rig...
count-number-of-pairs-with-absolute-difference-k
def countKDifference(nums: List[int], k: int) -> int: """ Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k. The value of |x| is defined as: x if x >= 0. -x if x < 0. Example 1: >>> countKDiffere...
find-original-array-from-doubled-array
def findOriginalArray(changed: List[int]) -> List[int]: """ An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array. Given an array changed, return original if changed is a doubled array....
maximum-earnings-from-taxi
def maxTaxiEarnings(n: int, rides: List[List[int]]) -> int: """ There are n points on a road you are driving your taxi on. The n points on the road are labeled from 1 to n in the direction you are going, and you want to drive from point 1 to point n to make money by picking up passengers. You cannot change the ...
minimum-number-of-operations-to-make-array-continuous
def minOperations(nums: List[int]) -> int: """ You are given an integer array nums. In one operation, you can replace any element in nums with any integer. nums is considered continuous if both of the following conditions are fulfilled: All elements in nums are unique. The difference between th...
final-value-of-variable-after-performing-operations
def finalValueAfterOperations(operations: List[str]) -> int: """ There is a programming language with only four operations and one variable X: ++X and X++ increments the value of the variable X by 1. --X and X-- decrements the value of the variable X by 1. Initially, the value of X is 0. ...
sum-of-beauty-in-the-array
def sumOfBeauties(nums: List[int]) -> int: """ You are given a 0-indexed integer array nums. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals: 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1. 1, if nums[i - 1] < nums[i] < nums[i + ...
longest-subsequence-repeated-k-times
def longestSubsequenceRepeatedK(s: str, k: int) -> str: """ You are given a string s of length n, and an integer k. You are tasked to find the longest subsequence repeated k times in string s. A subsequence is a string that can be derived from another string by deleting some or no characters without changin...
average-height-of-buildings-in-each-segment
def averageHeightOfBuildings(buildings: List[List[int]]) -> List[List[int]]: """ A perfectly straight street is represented by a number line. The street has building(s) on it and is represented by a 2D integer array buildings, where buildings[i] = [starti, endi, heighti]. This means that there is a building wit...
maximum-difference-between-increasing-elements
def maximumDifference(nums: List[int]) -> int: """ Given a 0-indexed integer array nums of size n, find the maximum difference between nums[i] and nums[j] (i.e., nums[j] - nums[i]), such that 0 <= i < j < n and nums[i] < nums[j]. Return the maximum difference. If no such i and j exists, return -1. ...
grid-game
def gridGame(grid: List[List[int]]) -> int: """ You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix. Both robots initially start at (0, 0) and want to reach (1, n-1). Each robot...
check-if-word-can-be-placed-in-crossword
def placeWordInCrossword(board: List[List[str]], word: str) -> bool: """ You are given an m x n matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent any blocked cells. ...
the-score-of-students-solving-math-expression
def scoreOfStudents(s: str, answers: List[int]) -> int: """ You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n elementary school students. The stu...
brightest-position-on-street
def brightestPosition(lights: List[List[int]]) -> int: """ A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [positioni, rangei] indicates that there is a street lamp at position positioni that light...
convert-1d-array-into-2d-array
def construct2DArray(original: List[int], m: int, n: int) -> List[List[int]]: """ You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original. The eleme...
number-of-pairs-of-strings-with-concatenation-equal-to-target
def numOfPairs(nums: List[str], target: str) -> int: """ Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target. Example 1: >>> numOfPairs(nums = ["777","7","77",...
maximize-the-confusion-of-an-exam
def maxConsecutiveAnswers(answerKey: str, k: int) -> int: """ A teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing the number of consecutive questions with the same answer (multiple trues or multiple falses in a ro...
maximum-number-of-ways-to-partition-an-array
def waysToPartition(nums: List[int], k: int) -> int: """ You are given a 0-indexed integer array nums of length n. The number of ways to partition nums is the number of pivot indices that satisfy both conditions: 1 <= pivot < n nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot +...
minimum-moves-to-convert-string
def minimumMoves(s: str) -> int: """ You are given a string s consisting of n characters which are either 'X' or 'O'. A move is defined as selecting three consecutive characters of s and converting them to 'O'. Note that if a move is applied to the character 'O', it will stay the same. Return the minimu...
find-missing-observations
def missingRolls(rolls: List[int], mean: int, n: int) -> List[int]: """ You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m r...
stone-game-ix
def stoneGameIX(stones: List[int]) -> bool: """ Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone. Alice and Bob take turns, with Alice starting first. On ea...
smallest-k-length-subsequence-with-occurrences-of-a-letter
def smallestSubsequence(s: str, k: int, letter: str, repetition: int) -> str: """ You are given a string s, an integer k, a letter letter, and an integer repetition. Return the lexicographically smallest subsequence of s of length k that has the letter letter appear at least repetition times. The test cases...
count-subarrays-with-more-ones-than-zeros
def subarraysWithMoreZerosThanOnes(nums: List[int]) -> int: """ You are given a binary array nums containing only the integers 0 and 1. Return the number of subarrays in nums that have more 1's than 0's. Since the answer may be very large, return it modulo 109 + 7. A subarray is a contiguous sequence of ele...
two-out-of-three
def twoOutOfThree(nums1: List[int], nums2: List[int], nums3: List[int]) -> List[int]: """ Given three integer arrays nums1, nums2, and nums3, return a distinct array containing all the values that are present in at least two out of the three arrays. You may return the values in any order. Example 1: ...
minimum-operations-to-make-a-uni-value-grid
def minOperations(grid: List[List[int]], x: int) -> int: """ You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid. A uni-value grid is a grid where all the elements of it are equal. Return the minimum number of oper...
partition-array-into-two-arrays-to-minimize-sum-difference
def minimumDifference(nums: List[int]) -> int: """ You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays. Return the m...
maximum-alternating-subarray-sum
def maximumAlternatingSubarraySum(nums: List[int]) -> int: """ A subarray of a 0-indexed integer array is a contiguous non-empty sequence of elements within an array. The alternating subarray sum of a subarray that ranges from index i to j (inclusive, 0 <= i <= j < nums.length) is nums[i] - nums[i+1] + nums...
minimum-number-of-moves-to-seat-everyone
def minMovesToSeat(seats: List[int], students: List[int]) -> int: """ There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of th...
remove-colored-pieces-if-both-neighbors-are-the-same-color
def winnerOfGame(colors: str) -> bool: """ There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece. Alice and Bob are playing a game where they take alternating turns removing pieces fro...
the-time-when-the-network-becomes-idle
def networkBecomesIdle(edges: List[List[int]], patience: List[int]) -> int: """ There is a network of n servers, labeled from 0 to n - 1. You are given a 2D integer array edges, where edges[i] = [ui, vi] indicates there is a message channel between servers ui and vi, and they can pass any number of messages to ...
kth-smallest-product-of-two-sorted-arrays
def kthSmallestProduct(nums1: List[int], nums2: List[int], k: int) -> int: """ Given two sorted 0-indexed integer arrays nums1 and nums2 as well as an integer k, return the kth (1-based) smallest product of nums1[i] * nums2[j] where 0 <= i < nums1.length and 0 <= j < nums2.length. Example 1: >...
check-if-numbers-are-ascending-in-a-sentence
def areNumbersAscending(s: str) -> bool: """ A sentence is a list of tokens separated by a single space with no leading or trailing spaces. Every token is either a positive number consisting of digits 0-9 with no leading zeros, or a word consisting of lowercase English letters. For example, "a puppy ha...
count-number-of-maximum-bitwise-or-subsets
def countMaxOrSubsets(nums: List[int]) -> int: """ Given an integer array nums, find the maximum possible bitwise OR of a subset of nums and return the number of different non-empty subsets with the maximum bitwise OR. An array a is a subset of an array b if a can be obtained from b by deleting some (possib...
second-minimum-time-to-reach-destination
def secondMinimum(n: int, edges: List[List[int]], time: int, change: int) -> int: """ A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi]...
sort-linked-list-already-sorted-using-absolute-values
# class ListNode: # def __init__(val=0, next=None): # self.val = val # self.next = next class Solution: def sortLinkedList(head: Optional[ListNode]) -> Optional[ListNode]: """ Given the head of a singly linked list that is sorted in non-decreasing order using the absolute values of its n...
number-of-valid-words-in-a-sentence
def countValidWords(sentence: str) -> int: """ A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separated by one or more spaces ' '. A token is a v...
next-greater-numerically-balanced-number
def nextBeautifulNumber(n: int) -> int: """ An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x. Given an integer n, return the smallest numerically balanced number strictly greater than n. Example 1: >>> nextBeautif...
count-nodes-with-the-highest-score
def countHighestScoreNodes(parents: List[int]) -> int: """ There is a binary tree rooted at 0 consisting of n nodes. The nodes are labeled from 0 to n - 1. You are given a 0-indexed integer array parents representing the tree, where parents[i] is the parent of node i. Since node 0 is the root, parents[0] == -1....
parallel-courses-iii
def minimumTime(n: int, relations: List[List[int]], time: List[int]) -> int: """ You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given a 2D integer array relations where relations[j] = [prevCoursej, nextCoursej] denotes that course prevCoursej has to be com...
minimum-cost-to-separate-sentence-into-rows
def minimumCost(sentence: str, k: int) -> int: """ You are given a string sentence containing words separated by spaces, and an integer k. Your task is to separate sentence into rows where the number of characters in each row is at most k. You may assume that sentence does not begin or end with a space, and the...
kth-distinct-string-in-an-array
def kthDistinct(arr: List[str], k: int) -> str: """ A distinct string is a string that is present only once in an array. Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return an empty string "". Note that the st...
two-best-non-overlapping-events
def maxTwoEvents(events: List[List[int]]) -> int: """ You are given a 0-indexed 2D integer array of events where events[i] = [startTimei, endTimei, valuei]. The ith event starts at startTimei and ends at endTimei, and if you attend this event, you will receive a value of valuei. You can choose at most two non-o...
plates-between-candles
def platesBetweenCandles(s: str, queries: List[List[int]]) -> List[int]: """ There is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|' only, where a '*' represents a plate and a '|' represents a candle. You are also...
number-of-valid-move-combinations-on-chessboard
def countCombinations(pieces: List[str], positions: List[List[int]]) -> int: """ There is an 8 x 8 chessboard containing n pieces (rooks, queens, or bishops). You are given a string array pieces of length n, where pieces[i] describes the type (rook, queen, or bishop) of the ith piece. In addition, you are given...
smallest-index-with-equal-value
def smallestEqual(nums: List[int]) -> int: """ Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist. x mod y denotes the remainder when x is divided by y. Example 1: >>> smallestEqual(nums = [0,1,2]) ...
find-the-minimum-and-maximum-number-of-nodes-between-critical-points
# class ListNode: # def __init__(val=0, next=None): # self.val = val # self.next = next class Solution: def nodesBetweenCriticalPoints(head: Optional[ListNode]) -> List[int]: """ A critical point in a linked list is defined as either a local maxima or a local minima. A node is a loca...
minimum-operations-to-convert-number
def minimumOperations(nums: List[int], start: int, goal: int) -> int: """ You are given a 0-indexed integer array nums containing distinct numbers, an integer start, and an integer goal. There is an integer x that is initially set to start, and you want to perform operations on x such that it is converted to go...
check-if-an-original-string-exists-given-two-encoded-strings
def possiblyEquals(s1: str, s2: str) -> bool: """ An original string, consisting of lowercase English letters, can be encoded by the following steps: Arbitrarily split it into a sequence of some number of non-empty substrings. Arbitrarily choose some elements (possibly none) of the sequence, and re...
number-of-spaces-cleaning-robot-cleaned
def numberOfCleanRooms(room: List[List[int]]) -> int: """ A room is represented by a 0-indexed 2D binary matrix room where a 0 represents an empty space and a 1 represents a space with an object. The top left corner of the room will be empty in all test cases. A cleaning robot starts at the top left corner ...
count-vowel-substrings-of-a-string
def countVowelSubstrings(word: str) -> int: """ A substring is a contiguous (non-empty) sequence of characters within a string. A vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it. Given a string word, return the number of vow...
vowels-of-all-substrings
def countVowels(word: str) -> int: """ Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word. A substring is a contiguous (non-empty) sequence of characters within a string. Note: Due to the large constraints, the answer may not fit in a sig...
minimized-maximum-of-products-distributed-to-any-store
def minimizedMaximum(n: int, quantities: List[int]) -> int: """ You are given an integer n indicating there are n specialty retail stores. There are m product types of varying amounts, which are given as a 0-indexed integer array quantities, where quantities[i] represents the number of products of the ith produ...
maximum-path-quality-of-a-graph
def maximalPathQuality(values: List[int], edges: List[List[int]], maxTime: int) -> int: """ There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. You are also given a 0-indexed 2D integer array...
number-of-equal-count-substrings
def equalCountSubstrings(s: str, count: int) -> int: """ You are given a 0-indexed string s consisting of only lowercase English letters, and an integer count. A substring of s is said to be an equal count substring if, for each unique letter in the substring, it appears exactly count times in the substring. ...
check-whether-two-strings-are-almost-equivalent
def checkAlmostEquivalent(word1: str, word2: str) -> bool: """ Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 is at most 3. Given two strings word1 and word2, each of length n, return true if word...
most-beautiful-item-for-each-query
def maximumBeauty(items: List[List[int]], queries: List[int]) -> List[int]: """ You are given a 2D integer array items where items[i] = [pricei, beautyi] denotes the price and beauty of an item respectively. You are also given a 0-indexed integer array queries. For each queries[j], you want to determine the...
maximum-number-of-tasks-you-can-assign
def maxTaskAssign(tasks: List[int], workers: List[int], pills: int, strength: int) -> int: """ You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the ith task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-i...
time-needed-to-buy-tickets
def timeRequiredToBuy(tickets: List[int], k: int) -> int: """ There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed integer array tickets of length n where the number of tickets tha...
reverse-nodes-in-even-length-groups
# class ListNode: # def __init__(val=0, next=None): # self.val = val # self.next = next class Solution: def reverseEvenLengthGroups(head: Optional[ListNode]) -> Optional[ListNode]: """ You are given the head of a linked list. The nodes in the linked list are sequentially assigned to ...
decode-the-slanted-ciphertext
def decodeCiphertext(encodedText: str, rows: int) -> str: """ A string originalText is encoded using a slanted transposition cipher to a string encodedText with the help of a matrix having a fixed number of rows rows. originalText is placed first in a top-left to bottom-right manner. The blue cells...
process-restricted-friend-requests
def friendRequests(n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]: """ You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1. You are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [xi, ...
paths-in-maze-that-lead-to-same-room
def numberOfPaths(n: int, corridors: List[List[int]]) -> int: """ A maze consists of n rooms numbered from 1 to n, and some rooms are connected by corridors. You are given a 2D integer array corridors where corridors[i] = [room1i, room2i] indicates that there is a corridor connecting room1i and room2i, allowing...
two-furthest-houses-with-different-colors
def maxDistance(colors: List[int]) -> int: """ There are n houses evenly lined up on the street, and each house is beautifully painted. You are given a 0-indexed integer array colors of length n, where colors[i] represents the color of the ith house. Return the maximum distance between two houses with diffe...
watering-plants
def wateringPlants(plants: List[int], capacity: int) -> int: """ You want to water n plants in your garden with a watering can. The plants are arranged in a row and are labeled from 0 to n - 1 from left to right where the ith plant is located at x = i. There is a river at x = -1 that you can refill your waterin...
sum-of-k-mirror-numbers
def kMirror(k: int, n: int) -> int: """ A k-mirror number is a positive integer without leading zeros that reads the same both forward and backward in base-10 as well as in base-k. For example, 9 is a 2-mirror number. The representation of 9 in base-10 and base-2 are 9 and 1001 respectively, which read...
substrings-that-begin-and-end-with-the-same-letter
def numberOfSubstrings(s: str) -> int: """ You are given a 0-indexed string s consisting of only lowercase English letters. Return the number of substrings in s that begin and end with the same character. A substring is a contiguous non-empty sequence of characters within a string. Example 1: ...
count-common-words-with-one-occurrence
def countWords(words1: List[str], words2: List[str]) -> int: """ Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays. Example 1: >>> countWords(words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode",...