id
stringlengths
13
13
content
stringlengths
774
4.21k
test
dict
labels
dict
LeetCode/3024
# String Transformation You are given two strings `s` and `t` of equal length `n`. You can perform the following operation on the string `s`: * Remove a **suffix** of `s` of length `l` where `0 < l < n` and append it at the start of `s`. For example, let `s = 'abcd'` then in one operation you can remove the suff...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.numberOfWays(*['abcd', 'cdab', 2]) == 2\nassert my_solution.numberOfWays(*['ababab', 'ababab', 1]) == 2\nassert my_solution.numberOfWays(*['goxoq', 'dfqgl', 244326024901249]) == 0\nassert my_solution.numberOfWays(*['ceoce...
{ "programming_language": "python", "execution_language": "python", "questionId": "3024", "questionFrontendId": "2851", "questionTitle": "String Transformation", "stats": { "totalAccepted": "1.5K", "totalSubmission": "3.5K", "totalAcceptedRaw": 1493, "totalSubmissionRaw": 3522, "acRate":...
LeetCode/2998
# Count Symmetric Integers You are given two positive integers `low` and `high`. An integer `x` consisting of `2 * n` digits is **symmetric** if the sum of the first `n` digits of `x` is equal to the sum of the last `n` digits of `x`. Numbers with an odd number of digits are never symmetric. Return *the **number...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countSymmetricIntegers(*[1, 100]) == 9\nassert my_solution.countSymmetricIntegers(*[1200, 1230]) == 4\nassert my_solution.countSymmetricIntegers(*[1, 1]) == 0\nassert my_solution.countSymmetricIntegers(*[1, 2]) == 0\nasse...
{ "programming_language": "python", "execution_language": "python", "questionId": "2998", "questionFrontendId": "2843", "questionTitle": " Count Symmetric Integers", "stats": { "totalAccepted": "7.7K", "totalSubmission": "10.9K", "totalAcceptedRaw": 7725, "totalSubmissionRaw": 10853, "a...
LeetCode/3046
# Minimum Operations to Make a Special Number You are given a **0-indexed** string `num` representing a non-negative integer. In one operation, you can pick any digit of `num` and delete it. Note that if you delete all the digits of `num`, `num` becomes `0`. Return *the **minimum number of operations** required to...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumOperations(*['2245047']) == 2\nassert my_solution.minimumOperations(*['2908305']) == 3\nassert my_solution.minimumOperations(*['10']) == 1\nassert my_solution.minimumOperations(*['1']) == 1\nassert my_solution.mini...
{ "programming_language": "python", "execution_language": "python", "questionId": "3046", "questionFrontendId": "2844", "questionTitle": "Minimum Operations to Make a Special Number", "stats": { "totalAccepted": "5.5K", "totalSubmission": "13.3K", "totalAcceptedRaw": 5519, "totalSubmissionRa...
LeetCode/2915
# Count of Interesting Subarrays You are given a **0-indexed** integer array `nums`, an integer `modulo`, and an integer `k`. Your task is to find the count of subarrays that are **interesting**. A **subarray** `nums[l..r]` is **interesting** if the following condition holds: * Let `cnt` be the number of indices...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countInterestingSubarrays(*[[3, 2, 4], 2, 1]) == 3\nassert my_solution.countInterestingSubarrays(*[[3, 1, 9, 6], 3, 0]) == 2\nassert my_solution.countInterestingSubarrays(*[[11, 12, 21, 31], 10, 1]) == 5\nassert my_soluti...
{ "programming_language": "python", "execution_language": "python", "questionId": "2915", "questionFrontendId": "2845", "questionTitle": "Count of Interesting Subarrays", "stats": { "totalAccepted": "4.1K", "totalSubmission": "11.7K", "totalAcceptedRaw": 4117, "totalSubmissionRaw": 11655, ...
LeetCode/2999
# Check if Strings Can be Made Equal With Operations I You are given two strings `s1` and `s2`, both of length `4`, consisting of **lowercase** English letters. You can apply the following operation on any of the two strings **any** number of times: * Choose any two indices `i` and `j` such that `j - i = 2`, then ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.canBeEqual(*['abcd', 'cdab']) == True\nassert my_solution.canBeEqual(*['abcd', 'dacb']) == False\nassert my_solution.canBeEqual(*['bnxw', 'bwxn']) == True\nassert my_solution.canBeEqual(*['gudo', 'ogdu']) == False\nassert...
{ "programming_language": "python", "execution_language": "python", "questionId": "2999", "questionFrontendId": "2839", "questionTitle": "Check if Strings Can be Made Equal With Operations I", "stats": { "totalAccepted": "4.6K", "totalSubmission": "7.1K", "totalAcceptedRaw": 4637, "totalSubm...
LeetCode/2978
# Check if Strings Can be Made Equal With Operations II You are given two strings `s1` and `s2`, both of length `n`, consisting of **lowercase** English letters. You can apply the following operation on **any** of the two strings **any** number of times: * Choose any two indices `i` and `j` such that `i < j` and t...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.checkStrings(*['abcdba', 'cabdab']) == True\nassert my_solution.checkStrings(*['abe', 'bea']) == False\nassert my_solution.checkStrings(*['ublnlasppynwgx', 'ganplbuylnswpx']) == True\nassert my_solution.checkStrings(*['aa...
{ "programming_language": "python", "execution_language": "python", "questionId": "2978", "questionFrontendId": "2840", "questionTitle": "Check if Strings Can be Made Equal With Operations II", "stats": { "totalAccepted": "4K", "totalSubmission": "6.6K", "totalAcceptedRaw": 4011, "totalSubmi...
LeetCode/2954
# Maximum Sum of Almost Unique Subarray You are given an integer array `nums` and two positive integers `m` and `k`. Return *the **maximum sum** out of all **almost unique** subarrays of length* `k` *of* `nums`. If no such subarray exists, return `0`. A subarray of `nums` is **almost unique** if it contains at lea...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxSum(*[[2, 6, 7, 3, 1, 7], 3, 4]) == 18\nassert my_solution.maxSum(*[[5, 9, 9, 2, 4, 5, 4], 1, 3]) == 23\nassert my_solution.maxSum(*[[1, 2, 1, 2, 1, 2, 1], 3, 3]) == 0\nassert my_solution.maxSum(*[[1], 1, 1]) == 1\nass...
{ "programming_language": "python", "execution_language": "python", "questionId": "2954", "questionFrontendId": "2841", "questionTitle": "Maximum Sum of Almost Unique Subarray", "stats": { "totalAccepted": "4.4K", "totalSubmission": "9.9K", "totalAcceptedRaw": 4425, "totalSubmissionRaw": 994...
LeetCode/3057
# Count K-Subsequences of a String With Maximum Beauty You are given a string `s` and an integer `k`. A **k-subsequence** is a **subsequence** of `s`, having length `k`, and all its characters are **unique**, **i.e**., every character occurs once. Let `f(c)` denote the number of times the character `c` occurs in `...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countKSubsequencesWithMaxBeauty(*['bcca', 2]) == 4\nassert my_solution.countKSubsequencesWithMaxBeauty(*['abbcd', 4]) == 2\nassert my_solution.countKSubsequencesWithMaxBeauty(*['am', 2]) == 1\nassert my_solution.countKSub...
{ "programming_language": "python", "execution_language": "python", "questionId": "3057", "questionFrontendId": "2842", "questionTitle": "Count K-Subsequences of a String With Maximum Beauty", "stats": { "totalAccepted": "2.7K", "totalSubmission": "9.3K", "totalAcceptedRaw": 2658, "totalSubm...
LeetCode/3019
# Furthest Point From Origin You are given a string `moves` of length `n` consisting only of characters `'L'`, `'R'`, and `'_'`. The string represents your movement on a number line starting from the origin `0`. In the `ith` move, you can choose one of the following directions: * move to the left if `moves[i] = 'L...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.furthestDistanceFromOrigin(*['L_RL__R']) == 3\nassert my_solution.furthestDistanceFromOrigin(*['_R__LL_']) == 5\nassert my_solution.furthestDistanceFromOrigin(*['_______']) == 7\nassert my_solution.furthestDistanceFromOri...
{ "programming_language": "python", "execution_language": "python", "questionId": "3019", "questionFrontendId": "2833", "questionTitle": "Furthest Point From Origin", "stats": { "totalAccepted": "8.2K", "totalSubmission": "10.4K", "totalAcceptedRaw": 8173, "totalSubmissionRaw": 10353, "a...
LeetCode/3026
# Find the Minimum Possible Sum of a Beautiful Array You are given positive integers `n` and `target`. An array `nums` is **beautiful** if it meets the following conditions: * `nums.length == n`. * `nums` consists of pairwise **distinct** **positive** integers. * There doesn't exist two **distinct** indices, `i` a...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumPossibleSum(*[2, 3]) == 4\nassert my_solution.minimumPossibleSum(*[3, 3]) == 8\nassert my_solution.minimumPossibleSum(*[1, 1]) == 1\nassert my_solution.minimumPossibleSum(*[16, 6]) == 162\nassert my_solution.minimu...
{ "programming_language": "python", "execution_language": "python", "questionId": "3026", "questionFrontendId": "2834", "questionTitle": "Find the Minimum Possible Sum of a Beautiful Array", "stats": { "totalAccepted": "6.4K", "totalSubmission": "15.6K", "totalAcceptedRaw": 6372, "totalSubmi...
LeetCode/3025
# Minimum Operations to Form Subsequence With Target Sum You are given a **0-indexed** array `nums` consisting of **non-negative** powers of `2`, and an integer `target`. In one operation, you must apply the following changes to the array: * Choose any element of the array `nums[i]` such that `nums[i] > 1`. * Remo...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minOperations(*[[1, 2, 8], 7]) == 1\nassert my_solution.minOperations(*[[1, 32, 1, 2], 12]) == 2\nassert my_solution.minOperations(*[[1, 32, 1], 35]) == -1\nassert my_solution.minOperations(*[[1], 1]) == 0\nassert my_solu...
{ "programming_language": "python", "execution_language": "python", "questionId": "3025", "questionFrontendId": "2835", "questionTitle": "Minimum Operations to Form Subsequence With Target Sum", "stats": { "totalAccepted": "3.7K", "totalSubmission": "10.8K", "totalAcceptedRaw": 3709, "totalS...
LeetCode/3032
# Maximize Value of Function in a Ball Passing Game You are given a **0-indexed** integer array `receiver` of length `n` and an integer `k`. There are `n` players having a **unique id** in the range `[0, n - 1]` who will play a ball passing game, and `receiver[i]` is the id of the player who receives passes from the...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.getMaxFunctionValue(*[[2, 0, 1], 4]) == 6\nassert my_solution.getMaxFunctionValue(*[[1, 1, 1, 2, 3], 3]) == 10\nassert my_solution.getMaxFunctionValue(*[[0], 1]) == 0\nassert my_solution.getMaxFunctionValue(*[[0], 2]) == ...
{ "programming_language": "python", "execution_language": "python", "questionId": "3032", "questionFrontendId": "2836", "questionTitle": "Maximize Value of Function in a Ball Passing Game", "stats": { "totalAccepted": "2.5K", "totalSubmission": "6.3K", "totalAcceptedRaw": 2453, "totalSubmiss...
LeetCode/2977
# Check if a String Is an Acronym of Words Given an array of strings `words` and a string `s`, determine if `s` is an **acronym** of words. The string `s` is considered an acronym of `words` if it can be formed by concatenating the **first** character of each string in `words` **in order**. For example, `"ab"` can b...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.isAcronym(*[['alice', 'bob', 'charlie'], 'abc']) == True\nassert my_solution.isAcronym(*[['an', 'apple'], 'a']) == False\nassert my_solution.isAcronym(*[['never', 'gonna', 'give', 'up', 'on', 'you'], 'ngguoy']) == True\na...
{ "programming_language": "python", "execution_language": "python", "questionId": "2977", "questionFrontendId": "2828", "questionTitle": "Check if a String Is an Acronym of Words", "stats": { "totalAccepted": "29.8K", "totalSubmission": "35K", "totalAcceptedRaw": 29846, "totalSubmissionRaw":...
LeetCode/2811
# Determine the Minimum Sum of a k-avoiding Array You are given two integers, `n` and `k`. An array of **distinct** positive integers is called a **k-avoiding** array if there does not exist any pair of distinct elements that sum to `k`. Return *the **minimum** possible sum of a k-avoiding array of length* `n`. ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumSum(*[5, 4]) == 18\nassert my_solution.minimumSum(*[2, 6]) == 3\nassert my_solution.minimumSum(*[1, 1]) == 1\nassert my_solution.minimumSum(*[1, 2]) == 1\nassert my_solution.minimumSum(*[1, 3]) == 1\nassert my_solu...
{ "programming_language": "python", "execution_language": "python", "questionId": "2811", "questionFrontendId": "2829", "questionTitle": "Determine the Minimum Sum of a k-avoiding Array", "stats": { "totalAccepted": "6.7K", "totalSubmission": "11.3K", "totalAcceptedRaw": 6723, "totalSubmissi...
LeetCode/2979
# Maximize the Profit as the Salesman You are given an integer `n` representing the number of houses on a number line, numbered from `0` to `n - 1`. Additionally, you are given a 2D integer array `offers` where `offers[i] = [starti, endi, goldi]`, indicating that `ith` buyer wants to buy all the houses from `starti`...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximizeTheProfit(*[5, [[0, 0, 1], [0, 2, 2], [1, 3, 2]]]) == 3\nassert my_solution.maximizeTheProfit(*[5, [[0, 0, 1], [0, 2, 10], [1, 3, 2]]]) == 10\nassert my_solution.maximizeTheProfit(*[4, [[1, 3, 10], [1, 3, 3], [0, ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2979", "questionFrontendId": "2830", "questionTitle": "Maximize the Profit as the Salesman", "stats": { "totalAccepted": "5.8K", "totalSubmission": "13.7K", "totalAcceptedRaw": 5837, "totalSubmissionRaw": 1374...
LeetCode/2832
# Find the Longest Equal Subarray You are given a **0-indexed** integer array `nums` and an integer `k`. A subarray is called **equal** if all of its elements are equal. Note that the empty subarray is an **equal** subarray. Return *the length of the **longest** possible equal subarray after deleting **at most*** ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.longestEqualSubarray(*[[1, 3, 2, 3, 1, 3], 3]) == 3\nassert my_solution.longestEqualSubarray(*[[1, 1, 2, 2, 1, 1], 2]) == 4\nassert my_solution.longestEqualSubarray(*[[1], 0]) == 1\nassert my_solution.longestEqualSubarray...
{ "programming_language": "python", "execution_language": "python", "questionId": "2832", "questionFrontendId": "2831", "questionTitle": "Find the Longest Equal Subarray", "stats": { "totalAccepted": "4.9K", "totalSubmission": "11.9K", "totalAcceptedRaw": 4881, "totalSubmissionRaw": 11886, ...
LeetCode/2917
# Count Pairs Whose Sum is Less than Target Given a **0-indexed** integer array `nums` of length `n` and an integer `target`, return *the number of pairs* `(i, j)` *where* `0 <= i < j < n` *and* `nums[i] + nums[j] < target`.   **Example 1:** ``` **Input:** nums = [-1,1,2,3,1], target = 2 **Output:** 3 **Explanat...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countPairs(*[[-1, 1, 2, 3, 1], 2]) == 3\nassert my_solution.countPairs(*[[-6, 2, 5, -2, -7, -1, 3], -2]) == 10\nassert my_solution.countPairs(*[[9, -5, -5, 5, -5, -4, -6, 6, -6], 3]) == 27\nassert my_solution.countPairs(*...
{ "programming_language": "python", "execution_language": "python", "questionId": "2917", "questionFrontendId": "2824", "questionTitle": "Count Pairs Whose Sum is Less than Target", "stats": { "totalAccepted": "31.1K", "totalSubmission": "35.7K", "totalAcceptedRaw": 31062, "totalSubmissionRa...
LeetCode/3018
# Make String a Subsequence Using Cyclic Increments You are given two **0-indexed** strings `str1` and `str2`. In an operation, you select a **set** of indices in `str1`, and for each index `i` in the set, increment `str1[i]` to the next character **cyclically**. That is `'a'` becomes `'b'`, `'b'` becomes `'c'`, and...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.canMakeSubsequence(*['abc', 'ad']) == True\nassert my_solution.canMakeSubsequence(*['zc', 'ad']) == True\nassert my_solution.canMakeSubsequence(*['ab', 'd']) == False\nassert my_solution.canMakeSubsequence(*['a', 'd']) ==...
{ "programming_language": "python", "execution_language": "python", "questionId": "3018", "questionFrontendId": "2825", "questionTitle": "Make String a Subsequence Using Cyclic Increments", "stats": { "totalAccepted": "4.2K", "totalSubmission": "7.6K", "totalAcceptedRaw": 4195, "totalSubmiss...
LeetCode/2904
# Sorting Three Groups You are given a **0-indexed** integer array `nums` of length `n`. The numbers from `0` to `n - 1` are divided into three groups numbered from `1` to `3`, where number `i` belongs to group `nums[i]`. Notice that some groups may be **empty**. You are allowed to perform this operation...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumOperations(*[[2, 1, 3, 2, 1]]) == 3\nassert my_solution.minimumOperations(*[[1, 3, 2, 1, 3, 3]]) == 2\nassert my_solution.minimumOperations(*[[2, 2, 2, 2, 3, 3]]) == 0\nassert my_solution.minimumOperations(*[[1]]) ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2904", "questionFrontendId": "2826", "questionTitle": "Sorting Three Groups", "stats": { "totalAccepted": "3.8K", "totalSubmission": "7.2K", "totalAcceptedRaw": 3831, "totalSubmissionRaw": 7183, "acRate": ...
LeetCode/3017
# Number of Beautiful Integers in the Range You are given positive integers `low`, `high`, and `k`. A number is **beautiful** if it meets both of the following conditions: * The count of even digits in the number is equal to the count of odd digits. * The number is divisible by `k`. Return *the number of beautif...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.numberOfBeautifulIntegers(*[10, 20, 3]) == 2\nassert my_solution.numberOfBeautifulIntegers(*[1, 10, 1]) == 1\nassert my_solution.numberOfBeautifulIntegers(*[5, 5, 2]) == 0\nassert my_solution.numberOfBeautifulIntegers(*[3...
{ "programming_language": "python", "execution_language": "python", "questionId": "3017", "questionFrontendId": "2827", "questionTitle": "Number of Beautiful Integers in the Range", "stats": { "totalAccepted": "2.6K", "totalSubmission": "7.6K", "totalAcceptedRaw": 2579, "totalSubmissionRaw":...
LeetCode/2902
# Max Pair Sum in an Array You are given a **0-indexed** integer array `nums`. You have to find the **maximum** sum of a pair of numbers from `nums` such that the maximum **digit** in both numbers are equal. Return *the maximum sum or* `-1` *if no such pair exists*.   **Example 1:** ``` **Input:** nums = [51...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxSum(*[[51, 71, 17, 24, 42]]) == 88\nassert my_solution.maxSum(*[[1, 2, 3, 4]]) == -1\nassert my_solution.maxSum(*[[31, 25, 72, 79, 74]]) == 146\nassert my_solution.maxSum(*[[84, 91, 18, 59, 27, 9, 81, 33, 17, 58]]) == ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2902", "questionFrontendId": "2815", "questionTitle": "Max Pair Sum in an Array", "stats": { "totalAccepted": "8K", "totalSubmission": "11.8K", "totalAcceptedRaw": 8044, "totalSubmissionRaw": 11816, "acRat...
LeetCode/3000
# Minimum Absolute Difference Between Elements With Constraint You are given a **0-indexed** integer array `nums` and an integer `x`. Find the **minimum absolute difference** between two elements in the array that are at least `x` indices apart. In other words, find two indices `i` and `j` such that `abs(i - j) >=...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minAbsoluteDifference(*[[4, 3, 2, 4], 2]) == 0\nassert my_solution.minAbsoluteDifference(*[[5, 3, 2, 10, 15], 1]) == 1\nassert my_solution.minAbsoluteDifference(*[[1, 2, 3, 4], 3]) == 3\nassert my_solution.minAbsoluteDiff...
{ "programming_language": "python", "execution_language": "python", "questionId": "3000", "questionFrontendId": "2817", "questionTitle": "Minimum Absolute Difference Between Elements With Constraint", "stats": { "totalAccepted": "5.1K", "totalSubmission": "16K", "totalAcceptedRaw": 5075, "to...
LeetCode/3001
# Apply Operations to Maximize Score You are given an array `nums` of `n` positive integers and an integer `k`. Initially, you start with a score of `1`. You have to maximize your score by applying the following operation at most `k` times: * Choose any **non-empty** subarray `nums[l, ..., r]` that you haven't cho...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximumScore(*[[8, 3, 9, 3, 8], 2]) == 81\nassert my_solution.maximumScore(*[[19, 12, 14, 6, 10, 18], 3]) == 4788\nassert my_solution.maximumScore(*[[3289, 2832, 14858, 22011], 6]) == 256720975\nassert my_solution.maximum...
{ "programming_language": "python", "execution_language": "python", "questionId": "3001", "questionFrontendId": "2818", "questionTitle": "Apply Operations to Maximize Score", "stats": { "totalAccepted": "3.8K", "totalSubmission": "8.2K", "totalAcceptedRaw": 3825, "totalSubmissionRaw": 8220, ...
LeetCode/2886
# Faulty Keyboard Your laptop keyboard is faulty, and whenever you type a character `'i'` on it, it reverses the string that you have written. Typing other characters works as expected. You are given a **0-indexed** string `s`, and you type each character of `s` using your faulty keyboard. Return *the final string...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.finalString(*['string']) == rtsng\nassert my_solution.finalString(*['poiinter']) == ponter\nassert my_solution.finalString(*['goci']) == cog\nassert my_solution.finalString(*['ksi']) == sk\nassert my_solution.finalString(...
{ "programming_language": "python", "execution_language": "python", "questionId": "2886", "questionFrontendId": "2810", "questionTitle": "Faulty Keyboard", "stats": { "totalAccepted": "9.1K", "totalSubmission": "11.1K", "totalAcceptedRaw": 9146, "totalSubmissionRaw": 11110, "acRate": "82...
LeetCode/2916
# Check if it is Possible to Split Array You are given an array `nums` of length `n` and an integer `m`. You need to determine if it is possible to split the array into `n` **non-empty** arrays by performing a series of steps. In each step, you can select an existing array (which may be the result of previous steps)...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.canSplitArray(*[[2, 2, 1], 4]) == True\nassert my_solution.canSplitArray(*[[2, 1, 3], 5]) == False\nassert my_solution.canSplitArray(*[[2, 3, 3, 2, 3], 6]) == True\nassert my_solution.canSplitArray(*[[1], 1]) == True\nass...
{ "programming_language": "python", "execution_language": "python", "questionId": "2916", "questionFrontendId": "2811", "questionTitle": "Check if it is Possible to Split Array", "stats": { "totalAccepted": "7K", "totalSubmission": "21.6K", "totalAcceptedRaw": 7044, "totalSubmissionRaw": 215...
LeetCode/2894
# Maximum Elegance of a K-Length Subsequence You are given a **0-indexed** 2D integer array `items` of length `n` and an integer `k`. `items[i] = [profiti, categoryi]`, where `profiti` and `categoryi` denote the profit and category of the `ith` item respectively. Let's define the **elegance** of a **subsequence** ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.findMaximumElegance(*[[[3, 2], [5, 1], [10, 1]], 2]) == 17\nassert my_solution.findMaximumElegance(*[[[3, 1], [3, 1], [2, 2], [5, 3]], 3]) == 19\nassert my_solution.findMaximumElegance(*[[[1, 1], [2, 1], [3, 1]], 3]) == 7...
{ "programming_language": "python", "execution_language": "python", "questionId": "2894", "questionFrontendId": "2813", "questionTitle": "Maximum Elegance of a K-Length Subsequence", "stats": { "totalAccepted": "2.4K", "totalSubmission": "5.9K", "totalAcceptedRaw": 2415, "totalSubmissionRaw"...
LeetCode/2955
# Account Balance After Rounded Purchase Initially, you have a bank account balance of `100` dollars. You are given an integer `purchaseAmount` representing the amount you will spend on a purchase in dollars. At the store where you will make the purchase, the purchase amount is rounded to the **nearest multiple** ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.accountBalanceAfterPurchase(*[9]) == 90\nassert my_solution.accountBalanceAfterPurchase(*[15]) == 80\nassert my_solution.accountBalanceAfterPurchase(*[10]) == 90\nassert my_solution.accountBalanceAfterPurchase(*[11]) == 9...
{ "programming_language": "python", "execution_language": "python", "questionId": "2955", "questionFrontendId": "2806", "questionTitle": "Account Balance After Rounded Purchase", "stats": { "totalAccepted": "4.7K", "totalSubmission": "7.5K", "totalAcceptedRaw": 4681, "totalSubmissionRaw": 75...
LeetCode/2920
# Minimum Seconds to Equalize a Circular Array You are given a **0-indexed** array `nums` containing `n` integers. At each second, you perform the following operation on the array: * For every index `i` in the range `[0, n - 1]`, replace `nums[i]` with either `nums[i]`, `nums[(i - 1 + n) % n]`, or `nums[(i + 1) % ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumSeconds(*[[1, 2, 1, 2]]) == 1\nassert my_solution.minimumSeconds(*[[2, 1, 3, 3, 2]]) == 2\nassert my_solution.minimumSeconds(*[[5, 5, 5, 5]]) == 0\nassert my_solution.minimumSeconds(*[[4, 18]]) == 1\nassert my_solu...
{ "programming_language": "python", "execution_language": "python", "questionId": "2920", "questionFrontendId": "2808", "questionTitle": "Minimum Seconds to Equalize a Circular Array", "stats": { "totalAccepted": "3.2K", "totalSubmission": "8.7K", "totalAcceptedRaw": 3192, "totalSubmissionRa...
LeetCode/2952
# Minimum Time to Make Array Sum At Most x You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length. Every second, for all indices `0 <= i < nums1.length`, value of `nums1[i]` is incremented by `nums2[i]`. **After** this is done, you can do the following operation: * Choose an index `0 <= i...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumTime(*[[1, 2, 3], [1, 2, 3], 4]) == 3\nassert my_solution.minimumTime(*[[1, 2, 3], [3, 3, 3], 4]) == -1\nassert my_solution.minimumTime(*[[4, 4, 9, 10], [4, 4, 1, 3], 16]) == 4\nassert my_solution.minimumTime(*[[5,...
{ "programming_language": "python", "execution_language": "python", "questionId": "2952", "questionFrontendId": "2809", "questionTitle": "Minimum Time to Make Array Sum At Most x", "stats": { "totalAccepted": "10.8K", "totalSubmission": "17.4K", "totalAcceptedRaw": 10761, "totalSubmissionRaw...
LeetCode/2876
# Number of Employees Who Met the Target There are `n` employees in a company, numbered from `0` to `n - 1`. Each employee `i` has worked for `hours[i]` hours in the company. The company requires each employee to work for **at least** `target` hours. You are given a **0-indexed** array of non-negative integers `ho...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.numberOfEmployeesWhoMetTarget(*[[0, 1, 2, 3, 4], 2]) == 3\nassert my_solution.numberOfEmployeesWhoMetTarget(*[[5, 1, 4, 2, 2], 6]) == 0\nassert my_solution.numberOfEmployeesWhoMetTarget(*[[98], 5]) == 1\nassert my_solutio...
{ "programming_language": "python", "execution_language": "python", "questionId": "2876", "questionFrontendId": "2798", "questionTitle": "Number of Employees Who Met the Target", "stats": { "totalAccepted": "10.2K", "totalSubmission": "11.9K", "totalAcceptedRaw": 10171, "totalSubmissionRaw":...
LeetCode/2856
# Count Complete Subarrays in an Array You are given an array `nums` consisting of **positive** integers. We call a subarray of an array **complete** if the following condition is satisfied: * The number of **distinct** elements in the subarray is equal to the number of distinct elements in the whole array. Retu...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countCompleteSubarrays(*[[1, 3, 1, 2, 2]]) == 4\nassert my_solution.countCompleteSubarrays(*[[5, 5, 5, 5]]) == 10\nassert my_solution.countCompleteSubarrays(*[[459, 459, 962, 1579, 1435, 756, 1872, 1597]]) == 2\nassert my...
{ "programming_language": "python", "execution_language": "python", "questionId": "2856", "questionFrontendId": "2799", "questionTitle": "Count Complete Subarrays in an Array", "stats": { "totalAccepted": "7.4K", "totalSubmission": "12.6K", "totalAcceptedRaw": 7372, "totalSubmissionRaw": 126...
LeetCode/2877
# Shortest String That Contains Three Strings Given three strings `a`, `b`, and `c`, your task is to find a string that has the **minimum** length and contains all three strings as **substrings**. If there are multiple such strings, return the**lexicographicallysmallest** one. Return *a string denoting the answer to...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumString(*['abc', 'bca', 'aaa']) == aaabca\nassert my_solution.minimumString(*['ab', 'ba', 'aba']) == aba\nassert my_solution.minimumString(*['xyyyz', 'xzyz', 'zzz']) == xyyyzxzyzzz\nassert my_solution.minimumString(...
{ "programming_language": "python", "execution_language": "python", "questionId": "2877", "questionFrontendId": "2800", "questionTitle": "Shortest String That Contains Three Strings", "stats": { "totalAccepted": "4.6K", "totalSubmission": "13.2K", "totalAcceptedRaw": 4622, "totalSubmissionRa...
LeetCode/2921
# Count Stepping Numbers in Range Given two positive integers `low` and `high` represented as strings, find the count of **stepping numbers** in the inclusive range `[low, high]`. A **stepping number** is an integer such that all of its adjacent digits have an absolute difference of **exactly** `1`. Return *an int...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countSteppingNumbers(*['1', '11']) == 10\nassert my_solution.countSteppingNumbers(*['90', '101']) == 2\nassert my_solution.countSteppingNumbers(*['2', '40']) == 14\nassert my_solution.countSteppingNumbers(*['26', '60']) =...
{ "programming_language": "python", "execution_language": "python", "questionId": "2921", "questionFrontendId": "2801", "questionTitle": "Count Stepping Numbers in Range", "stats": { "totalAccepted": "2.9K", "totalSubmission": "6.9K", "totalAcceptedRaw": 2947, "totalSubmissionRaw": 6888, ...
LeetCode/2881
# Split Strings by Separator Given an array of strings `words` and a character `separator`, **split** each string in `words` by `separator`. Return *an array of strings containing the new strings formed after the splits, **excluding empty strings**.* **Notes** * `separator` is used to determine where the split s...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.splitWordsBySeparator(*[['one.two.three', 'four.five', 'six'], '.']) == ['one', 'two', 'three', 'four', 'five', 'six']\nassert my_solution.splitWordsBySeparator(*[['$easy$', '$problem$'], '$']) == ['easy', 'problem']\nass...
{ "programming_language": "python", "execution_language": "python", "questionId": "2881", "questionFrontendId": "2788", "questionTitle": "Split Strings by Separator", "stats": { "totalAccepted": "23.7K", "totalSubmission": "29.4K", "totalAcceptedRaw": 23744, "totalSubmissionRaw": 29444, ...
LeetCode/2872
# Largest Element in an Array after Merge Operations You are given a **0-indexed** array `nums` consisting of positive integers. You can do the following operation on the array **any** number of times: * Choose an integer `i` such that `0 <= i < nums.length - 1` and `nums[i] <= nums[i + 1]`. Replace the element `n...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxArrayValue(*[[2, 3, 7, 9, 3]]) == 21\nassert my_solution.maxArrayValue(*[[5, 3, 3]]) == 11\nassert my_solution.maxArrayValue(*[[77]]) == 77\nassert my_solution.maxArrayValue(*[[34, 95, 50, 12, 25, 100, 21, 3, 25, 16, 7...
{ "programming_language": "python", "execution_language": "python", "questionId": "2872", "questionFrontendId": "2789", "questionTitle": "Largest Element in an Array after Merge Operations", "stats": { "totalAccepted": "6.5K", "totalSubmission": "13.1K", "totalAcceptedRaw": 6493, "totalSubmi...
LeetCode/2919
# Maximum Number of Groups With Increasing Length You are given a **0-indexed** array `usageLimits` of length `n`. Your task is to create **groups** using numbers from `0` to `n - 1`, ensuring that each number, `i`, is used no more than `usageLimits[i]` times in total **across all groups**. You must also satisfy the...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxIncreasingGroups(*[[1, 2, 5]]) == 3\nassert my_solution.maxIncreasingGroups(*[[2, 1, 2]]) == 2\nassert my_solution.maxIncreasingGroups(*[[1, 1]]) == 1\nassert my_solution.maxIncreasingGroups(*[[1, 4]]) == 2\nassert my_...
{ "programming_language": "python", "execution_language": "python", "questionId": "2919", "questionFrontendId": "2790", "questionTitle": "Maximum Number of Groups With Increasing Length", "stats": { "totalAccepted": "2.8K", "totalSubmission": "12.7K", "totalAcceptedRaw": 2801, "totalSubmissi...
LeetCode/2892
# Check if Array is Good You are given an integer array `nums`. We consider an array **good** if it is a permutation of an array `base[n]`. `base[n] = [1, 2, ..., n - 1, n, n]` (in other words, it is an array of length `n + 1` which contains `1` to `n - 1` exactly once, plus two occurrences of `n`). For example, `ba...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.isGood(*[[2, 1, 3]]) == False\nassert my_solution.isGood(*[[1, 3, 3, 2]]) == True\nassert my_solution.isGood(*[[1, 1]]) == True\nassert my_solution.isGood(*[[3, 4, 4, 1, 2, 1]]) == False\nassert my_solution.isGood(*[[1]])...
{ "programming_language": "python", "execution_language": "python", "questionId": "2892", "questionFrontendId": "2784", "questionTitle": "Check if Array is Good", "stats": { "totalAccepted": "4.8K", "totalSubmission": "7.7K", "totalAcceptedRaw": 4778, "totalSubmissionRaw": 7743, "acRate"...
LeetCode/2887
# Sort Vowels in a String Given a **0-indexed** string `s`, **permute** `s` to get a new string `t` such that: * All consonants remain in their original places. More formally, if there is an index `i` with `0 <= i < s.length` such that `s[i]` is a consonant, then `t[i] = s[i]`. * The vowels must be sorted in the **n...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.sortVowels(*['lEetcOde']) == lEOtcede\nassert my_solution.sortVowels(*['lYmpH']) == lYmpH\nassert my_solution.sortVowels(*['mDVD']) == mDVD\nassert my_solution.sortVowels(*['xdX']) == xdX\nassert my_solution.sortVowels(*[...
{ "programming_language": "python", "execution_language": "python", "questionId": "2887", "questionFrontendId": "2785", "questionTitle": "Sort Vowels in a String", "stats": { "totalAccepted": "4.2K", "totalSubmission": "5.5K", "totalAcceptedRaw": 4201, "totalSubmissionRaw": 5452, "acRate...
LeetCode/2893
# Visit Array Positions to Maximize Score You are given a **0-indexed** integer array `nums` and a positive integer `x`. You are **initially** at position `0` in the array and you can visit other positions according to the following rules: * If you are currently in position `i`, then you can move to **any** positi...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxScore(*[[2, 3, 6, 1, 9, 2], 5]) == 13\nassert my_solution.maxScore(*[[2, 4, 6, 8], 3]) == 20\nassert my_solution.maxScore(*[[38, 92, 23, 30, 25, 96, 6, 71, 78, 77, 33, 23, 71, 48, 87, 77, 53, 28, 6, 20, 90, 83, 42, 21,...
{ "programming_language": "python", "execution_language": "python", "questionId": "2893", "questionFrontendId": "2786", "questionTitle": "Visit Array Positions to Maximize Score", "stats": { "totalAccepted": "3.8K", "totalSubmission": "9.5K", "totalAcceptedRaw": 3830, "totalSubmissionRaw": 9...
LeetCode/2882
# Ways to Express an Integer as Sum of Powers Given two **positive** integers `n` and `x`. Return *the number of ways* `n` *can be expressed as the sum of the* `xth` *power of **unique** positive integers, in other words, the number of sets of unique integers* `[n1, n2, ..., nk]` *where* `n = n1x + n2x + ... + nkx`*...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.numberOfWays(*[10, 2]) == 1\nassert my_solution.numberOfWays(*[4, 1]) == 2\nassert my_solution.numberOfWays(*[1, 1]) == 1\nassert my_solution.numberOfWays(*[1, 2]) == 1\nassert my_solution.numberOfWays(*[1, 3]) == 1\nasse...
{ "programming_language": "python", "execution_language": "python", "questionId": "2882", "questionFrontendId": "2787", "questionTitle": "Ways to Express an Integer as Sum of Powers", "stats": { "totalAccepted": "3.3K", "totalSubmission": "7.5K", "totalAcceptedRaw": 3345, "totalSubmissionRaw...
LeetCode/2844
# Sum of Squares of Special Elements You are given a **1-indexed** integer array `nums` of length `n`. An element `nums[i]` of `nums` is called **special** if `i` divides `n`, i.e. `n % i == 0`. Return *the **sum of the squares** of all **special** elements of* `nums`.   **Example 1:** ``` **Input:** nums...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.sumOfSquares(*[[1, 2, 3, 4]]) == 21\nassert my_solution.sumOfSquares(*[[2, 7, 1, 19, 18, 3]]) == 63\nassert my_solution.sumOfSquares(*[[1]]) == 1\nassert my_solution.sumOfSquares(*[[2]]) == 4\nassert my_solution.sumOfSqua...
{ "programming_language": "python", "execution_language": "python", "questionId": "2844", "questionFrontendId": "2778", "questionTitle": "Sum of Squares of Special Elements ", "stats": { "totalAccepted": "8.2K", "totalSubmission": "10.4K", "totalAcceptedRaw": 8223, "totalSubmissionRaw": 1040...
LeetCode/2891
# Maximum Beauty of an Array After Applying Operation You are given a **0-indexed** array `nums` and a **non-negative** integer `k`. In one operation, you can do the following: * Choose an index `i` that **hasn't been chosen before** from the range `[0, nums.length - 1]`. * Replace `nums[i]` with any integer from ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximumBeauty(*[[4, 6, 1, 2], 2]) == 3\nassert my_solution.maximumBeauty(*[[1, 1, 1, 1], 10]) == 4\nassert my_solution.maximumBeauty(*[[12, 71], 10]) == 1\nassert my_solution.maximumBeauty(*[[27, 55], 1]) == 1\nassert my_...
{ "programming_language": "python", "execution_language": "python", "questionId": "2891", "questionFrontendId": "2779", "questionTitle": "Maximum Beauty of an Array After Applying Operation", "stats": { "totalAccepted": "6.7K", "totalSubmission": "16.7K", "totalAcceptedRaw": 6655, "totalSubm...
LeetCode/2888
# Minimum Index of a Valid Split An element `x` of an integer array `arr` of length `m` is **dominant** if `freq(x) * 2 > m`, where `freq(x)` is the number of occurrences of `x` in `arr`. Note that this definition implies that `arr` can have **at most one** dominant element. You are given a **0-indexed** integer arr...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumIndex(*[[1, 2, 2, 2]]) == 2\nassert my_solution.minimumIndex(*[[2, 1, 3, 1, 1, 1, 7, 1, 2, 1]]) == 4\nassert my_solution.minimumIndex(*[[3, 3, 3, 3, 7, 2, 2]]) == -1\nassert my_solution.minimumIndex(*[[1]]) == -1\n...
{ "programming_language": "python", "execution_language": "python", "questionId": "2888", "questionFrontendId": "2780", "questionTitle": "Minimum Index of a Valid Split", "stats": { "totalAccepted": "5K", "totalSubmission": "7.5K", "totalAcceptedRaw": 4951, "totalSubmissionRaw": 7546, "a...
LeetCode/2884
# Length of the Longest Valid Substring You are given a string `word` and an array of strings `forbidden`. A string is called **valid** if none of its substrings are present in `forbidden`. Return *the length of the **longest valid substring** of the string* `word`. A **substring** is a contiguous sequence of ch...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.longestValidSubstring(*['cbaaaabc', ['aaa', 'cb']]) == 4\nassert my_solution.longestValidSubstring(*['leetcode', ['de', 'le', 'e']]) == 4\nassert my_solution.longestValidSubstring(*['a', ['n']]) == 1\nassert my_solution.l...
{ "programming_language": "python", "execution_language": "python", "questionId": "2884", "questionFrontendId": "2781", "questionTitle": "Length of the Longest Valid Substring", "stats": { "totalAccepted": "4K", "totalSubmission": "10.3K", "totalAcceptedRaw": 4003, "totalSubmissionRaw": 1032...
LeetCode/2812
# Find the Maximum Achievable Number You are given two integers, `num` and `t`. An integer `x` is called **achievable** if it can become equal to `num` after applying the following operation no more than `t` times: * Increase or decrease `x` by `1`, and simultaneously increase or decrease `num` by `1`. Return *t...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.theMaximumAchievableX(*[4, 1]) == 6\nassert my_solution.theMaximumAchievableX(*[3, 2]) == 7\nassert my_solution.theMaximumAchievableX(*[1, 1]) == 3\nassert my_solution.theMaximumAchievableX(*[1, 2]) == 5\nassert my_soluti...
{ "programming_language": "python", "execution_language": "python", "questionId": "2812", "questionFrontendId": "2769", "questionTitle": "Find the Maximum Achievable Number", "stats": { "totalAccepted": "13.9K", "totalSubmission": "15.5K", "totalAcceptedRaw": 13921, "totalSubmissionRaw": 155...
LeetCode/2855
# Maximum Number of Jumps to Reach the Last Index You are given a **0-indexed** array `nums` of `n` integers and an integer `target`. You are initially positioned at index `0`. In one step, you can jump from index `i` to any index `j` such that: * `0 <= i < j < n` * `-target <= nums[j] - nums[i] <= target` Retur...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximumJumps(*[[1, 3, 6, 4, 1, 2], 2]) == 3\nassert my_solution.maximumJumps(*[[1, 3, 6, 4, 1, 2], 3]) == 5\nassert my_solution.maximumJumps(*[[1, 3, 6, 4, 1, 2], 0]) == -1\nassert my_solution.maximumJumps(*[[0, 1], 0]) =...
{ "programming_language": "python", "execution_language": "python", "questionId": "2855", "questionFrontendId": "2770", "questionTitle": "Maximum Number of Jumps to Reach the Last Index", "stats": { "totalAccepted": "6.8K", "totalSubmission": "19K", "totalAcceptedRaw": 6779, "totalSubmission...
LeetCode/2869
# Longest Non-decreasing Subarray From Two Arrays You are given two **0-indexed** integer arrays `nums1` and `nums2` of length `n`. Let's define another **0-indexed** integer array, `nums3`, of length `n`. For each index `i` in the range `[0, n - 1]`, you can assign either `nums1[i]` or `nums2[i]` to `nums3[i]`. Y...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxNonDecreasingLength(*[[2, 3, 1], [1, 2, 1]]) == 2\nassert my_solution.maxNonDecreasingLength(*[[1, 3, 2, 1], [2, 2, 3, 4]]) == 4\nassert my_solution.maxNonDecreasingLength(*[[1, 1], [2, 2]]) == 2\nassert my_solution.ma...
{ "programming_language": "python", "execution_language": "python", "questionId": "2869", "questionFrontendId": "2771", "questionTitle": "Longest Non-decreasing Subarray From Two Arrays", "stats": { "totalAccepted": "5.7K", "totalSubmission": "16.3K", "totalAcceptedRaw": 5687, "totalSubmissi...
LeetCode/2878
# Apply Operations to Make All Array Elements Equal to Zero You are given a **0-indexed** integer array `nums` and a positive integer `k`. You can apply the following operation on the array **any** number of times: * Choose **any** subarray of size `k` from the array and **decrease** all its elements by `1`. Ret...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.checkArray(*[[2, 2, 3, 1, 1, 0], 3]) == True\nassert my_solution.checkArray(*[[1, 3, 1, 1], 2]) == False\nassert my_solution.checkArray(*[[60, 72, 87, 89, 63, 52, 64, 62, 31, 37, 57, 83, 98, 94, 92, 77, 94, 91, 87, 100, 9...
{ "programming_language": "python", "execution_language": "python", "questionId": "2878", "questionFrontendId": "2772", "questionTitle": "Apply Operations to Make All Array Elements Equal to Zero", "stats": { "totalAccepted": "5.6K", "totalSubmission": "15K", "totalAcceptedRaw": 5587, "total...
LeetCode/2870
# Longest Alternating Subarray You are given a **0-indexed** integer array `nums`. A subarray `s` of length `m` is called **alternating** if: * `m` is greater than `1`. * `s1 = s0 + 1`. * The **0-indexed** subarray `s` looks like `[s0, s1, s0, s1,...,s(m-1) % 2]`. In other words, `s1 - s0 = 1`, `s2 - s1 = -1`, `s3 -...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.alternatingSubarray(*[[2, 3, 4, 3, 4]]) == 4\nassert my_solution.alternatingSubarray(*[[4, 5, 6]]) == 2\nassert my_solution.alternatingSubarray(*[[31, 32, 31, 32, 33]]) == 4\nassert my_solution.alternatingSubarray(*[[21, ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2870", "questionFrontendId": "2765", "questionTitle": "Longest Alternating Subarray", "stats": { "totalAccepted": "14.8K", "totalSubmission": "29.8K", "totalAcceptedRaw": 14784, "totalSubmissionRaw": 29841, ...
LeetCode/2834
# Relocate Marbles You are given a **0-indexed** integer array `nums` representing the initial positions of some marbles. You are also given two **0-indexed** integer arrays `moveFrom` and `moveTo` of **equal** length. Throughout `moveFrom.length` steps, you will change the positions of the marbles. On the `ith` ste...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.relocateMarbles(*[[1, 6, 7, 8], [1, 7, 2], [2, 9, 5]]) == [5, 6, 8, 9]\nassert my_solution.relocateMarbles(*[[1, 1, 3, 3], [1, 3], [2, 2]]) == [2]\nassert my_solution.relocateMarbles(*[[5, 7, 8, 15], [5, 7, 8, 9], [9, 15,...
{ "programming_language": "python", "execution_language": "python", "questionId": "2834", "questionFrontendId": "2766", "questionTitle": "Relocate Marbles", "stats": { "totalAccepted": "3.8K", "totalSubmission": "6.9K", "totalAcceptedRaw": 3816, "totalSubmissionRaw": 6860, "acRate": "55....
LeetCode/2883
# Partition String Into Minimum Beautiful Substrings Given a binary string `s`, partition the string into one or more **substrings** such that each substring is **beautiful**. A string is **beautiful** if: * It doesn't contain leading zeros. * It's the **binary** representation of a number that is a power of `5`. ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumBeautifulSubstrings(*['1011']) == 2\nassert my_solution.minimumBeautifulSubstrings(*['111']) == 3\nassert my_solution.minimumBeautifulSubstrings(*['0']) == -1\nassert my_solution.minimumBeautifulSubstrings(*['10011...
{ "programming_language": "python", "execution_language": "python", "questionId": "2883", "questionFrontendId": "2767", "questionTitle": "Partition String Into Minimum Beautiful Substrings", "stats": { "totalAccepted": "3.2K", "totalSubmission": "5.6K", "totalAcceptedRaw": 3180, "totalSubmis...
LeetCode/2866
# Longest Even Odd Subarray With Threshold You are given a **0-indexed** integer array `nums` and an integer `threshold`. Find the length of the **longest subarray** of `nums` starting at index `l` and ending at index `r` `(0 <= l <= r < nums.length)` that satisfies the following conditions: * `nums[l] % 2 == 0` *...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.longestAlternatingSubarray(*[[3, 2, 5, 4], 5]) == 3\nassert my_solution.longestAlternatingSubarray(*[[1, 2], 2]) == 1\nassert my_solution.longestAlternatingSubarray(*[[2, 3, 4, 5], 4]) == 3\nassert my_solution.longestAlte...
{ "programming_language": "python", "execution_language": "python", "questionId": "2866", "questionFrontendId": "2760", "questionTitle": "Longest Even Odd Subarray With Threshold", "stats": { "totalAccepted": "28.9K", "totalSubmission": "63.7K", "totalAcceptedRaw": 28941, "totalSubmissionRaw...
LeetCode/2873
# Prime Pairs With Target Sum You are given an integer `n`. We say that two integers `x` and `y` form a prime number pair if: * `1 <= x <= y <= n` * `x + y == n` * `x` and `y` are prime numbers Return *the 2D sorted list of prime number pairs* `[xi, yi]`. The list should be sorted in **increasing** order of `xi`. ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.findPrimePairs(*[10]) == [[3, 7], [5, 5]]\nassert my_solution.findPrimePairs(*[2]) == []\nassert my_solution.findPrimePairs(*[1]) == []\nassert my_solution.findPrimePairs(*[3]) == []\nassert my_solution.findPrimePairs(*[4...
{ "programming_language": "python", "execution_language": "python", "questionId": "2873", "questionFrontendId": "2761", "questionTitle": "Prime Pairs With Target Sum", "stats": { "totalAccepted": "6.1K", "totalSubmission": "17.8K", "totalAcceptedRaw": 6135, "totalSubmissionRaw": 17830, "...
LeetCode/2868
# Continuous Subarrays You are given a **0-indexed** integer array `nums`. A subarray of `nums` is called **continuous** if: * Let `i`, `i + 1`, ..., `j`be the indices in the subarray. Then, for each pair of indices `i <= i1, i2 <= j`, `0 <= |nums[i1] - nums[i2]| <= 2`. Return *the total number of **continuous** s...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.continuousSubarrays(*[[5, 4, 2, 4]]) == 8\nassert my_solution.continuousSubarrays(*[[1, 2, 3]]) == 6\nassert my_solution.continuousSubarrays(*[[31, 30, 31, 32]]) == 10\nassert my_solution.continuousSubarrays(*[[65, 66, 67...
{ "programming_language": "python", "execution_language": "python", "questionId": "2868", "questionFrontendId": "2762", "questionTitle": "Continuous Subarrays", "stats": { "totalAccepted": "5K", "totalSubmission": "10.4K", "totalAcceptedRaw": 5024, "totalSubmissionRaw": 10377, "acRate": ...
LeetCode/2849
# Sum of Imbalance Numbers of All Subarrays The **imbalance number** of a **0-indexed** integer array `arr` of length `n` is defined as the number of indices in `sarr = sorted(arr)` such that: * `0 <= i < n - 1`, and * `sarr[i+1] - sarr[i] > 1` Here, `sorted(arr)` is the function that returns the sorted version of...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.sumImbalanceNumbers(*[[2, 3, 1, 4]]) == 3\nassert my_solution.sumImbalanceNumbers(*[[1, 3, 3, 3, 5]]) == 8\nassert my_solution.sumImbalanceNumbers(*[[1]]) == 0\nassert my_solution.sumImbalanceNumbers(*[[1, 1]]) == 0\nasse...
{ "programming_language": "python", "execution_language": "python", "questionId": "2849", "questionFrontendId": "2763", "questionTitle": "Sum of Imbalance Numbers of All Subarrays", "stats": { "totalAccepted": "2.8K", "totalSubmission": "4.5K", "totalAcceptedRaw": 2802, "totalSubmissionRaw":...
LeetCode/2831
# Number of Beautiful Pairs You are given a **0-indexed** integer array `nums`. A pair of indices `i`, `j` where `0 <= i < j < nums.length` is called beautiful if the **first digit** of `nums[i]` and the **last digit** of `nums[j]` are **coprime**. Return *the total number of beautiful pairs in* `nums`. Two intege...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countBeautifulPairs(*[[2, 5, 1, 4]]) == 5\nassert my_solution.countBeautifulPairs(*[[11, 21, 12]]) == 2\nassert my_solution.countBeautifulPairs(*[[31, 25, 72, 79, 74]]) == 7\nassert my_solution.countBeautifulPairs(*[[84, ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2831", "questionFrontendId": "2748", "questionTitle": "Number of Beautiful Pairs", "stats": { "totalAccepted": "5.6K", "totalSubmission": "9.7K", "totalAcceptedRaw": 5612, "totalSubmissionRaw": 9720, "acRa...
LeetCode/2837
# Minimum Operations to Make the Integer Zero You are given two integers `num1` and `num2`. In one operation, you can choose integer `i` in the range `[0, 60]` and subtract `2i + num2` from `num1`. Return *the integer denoting the **minimum** number of operations needed to make* `num1` *equal to* `0`. If it is i...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.makeTheIntegerZero(*[3, -2]) == 3\nassert my_solution.makeTheIntegerZero(*[5, 7]) == -1\nassert my_solution.makeTheIntegerZero(*[5, -21]) == 3\nassert my_solution.makeTheIntegerZero(*[2, 71]) == -1\nassert my_solution.mak...
{ "programming_language": "python", "execution_language": "python", "questionId": "2837", "questionFrontendId": "2749", "questionTitle": "Minimum Operations to Make the Integer Zero", "stats": { "totalAccepted": "3.7K", "totalSubmission": "10.9K", "totalAcceptedRaw": 3672, "totalSubmissionRa...
LeetCode/2867
# Ways to Split Array Into Good Subarrays You are given a binary array `nums`. A subarray of an array is **good** if it contains **exactly** **one** element with the value `1`. Return *an integer denoting the number of ways to split the array* `nums` *into **good** subarrays*. As the number may be too large, retur...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.numberOfGoodSubarraySplits(*[[0, 1, 0, 0, 1]]) == 3\nassert my_solution.numberOfGoodSubarraySplits(*[[0, 1, 0]]) == 1\nassert my_solution.numberOfGoodSubarraySplits(*[[0, 1, 0, 0]]) == 1\nassert my_solution.numberOfGoodSu...
{ "programming_language": "python", "execution_language": "python", "questionId": "2867", "questionFrontendId": "2750", "questionTitle": "Ways to Split Array Into Good Subarrays", "stats": { "totalAccepted": "4.1K", "totalSubmission": "10.5K", "totalAcceptedRaw": 4148, "totalSubmissionRaw": ...
LeetCode/2847
# Find Maximum Number of String Pairs You are given a **0-indexed** array `words` consisting of **distinct** strings. The string `words[i]` can be paired with the string `words[j]` if: * The string `words[i]` is equal to the reversed string of `words[j]`. * `0 <= i < j < words.length`. Return *the **maximum** nu...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximumNumberOfStringPairs(*[['cd', 'ac', 'dc', 'ca', 'zz']]) == 2\nassert my_solution.maximumNumberOfStringPairs(*[['ab', 'ba', 'cc']]) == 1\nassert my_solution.maximumNumberOfStringPairs(*[['aa', 'ab']]) == 0\nassert my...
{ "programming_language": "python", "execution_language": "python", "questionId": "2847", "questionFrontendId": "2744", "questionTitle": "Find Maximum Number of String Pairs", "stats": { "totalAccepted": "28.4K", "totalSubmission": "32.6K", "totalAcceptedRaw": 28385, "totalSubmissionRaw": 32...
LeetCode/2850
# Construct the Longest New String You are given three integers `x`, `y`, and `z`. You have `x` strings equal to `"AA"`, `y` strings equal to `"BB"`, and `z` strings equal to `"AB"`. You want to choose some (possibly all or none) of these strings and concatenate them in some order to form a new string. This new stri...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.longestString(*[2, 5, 1]) == 12\nassert my_solution.longestString(*[3, 2, 2]) == 14\nassert my_solution.longestString(*[1, 34, 1]) == 8\nassert my_solution.longestString(*[1, 39, 14]) == 34\nassert my_solution.longestStri...
{ "programming_language": "python", "execution_language": "python", "questionId": "2850", "questionFrontendId": "2745", "questionTitle": "Construct the Longest New String", "stats": { "totalAccepted": "3.7K", "totalSubmission": "6.3K", "totalAcceptedRaw": 3667, "totalSubmissionRaw": 6265, ...
LeetCode/2854
# Decremental String Concatenation You are given a **0-indexed** array `words` containing `n` strings. Let's define a **join** operation `join(x, y)` between two strings `x` and `y` as concatenating them into `xy`. However, if the last character of `x` is equal to the first character of `y`, one of them is **deleted...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimizeConcatenatedLength(*[['aa', 'ab', 'bc']]) == 4\nassert my_solution.minimizeConcatenatedLength(*[['ab', 'b']]) == 2\nassert my_solution.minimizeConcatenatedLength(*[['aaa', 'c', 'aba']]) == 6\nassert my_solution.mi...
{ "programming_language": "python", "execution_language": "python", "questionId": "2854", "questionFrontendId": "2746", "questionTitle": "Decremental String Concatenation", "stats": { "totalAccepted": "2.5K", "totalSubmission": "6.4K", "totalAcceptedRaw": 2537, "totalSubmissionRaw": 6371, ...
LeetCode/2833
# Count Zero Request Servers You are given an integer `n` denoting the total number of servers and a **2D** **0-indexed** integer array `logs`, where `logs[i] = [server_id, time]` denotes that the server with id `server_id` received a request at time `time`. You are also given an integer `x` and a **0-indexed** inte...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countServers(*[3, [[1, 3], [2, 6], [1, 5]], 5, [10, 11]]) == [1, 2]\nassert my_solution.countServers(*[3, [[2, 4], [2, 1], [1, 2], [3, 1]], 2, [3, 4]]) == [0, 1]\nassert my_solution.countServers(*[4, [[2, 30], [2, 5], [3,...
{ "programming_language": "python", "execution_language": "python", "questionId": "2833", "questionFrontendId": "2747", "questionTitle": "Count Zero Request Servers", "stats": { "totalAccepted": "2K", "totalSubmission": "5.3K", "totalAcceptedRaw": 2009, "totalSubmissionRaw": 5259, "acRat...
LeetCode/2857
# Total Distance Traveled A truck has two fuel tanks. You are given two integers, `mainTank` representing the fuel present in the main tank in liters and `additionalTank` representing the fuel present in the additional tank in liters. The truck has a mileage of `10` km per liter. Whenever `5` liters of fuel get used...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.distanceTraveled(*[5, 10]) == 60\nassert my_solution.distanceTraveled(*[1, 2]) == 10\nassert my_solution.distanceTraveled(*[1, 1]) == 10\nassert my_solution.distanceTraveled(*[1, 3]) == 10\nassert my_solution.distanceTrav...
{ "programming_language": "python", "execution_language": "python", "questionId": "2857", "questionFrontendId": "2739", "questionTitle": "Total Distance Traveled", "stats": { "totalAccepted": "7.2K", "totalSubmission": "13.8K", "totalAcceptedRaw": 7238, "totalSubmissionRaw": 13804, "acRa...
LeetCode/2845
# Find the Value of the Partition You are given a **positive** integer array `nums`. Partition `nums` into two arrays, `nums1` and `nums2`, such that: * Each element of the array `nums` belongs to either the array `nums1` or the array `nums2`. * Both arrays are **non-empty**. * The value of the partition is **mini...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.findValueOfPartition(*[[1, 3, 2, 4]]) == 1\nassert my_solution.findValueOfPartition(*[[100, 1, 10]]) == 9\nassert my_solution.findValueOfPartition(*[[59, 51, 1, 98, 73]]) == 8\nassert my_solution.findValueOfPartition(*[[8...
{ "programming_language": "python", "execution_language": "python", "questionId": "2845", "questionFrontendId": "2740", "questionTitle": "Find the Value of the Partition", "stats": { "totalAccepted": "6.2K", "totalSubmission": "8.4K", "totalAcceptedRaw": 6227, "totalSubmissionRaw": 8377, ...
LeetCode/2848
# Special Permutations You are given a **0-indexed** integer array `nums` containing `n` **distinct** positive integers. A permutation of `nums` is called special if: * For all indexes `0 <= i < n - 1`, either `nums[i] % nums[i+1] == 0` or `nums[i+1] % nums[i] == 0`. Return *the total number of special permutation...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.specialPerm(*[[2, 3, 6]]) == 2\nassert my_solution.specialPerm(*[[1, 4, 3]]) == 2\nassert my_solution.specialPerm(*[[31, 93]]) == 2\nassert my_solution.specialPerm(*[[20, 100, 50, 5, 10, 70, 7]]) == 48\nassert my_solution...
{ "programming_language": "python", "execution_language": "python", "questionId": "2848", "questionFrontendId": "2741", "questionTitle": "Special Permutations", "stats": { "totalAccepted": "4.6K", "totalSubmission": "12.5K", "totalAcceptedRaw": 4591, "totalSubmissionRaw": 12533, "acRate"...
LeetCode/2808
# Painting the Walls You are given two **0-indexed** integer arrays, `cost` and `time`, of size `n` representing the costs and the time taken to paint `n` different walls respectively. There are two painters available: * A**paid painter** that paints the `ith` wall in `time[i]` units of time and takes `cost[i]` unit...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.paintWalls(*[[1, 2, 3, 2], [1, 2, 3, 2]]) == 3\nassert my_solution.paintWalls(*[[2, 3, 4, 2], [1, 1, 1, 1]]) == 4\nassert my_solution.paintWalls(*[[8, 7, 5, 15], [1, 1, 2, 1]]) == 12\nassert my_solution.paintWalls(*[[42, ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2808", "questionFrontendId": "2742", "questionTitle": "Painting the Walls", "stats": { "totalAccepted": "3.3K", "totalSubmission": "9K", "totalAcceptedRaw": 3337, "totalSubmissionRaw": 9014, "acRate": "37....
LeetCode/2836
# Neither Minimum nor Maximum Given an integer array `nums` containing **distinct** **positive** integers, find and return **any** number from the array that is neither the **minimum** nor the **maximum** value in the array, or **`-1`** if there is no such number. Return *the selected integer.*   **Example 1:** ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.findNonMinOrMax(*[[3, 2, 1, 4]]) == 2\nassert my_solution.findNonMinOrMax(*[[1, 2]]) == -1\nassert my_solution.findNonMinOrMax(*[[2, 1, 3]]) == 2\nassert my_solution.findNonMinOrMax(*[[1]]) == -1\nassert my_solution.findN...
{ "programming_language": "python", "execution_language": "python", "questionId": "2836", "questionFrontendId": "2733", "questionTitle": "Neither Minimum nor Maximum", "stats": { "totalAccepted": "9.6K", "totalSubmission": "12.3K", "totalAcceptedRaw": 9556, "totalSubmissionRaw": 12269, "...
LeetCode/2828
# Lexicographically Smallest String After Substring Operation You are given a string `s` consisting of only lowercase English letters. In one operation, you can do the following: * Select any non-empty substring of `s`, possibly the entire string, then replace each one of its characters with the previous character o...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.smallestString(*['cbabc']) == baabc\nassert my_solution.smallestString(*['acbbc']) == abaab\nassert my_solution.smallestString(*['leetcode']) == kddsbncd\nassert my_solution.smallestString(*['a']) == z\nassert my_solution...
{ "programming_language": "python", "execution_language": "python", "questionId": "2828", "questionFrontendId": "2734", "questionTitle": "Lexicographically Smallest String After Substring Operation", "stats": { "totalAccepted": "6K", "totalSubmission": "17.5K", "totalAcceptedRaw": 5992, "tot...
LeetCode/2810
# Collecting Chocolates You are given a **0-indexed** integer array `nums` of size `n` representing the cost of collecting different chocolates. The cost of collecting the chocolate at the index `i` is `nums[i]`. Each chocolate is of a different type, and initially, the chocolate at the index `i` is of `ith` type. I...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minCost(*[[20, 1, 15], 5]) == 13\nassert my_solution.minCost(*[[1, 2, 3], 4]) == 6\nassert my_solution.minCost(*[[31, 25, 18, 59], 27]) == 119\nassert my_solution.minCost(*[[5, 3], 8]) == 8\nassert my_solution.minCost(*[[...
{ "programming_language": "python", "execution_language": "python", "questionId": "2810", "questionFrontendId": "2735", "questionTitle": "Collecting Chocolates", "stats": { "totalAccepted": "16.9K", "totalSubmission": "30.7K", "totalAcceptedRaw": 16860, "totalSubmissionRaw": 30748, "acRa...
LeetCode/2839
# Maximum Sum Queries You are given two **0-indexed** integer arrays `nums1` and `nums2`, each of length `n`, and a **1-indexed 2D array** `queries` where `queries[i] = [xi, yi]`. For the `ith` query, find the **maximum value** of `nums1[j] + nums2[j]` among all indices `j` `(0 <= j < n)`, where `nums1[j] >= xi` and...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximumSumQueries(*[[4, 3, 1, 2], [2, 4, 9, 5], [[4, 1], [1, 3], [2, 5]]]) == [6, 10, 7]\nassert my_solution.maximumSumQueries(*[[3, 2, 5], [2, 3, 4], [[4, 4], [3, 2], [1, 1]]]) == [9, 9, 9]\nassert my_solution.maximumSum...
{ "programming_language": "python", "execution_language": "python", "questionId": "2839", "questionFrontendId": "2736", "questionTitle": "Maximum Sum Queries", "stats": { "totalAccepted": "12.5K", "totalSubmission": "23.8K", "totalAcceptedRaw": 12499, "totalSubmissionRaw": 23813, "acRate...
LeetCode/2786
# Find the Longest Semi-Repetitive Substring You are given a **0-indexed** string `s` that consists of digits from `0` to `9`. A string `t` is called a **semi-repetitive** if there is at most one consecutive pair of the same digits inside `t`. For example, `0010`, `002020`, `0123`, `2002`, and `54944` are semi-repet...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.longestSemiRepetitiveSubstring(*['52233']) == 4\nassert my_solution.longestSemiRepetitiveSubstring(*['5494']) == 4\nassert my_solution.longestSemiRepetitiveSubstring(*['1111111']) == 2\nassert my_solution.longestSemiRepet...
{ "programming_language": "python", "execution_language": "python", "questionId": "2786", "questionFrontendId": "2730", "questionTitle": "Find the Longest Semi-Repetitive Substring", "stats": { "totalAccepted": "4.9K", "totalSubmission": "10.4K", "totalAcceptedRaw": 4896, "totalSubmissionRaw...
LeetCode/2787
# Movement of Robots Some robots are standing on an infinite number line with their initial coordinates given by a **0-indexed** integer array `nums` and will start moving once given the command to move. The robots will move a unit distance each second. You are given a string `s` denoting the direction in which robo...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.sumDistance(*[[-2, 0, 2], 'RLL', 3]) == 8\nassert my_solution.sumDistance(*[[1, 0], 'RL', 2]) == 5\nassert my_solution.sumDistance(*[[-10, -13, 10, 14, 11], 'LRLLR', 2]) == 146\nassert my_solution.sumDistance(*[[1, -67, 6...
{ "programming_language": "python", "execution_language": "python", "questionId": "2787", "questionFrontendId": "2731", "questionTitle": "Movement of Robots", "stats": { "totalAccepted": "20.3K", "totalSubmission": "53.3K", "totalAcceptedRaw": 20268, "totalSubmissionRaw": 53335, "acRate"...
LeetCode/2826
# Find a Good Subset of the Matrix You are given a **0-indexed** `m x n` binary matrix `grid`. Let us call a **non-empty** subset of rows **good** if the sum of each column of the subset is at most half of the length of the subset. More formally, if the length of the chosen subset of rows is `k`, then the sum of e...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.goodSubsetofBinaryMatrix(*[[[0, 1, 1, 0], [0, 0, 0, 1], [1, 1, 1, 1]]]) == [0, 1]\nassert my_solution.goodSubsetofBinaryMatrix(*[[[0]]]) == [0]\nassert my_solution.goodSubsetofBinaryMatrix(*[[[1, 1, 1], [1, 1, 1]]]) == []...
{ "programming_language": "python", "execution_language": "python", "questionId": "2826", "questionFrontendId": "2732", "questionTitle": "Find a Good Subset of the Matrix", "stats": { "totalAccepted": "1.7K", "totalSubmission": "3.1K", "totalAcceptedRaw": 1740, "totalSubmissionRaw": 3051, ...
LeetCode/2825
# Minimize String Length Given a **0-indexed** string `s`, repeatedly perform the following operation **any** number of times: * Choose an index `i` in the string, and let `c` be the character in position `i`. **Delete** the **closest occurrence** of `c` to the **left** of `i` (if any) and the **closest occurrence**...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimizedStringLength(*['aaabc']) == 3\nassert my_solution.minimizedStringLength(*['cbbd']) == 3\nassert my_solution.minimizedStringLength(*['dddaaa']) == 2\nassert my_solution.minimizedStringLength(*['a']) == 1\nassert m...
{ "programming_language": "python", "execution_language": "python", "questionId": "2825", "questionFrontendId": "2716", "questionTitle": "Minimize String Length", "stats": { "totalAccepted": "7.3K", "totalSubmission": "10K", "totalAcceptedRaw": 7280, "totalSubmissionRaw": 9995, "acRate":...
LeetCode/2785
# Semi-Ordered Permutation You are given a **0-indexed** permutation of `n` integers `nums`. A permutation is called **semi-ordered** if the first number equals `1` and the last number equals `n`. You can perform the below operation as many times as you want until you make `nums` a **semi-ordered** permutation: * ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.semiOrderedPermutation(*[[2, 1, 4, 3]]) == 2\nassert my_solution.semiOrderedPermutation(*[[2, 4, 1, 3]]) == 3\nassert my_solution.semiOrderedPermutation(*[[1, 3, 4, 2, 5]]) == 0\nassert my_solution.semiOrderedPermutation(...
{ "programming_language": "python", "execution_language": "python", "questionId": "2785", "questionFrontendId": "2717", "questionTitle": "Semi-Ordered Permutation", "stats": { "totalAccepted": "7K", "totalSubmission": "9.5K", "totalAcceptedRaw": 6957, "totalSubmissionRaw": 9475, "acRate"...
LeetCode/2757
# Count of Integers You are given two numeric strings `num1` and `num2` and two integers `max_sum` and `min_sum`. We denote an integer `x` to be *good* if: * `num1 <= x <= num2` * `min_sum <= digit_sum(x) <= max_sum`. Return *the number of good integers*. Since the answer may be large, return it modulo `109 + 7`. ...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.count(*['1', '12', 1, 8]) == 11\nassert my_solution.count(*['1', '5', 1, 5]) == 5\nassert my_solution.count(*['4179205230', '7748704426', 8, 46]) == 883045899\nassert my_solution.count(*['1479192516', '5733987233', 36, 10...
{ "programming_language": "python", "execution_language": "python", "questionId": "2757", "questionFrontendId": "2719", "questionTitle": "Count of Integers", "stats": { "totalAccepted": "14.4K", "totalSubmission": "25.6K", "totalAcceptedRaw": 14375, "totalSubmissionRaw": 25620, "acRate":...
LeetCode/2819
# Remove Trailing Zeros From a String Given a **positive** integer `num` represented as a string, return *the integer* `num` *without trailing zeros as a string*.   **Example 1:** ``` **Input:** num = "51230100" **Output:** "512301" **Explanation:** Integer "51230100" has 2 trailing zeros, we remove them and r...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.removeTrailingZeros(*['51230100']) == 512301\nassert my_solution.removeTrailingZeros(*['123']) == 123\nassert my_solution.removeTrailingZeros(*['1720865079269529096765717822459']) == 1720865079269529096765717822459\nasser...
{ "programming_language": "python", "execution_language": "python", "questionId": "2819", "questionFrontendId": "2710", "questionTitle": "Remove Trailing Zeros From a String", "stats": { "totalAccepted": "9.2K", "totalSubmission": "11.2K", "totalAcceptedRaw": 9183, "totalSubmissionRaw": 1119...
LeetCode/2817
# Minimum Cost to Make All Characters Equal You are given a **0-indexed** binary string `s` of length `n` on which you can apply two types of operations: * Choose an index `i` and invert all characters from index `0` to index `i` (both inclusive), with a cost of `i + 1` * Choose an index `i` and invert all character...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumCost(*['0011']) == 2\nassert my_solution.minimumCost(*['010101']) == 9\nassert my_solution.minimumCost(*['0']) == 0\nassert my_solution.minimumCost(*['00']) == 0\nassert my_solution.minimumCost(*['000']) == 0\nasse...
{ "programming_language": "python", "execution_language": "python", "questionId": "2817", "questionFrontendId": "2712", "questionTitle": "Minimum Cost to Make All Characters Equal", "stats": { "totalAccepted": "4.8K", "totalSubmission": "8.4K", "totalAcceptedRaw": 4782, "totalSubmissionRaw":...
LeetCode/2756
# Buy Two Chocolates You are given an integer array `prices` representing the prices of various chocolates in a store. You are also given a single integer `money`, which represents your initial amount of money. You must buy **exactly** two chocolates in such a way that you still have some **non-negative** leftover m...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.buyChoco(*[[1, 2, 2], 3]) == 0\nassert my_solution.buyChoco(*[[3, 2, 3], 3]) == 3\nassert my_solution.buyChoco(*[[98, 54, 6, 34, 66, 63, 52, 39], 62]) == 22\nassert my_solution.buyChoco(*[[75, 28, 65, 18, 37, 18, 97], 13]...
{ "programming_language": "python", "execution_language": "python", "questionId": "2756", "questionFrontendId": "2706", "questionTitle": "Buy Two Chocolates", "stats": { "totalAccepted": "26.8K", "totalSubmission": "34.6K", "totalAcceptedRaw": 26830, "totalSubmissionRaw": 34620, "acRate"...
LeetCode/2755
# Extra Characters in a String You are given a **0-indexed** string `s` and a dictionary of words `dictionary`. You have to break `s` into one or more **non-overlapping** substrings such that each substring is present in `dictionary`. There may be some **extra characters** in `s` which are not present in any of the su...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minExtraChar(*['leetscode', ['leet', 'code', 'leetcode']]) == 1\nassert my_solution.minExtraChar(*['sayhelloworld', ['hello', 'world']]) == 3\nassert my_solution.minExtraChar(*['dwmodizxvvbosxxw', ['ox', 'lb', 'diz', 'gu'...
{ "programming_language": "python", "execution_language": "python", "questionId": "2755", "questionFrontendId": "2707", "questionTitle": "Extra Characters in a String", "stats": { "totalAccepted": "20.2K", "totalSubmission": "31.8K", "totalAcceptedRaw": 20196, "totalSubmissionRaw": 31839, ...
LeetCode/2754
# Maximum Strength of a Group You are given a **0-indexed** integer array `nums` representing the score of students in an exam. The teacher would like to form one **non-empty** group of students with maximal **strength**, where the strength of a group of students of indices `i0`, `i1`, `i2`, ... , `ik` is defined as `...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maxStrength(*[[3, -1, -5, 2, 5, -9]]) == 1350\nassert my_solution.maxStrength(*[[-4, -5, -4]]) == 20\nassert my_solution.maxStrength(*[[-2, -3, 8, 9]]) == 432\nassert my_solution.maxStrength(*[[-5, 5, -3, -7, -1, -5, 5, 1...
{ "programming_language": "python", "execution_language": "python", "questionId": "2754", "questionFrontendId": "2708", "questionTitle": "Maximum Strength of a Group", "stats": { "totalAccepted": "4.9K", "totalSubmission": "16.1K", "totalAcceptedRaw": 4897, "totalSubmissionRaw": 16063, "...
LeetCode/2827
# Greatest Common Divisor Traversal You are given a **0-indexed** integer array `nums`, and you are allowed to **traverse** between its indices. You can traverse between index `i` and index `j`, `i != j`, if and only if `gcd(nums[i], nums[j]) > 1`, where `gcd` is the **greatest common divisor**. Your task is to dete...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.canTraverseAllPairs(*[[2, 3, 6]]) == True\nassert my_solution.canTraverseAllPairs(*[[3, 9, 5]]) == False\nassert my_solution.canTraverseAllPairs(*[[4, 3, 12, 8]]) == True\nassert my_solution.canTraverseAllPairs(*[[10]]) =...
{ "programming_language": "python", "execution_language": "python", "questionId": "2827", "questionFrontendId": "2709", "questionTitle": "Greatest Common Divisor Traversal", "stats": { "totalAccepted": "3K", "totalSubmission": "12.1K", "totalAcceptedRaw": 3023, "totalSubmissionRaw": 12060, ...
LeetCode/2800
# Minimum String Length After Removing Substrings You are given a string `s` consisting only of **uppercase** English letters. You can apply some operations to this string where, in one operation, you can remove **any** occurrence of one of the substrings `"AB"` or `"CD"` from `s`. Return *the **minimum** possible...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minLength(*['ABFCACDB']) == 2\nassert my_solution.minLength(*['ACBBD']) == 5\nassert my_solution.minLength(*['A']) == 1\nassert my_solution.minLength(*['D']) == 1\nassert my_solution.minLength(*['Z']) == 1\nassert my_solu...
{ "programming_language": "python", "execution_language": "python", "questionId": "2800", "questionFrontendId": "2696", "questionTitle": "Minimum String Length After Removing Substrings", "stats": { "totalAccepted": "31.6K", "totalSubmission": "40.8K", "totalAcceptedRaw": 31637, "totalSubmis...
LeetCode/2816
# Lexicographically Smallest Palindrome You are given a string `s` consisting of **lowercase English letters**, and you are allowed to perform operations on it. In one operation, you can **replace** a character in `s` with another lowercase English letter. Your task is to make `s` a **palindrome** with the **minimum...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.makeSmallestPalindrome(*['egcfe']) == efcfe\nassert my_solution.makeSmallestPalindrome(*['abcd']) == abba\nassert my_solution.makeSmallestPalindrome(*['seven']) == neven\nassert my_solution.makeSmallestPalindrome(*['a']) ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2816", "questionFrontendId": "2697", "questionTitle": "Lexicographically Smallest Palindrome", "stats": { "totalAccepted": "28.8K", "totalSubmission": "32.9K", "totalAcceptedRaw": 28789, "totalSubmissionRaw": ...
LeetCode/2802
# Find the Punishment Number of an Integer Given a positive integer `n`, return *the **punishment number*** of `n`. The **punishment number** of `n` is defined as the sum of the squares of all integers `i` such that: * `1 <= i <= n` * The decimal representation of `i * i` can be partitioned into contiguous substri...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.punishmentNumber(*[10]) == 182\nassert my_solution.punishmentNumber(*[37]) == 1478\nassert my_solution.punishmentNumber(*[1]) == 1\nassert my_solution.punishmentNumber(*[2]) == 1\nassert my_solution.punishmentNumber(*[3])...
{ "programming_language": "python", "execution_language": "python", "questionId": "2802", "questionFrontendId": "2698", "questionTitle": "Find the Punishment Number of an Integer", "stats": { "totalAccepted": "27.1K", "totalSubmission": "34.5K", "totalAcceptedRaw": 27123, "totalSubmissionRaw...
LeetCode/2791
# Find the Losers of the Circular Game 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 `nt...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.circularGameLosers(*[5, 2]) == [4, 5]\nassert my_solution.circularGameLosers(*[4, 4]) == [2, 3, 4]\nassert my_solution.circularGameLosers(*[1, 1]) == []\nassert my_solution.circularGameLosers(*[2, 1]) == []\nassert my_sol...
{ "programming_language": "python", "execution_language": "python", "questionId": "2791", "questionFrontendId": "2682", "questionTitle": "Find the Losers of the Circular Game", "stats": { "totalAccepted": "31.1K", "totalSubmission": "51.2K", "totalAcceptedRaw": 31126, "totalSubmissionRaw": 5...
LeetCode/2792
# Neighboring Bitwise XOR A **0-indexed** array `derived` with length `n` is derived by computing the **bitwise XOR** (⊕) of adjacent values in a **binary array** `original` of length `n`. Specifically, for each index `i` in the range `[0, n - 1]`: * If `i = n - 1`, then `derived[i] = original[i] ⊕ original[0]`. *...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.doesValidArrayExist(*[[1, 1, 0]]) == True\nassert my_solution.doesValidArrayExist(*[[1, 1]]) == True\nassert my_solution.doesValidArrayExist(*[[1, 0]]) == False\nassert my_solution.doesValidArrayExist(*[[0]]) == True\nass...
{ "programming_language": "python", "execution_language": "python", "questionId": "2792", "questionFrontendId": "2683", "questionTitle": "Neighboring Bitwise XOR", "stats": { "totalAccepted": "6.4K", "totalSubmission": "9.1K", "totalAcceptedRaw": 6399, "totalSubmissionRaw": 9102, "acRate...
LeetCode/2727
# Number of Senior Citizens You are given a **0-indexed** array of strings `details`. Each element of `details` provides information about a given passenger compressed into a string of length `15`. The system is such that: * The first ten characters consist of the phone number of passengers. * The next character den...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countSeniors(*[['7868190130M7522', '5303914400F9211', '9273338290F4010']]) == 2\nassert my_solution.countSeniors(*[['1313579440F2036', '2921522980M5644']]) == 0\nassert my_solution.countSeniors(*[['5612624052M0130', '5378...
{ "programming_language": "python", "execution_language": "python", "questionId": "2727", "questionFrontendId": "2678", "questionTitle": "Number of Senior Citizens", "stats": { "totalAccepted": "35.6K", "totalSubmission": "44.9K", "totalAcceptedRaw": 35613, "totalSubmissionRaw": 44872, "...
LeetCode/2728
# Sum in a Matrix You are given a **0-indexed** 2D integer array `nums`. Initially, your score is `0`. Perform the following operations until the matrix becomes empty: 1. From each row in the matrix, select the largest number and remove it. In the case of a tie, it does not matter which number is chosen. 2. Identify...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.matrixSum(*[[[7, 2, 1], [6, 4, 2], [6, 5, 3], [3, 2, 1]]]) == 15\nassert my_solution.matrixSum(*[[[1]]]) == 1\nassert my_solution.matrixSum(*[[[1, 8, 16, 15, 12, 9, 15, 11, 18, 6, 16, 4, 9, 4], [3, 19, 8, 17, 19, 4, 9, 3,...
{ "programming_language": "python", "execution_language": "python", "questionId": "2728", "questionFrontendId": "2679", "questionTitle": "Sum in a Matrix", "stats": { "totalAccepted": "26K", "totalSubmission": "33.3K", "totalAcceptedRaw": 25981, "totalSubmissionRaw": 33306, "acRate": "78...
LeetCode/2730
# Maximum OR You are given a **0-indexed** integer array `nums` of length `n` and an integer `k`. In an operation, you can choose an element and multiply it by `2`. Return *the maximum possible value of* `nums[0] | nums[1] | ... | nums[n - 1]` *that can be obtained after applying the operation on nums at most* `k` *...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximumOr(*[[12, 9], 1]) == 30\nassert my_solution.maximumOr(*[[8, 1, 2], 2]) == 35\nassert my_solution.maximumOr(*[[98, 54, 6, 34, 66, 63, 52, 39, 62, 46, 75, 28, 65, 18, 37, 18, 97, 13, 80, 33, 69, 91, 78, 19, 40], 2]) ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2730", "questionFrontendId": "2680", "questionTitle": "Maximum OR", "stats": { "totalAccepted": "3.5K", "totalSubmission": "8K", "totalAcceptedRaw": 3508, "totalSubmissionRaw": 8048, "acRate": "43.6%" } ...
LeetCode/2784
# Power of Heroes You are given a **0-indexed** integer array `nums` representing the strength of some heroes. The **power** of a group of heroes is defined as follows: * Let `i0`, `i1`, ... ,`ik` be the indices of the heroes in a group. Then, the power of this group is `max(nums[i0], nums[i1], ... ,nums[ik])2 * min...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.sumOfPower(*[[2, 1, 4]]) == 141\nassert my_solution.sumOfPower(*[[1, 1, 1]]) == 7\nassert my_solution.sumOfPower(*[[4, 4]]) == 192\nassert my_solution.sumOfPower(*[[8, 4]]) == 832\nassert my_solution.sumOfPower(*[[5, 3]])...
{ "programming_language": "python", "execution_language": "python", "questionId": "2784", "questionFrontendId": "2681", "questionTitle": "Power of Heroes", "stats": { "totalAccepted": "18.7K", "totalSubmission": "44.8K", "totalAcceptedRaw": 18652, "totalSubmissionRaw": 44844, "acRate": "...
LeetCode/2777
# Find the Distinct Difference Array You are given a **0-indexed** array `nums` of length `n`. The **distinct difference** array of `nums` is an array `diff` of length `n` such that `diff[i]` is equal to the number of distinct elements in the suffix `nums[i + 1, ..., n - 1]` **subtracted from** the number of distinc...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.distinctDifferenceArray(*[[1, 2, 3, 4, 5]]) == [-3, -1, 1, 3, 5]\nassert my_solution.distinctDifferenceArray(*[[3, 2, 3, 4, 2]]) == [-2, -1, 0, 2, 3]\nassert my_solution.distinctDifferenceArray(*[[16]]) == [1]\nassert my_...
{ "programming_language": "python", "execution_language": "python", "questionId": "2777", "questionFrontendId": "2670", "questionTitle": "Find the Distinct Difference Array", "stats": { "totalAccepted": "7.6K", "totalSubmission": "9.9K", "totalAcceptedRaw": 7588, "totalSubmissionRaw": 9899, ...
LeetCode/2779
# Number of Adjacent Elements With the Same Color There is a **0-indexed** array `nums` of length `n`. Initially, all elements are **uncolored** (has a value of `0`). You are given a 2D integer array `queries` where `queries[i] = [indexi, colori]`. For each query, you color the index `indexi` with the color `color...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.colorTheArray(*[4, [[0, 2], [1, 2], [3, 1], [1, 1], [2, 1]]]) == [0, 1, 1, 0, 2]\nassert my_solution.colorTheArray(*[1, [[0, 100000]]]) == [0]\nassert my_solution.colorTheArray(*[8, [[6, 2], [2, 1], [0, 6], [0, 1], [0, 4]...
{ "programming_language": "python", "execution_language": "python", "questionId": "2779", "questionFrontendId": "2672", "questionTitle": "Number of Adjacent Elements With the Same Color", "stats": { "totalAccepted": "5.3K", "totalSubmission": "9K", "totalAcceptedRaw": 5287, "totalSubmissionR...
LeetCode/2684
# Determine the Winner of a Bowling Game You are given two **0-indexed** integer arrays `player1` and `player2`, that represent the number of pins that player 1 and player 2 hit in a bowling game, respectively. The bowling game consists of `n` turns, and the number of pins in each turn is exactly `10`. Assume a pl...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.isWinner(*[[4, 10, 7, 9], [6, 5, 2, 3]]) == 1\nassert my_solution.isWinner(*[[3, 5, 7, 6], [8, 10, 10, 2]]) == 2\nassert my_solution.isWinner(*[[2, 3], [4, 1]]) == 0\nassert my_solution.isWinner(*[[0, 4, 7, 2, 0], [2, 3, ...
{ "programming_language": "python", "execution_language": "python", "questionId": "2684", "questionFrontendId": "2660", "questionTitle": "Determine the Winner of a Bowling Game", "stats": { "totalAccepted": "27K", "totalSubmission": "58.4K", "totalAcceptedRaw": 26998, "totalSubmissionRaw": 5...
LeetCode/2686
# Minimum Cost of a Path With Special Roads You are given an array `start` where `start = [startX, startY]` represents your initial position `(startX, startY)` in a 2D space. You are also given the array `target` where `target = [targetX, targetY]` represents your target position `(targetX, targetY)`. The cost of go...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.minimumCost(*[[1, 1], [4, 5], [[1, 2, 3, 3, 2], [3, 4, 4, 5, 1]]]) == 5\nassert my_solution.minimumCost(*[[3, 2], [5, 7], [[3, 2, 3, 4, 4], [3, 3, 5, 5, 5], [3, 4, 5, 6, 6]]]) == 7\nassert my_solution.minimumCost(*[[1, 1]...
{ "programming_language": "python", "execution_language": "python", "questionId": "2686", "questionFrontendId": "2662", "questionTitle": "Minimum Cost of a Path With Special Roads", "stats": { "totalAccepted": "3.9K", "totalSubmission": "10.2K", "totalAcceptedRaw": 3874, "totalSubmissionRaw"...
LeetCode/2687
# Lexicographically Smallest Beautiful String A string is **beautiful** if: * It consists of the first `k` letters of the English lowercase alphabet. * It does not contain any substring of length `2` or more which is a palindrome. You are given a beautiful string `s` of length `n` and a positive integer `k`. Ret...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.smallestBeautifulString(*['abcz', 26]) == abda\nassert my_solution.smallestBeautifulString(*['dc', 4]) == \nassert my_solution.smallestBeautifulString(*['abc', 8]) == abd\nassert my_solution.smallestBeautifulString(*['dfa...
{ "programming_language": "python", "execution_language": "python", "questionId": "2687", "questionFrontendId": "2663", "questionTitle": "Lexicographically Smallest Beautiful String", "stats": { "totalAccepted": "1.9K", "totalSubmission": "4.2K", "totalAcceptedRaw": 1924, "totalSubmissionRaw...
LeetCode/2767
# Maximum Sum With Exactly K Elements You are given a **0-indexed** integer array `nums` and an integer `k`. Your task is to perform the following operation **exactly** `k` times in order to maximize your score: 1. Select an element `m` from `nums`. 2. Remove the selected element `m` from the array. 3. Add a new el...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.maximizeSum(*[[1, 2, 3, 4, 5], 3]) == 18\nassert my_solution.maximizeSum(*[[5, 5, 5], 2]) == 11\nassert my_solution.maximizeSum(*[[4, 4, 9, 10, 10, 9, 3, 8, 4, 2, 5, 3, 8, 6, 1, 10, 4, 5, 3, 2, 3, 9, 5, 7, 10, 4, 9, 10, 1...
{ "programming_language": "python", "execution_language": "python", "questionId": "2767", "questionFrontendId": "2656", "questionTitle": "Maximum Sum With Exactly K Elements ", "stats": { "totalAccepted": "35.7K", "totalSubmission": "41.1K", "totalAcceptedRaw": 35732, "totalSubmissionRaw": 4...
LeetCode/2766
# Find the Prefix Common Array of Two Arrays You are given two **0-indexed** integerpermutations `A` and `B` of length `n`. A **prefix common array** of `A` and `B` is an array `C` such that `C[i]` is equal to the count of numbers that are present at or before the index `i` in both `A` and `B`. Return *the **prefi...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.findThePrefixCommonArray(*[[1, 3, 2, 4], [3, 1, 2, 4]]) == [0, 2, 3, 4]\nassert my_solution.findThePrefixCommonArray(*[[2, 3, 1], [3, 1, 2]]) == [0, 1, 3]\nassert my_solution.findThePrefixCommonArray(*[[1], [1]]) == [1]\n...
{ "programming_language": "python", "execution_language": "python", "questionId": "2766", "questionFrontendId": "2657", "questionTitle": "Find the Prefix Common Array of Two Arrays", "stats": { "totalAccepted": "4.7K", "totalSubmission": "5.8K", "totalAcceptedRaw": 4684, "totalSubmissionRaw"...
LeetCode/2765
# Make Array Empty You are given an integer array `nums` containing **distinct** numbers, and you can perform the following operations **until the array is empty**: * If the first element has the **smallest** value, remove it * Otherwise, put the first element at the **end** of the array. Return *an integer denoti...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.countOperationsToEmptyArray(*[[3, 4, -1]]) == 5\nassert my_solution.countOperationsToEmptyArray(*[[1, 2, 4, 3]]) == 5\nassert my_solution.countOperationsToEmptyArray(*[[1, 2, 3]]) == 3\nassert my_solution.countOperationsT...
{ "programming_language": "python", "execution_language": "python", "questionId": "2765", "questionFrontendId": "2659", "questionTitle": "Make Array Empty", "stats": { "totalAccepted": "2.6K", "totalSubmission": "6.5K", "totalAcceptedRaw": 2564, "totalSubmissionRaw": 6505, "acRate": "39....
LeetCode/2748
# Calculate Delayed Arrival Time You are given a positive integer `arrivalTime` denoting the arrival time of a train in hours, and another positive integer `delayedTime` denoting the amount of delay in hours. Return *the time when the train will arrive at the station.* Note that the time in this problem is in 24-h...
{ "code": "\nfrom typing import *\n\n#<INSERT>\n\nmy_solution = Solution()\n\nassert my_solution.findDelayedArrivalTime(*[15, 5]) == 20\nassert my_solution.findDelayedArrivalTime(*[13, 11]) == 0\nassert my_solution.findDelayedArrivalTime(*[1, 1]) == 2\nassert my_solution.findDelayedArrivalTime(*[1, 2]) == 3\nassert m...
{ "programming_language": "python", "execution_language": "python", "questionId": "2748", "questionFrontendId": "2651", "questionTitle": "Calculate Delayed Arrival Time", "stats": { "totalAccepted": "40.6K", "totalSubmission": "46.3K", "totalAcceptedRaw": 40577, "totalSubmissionRaw": 46342, ...