diff --git a/.flake8 b/.flake8
new file mode 100644
index 00000000..dda5ecfd
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,2 @@
+[flake8]
+ignore = E501, W503, E203, F541, W293, W291
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..dab4d260
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,4 @@
+*.csv linguist-generated=true
+*.json linguist-generated=true
+*.jsonl linguist-generated=true
+*.ipynb linguist-generated=true
diff --git a/.gitignore b/.gitignore
index 1378e49e..3e5489cc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,7 @@
-**/__pycache__/**
+# Local cruft and other
.env
+*.bak
+**/__pycache__/**
+
+# Local sandbox environments
+playground/
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 00000000..20096412
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,26 @@
+repos:
+ - repo: https://github.com/pre-commit/mirrors-mypy
+ rev: v1.1.1
+ hooks:
+ - id: mypy
+ additional_dependencies: [types-requests, types-attrs]
+ - repo: https://github.com/google/yapf
+ rev: v0.31.0
+ hooks:
+ - id: yapf
+ args: [--style, google]
+ - repo: https://github.com/psf/black
+ rev: 23.1.0
+ hooks:
+ - id: black
+ language_version: python3.10 # Replace with your Python version
+ - repo: https://github.com/pycqa/flake8
+ rev: 6.0.0
+ hooks:
+ - id: flake8
+ - repo: https://github.com/pycqa/isort
+ rev: 5.12.0
+ hooks:
+ - id: isort
+ language_version: python3.10
+
diff --git a/README.md b/README.md
index e7679c40..a4ff18c1 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,7 @@ poetry run python runner.py --provider openai --dataset human-eval --model gpt-4
|----------------------------------|----------------------|----------------------|------------------|------------------------------------------------------------------------|
| HumanEval | 87.2 | 84.1 | 67 | [1] |
| EvalPlus | 79.2 | 74.4 | N/A | |
+| GSM8K | X | X | 87.1 | |
| Leetcode Easy | X | X | 72.2-75.6 | [1,2] |
| Leetcode Medium | X | X | 26.2-38.7 | [1,2] |
| Leetcode Hard | X | X | 6.7-7 | [1,2] |
diff --git a/datasets/inputs/leetcode/randomly_sampled_problems.csv b/datasets/inputs/leetcode/randomly_sampled_problems.csv
new file mode 100644
index 00000000..e6c6476e
--- /dev/null
+++ b/datasets/inputs/leetcode/randomly_sampled_problems.csv
@@ -0,0 +1,178014 @@
+,question_slug,question_title,frontend_question_id,question_id,raw_content,difficulty,paid_only,cpp_snippet,java_snippet,python_snippet,python3_snippet,c_snippet,csharp_snippet,javascript_snippet,ruby_snippet,swift_snippet,golang_snippet,scala_snippet,kotlin_snippet,rust_snippet,php_snippet,typescript_snippet,racket_snippet,erlang_snippet,elixir_snippet,dart_snippet,react_snippet
+0,apply-operations-to-maximize-score,Apply Operations to Maximize Score,2818.0,3001.0,"
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 chosen previously.
+ - Choose an element
x
of nums[l, ..., r]
with the highest prime score. If multiple such elements exist, choose the one with the smallest index.
+ - Multiply your score by
x
.
+
+
+Here, nums[l, ..., r]
denotes the subarray of nums
starting at index l
and ending at the index r
, both ends being inclusive.
+
+The prime score of an integer x
is equal to the number of distinct prime factors of x
. For example, the prime score of 300
is 3
since 300 = 2 * 2 * 3 * 5 * 5
.
+
+Return the maximum possible score after applying at most k
operations.
+
+Since the answer may be large, return it modulo 109 + 7
.
+
+
+Example 1:
+
+
+Input: nums = [8,3,9,3,8], k = 2
+Output: 81
+Explanation: To get a score of 81, we can apply the following operations:
+- Choose subarray nums[2, ..., 2]. nums[2] is the only element in this subarray. Hence, we multiply the score by nums[2]. The score becomes 1 * 9 = 9.
+- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 1, but nums[2] has the smaller index. Hence, we multiply the score by nums[2]. The score becomes 9 * 9 = 81.
+It can be proven that 81 is the highest score one can obtain.
+
+Example 2:
+
+
+Input: nums = [19,12,14,6,10,18], k = 3
+Output: 4788
+Explanation: To get a score of 4788, we can apply the following operations:
+- Choose subarray nums[0, ..., 0]. nums[0] is the only element in this subarray. Hence, we multiply the score by nums[0]. The score becomes 1 * 19 = 19.
+- Choose subarray nums[5, ..., 5]. nums[5] is the only element in this subarray. Hence, we multiply the score by nums[5]. The score becomes 19 * 18 = 342.
+- Choose subarray nums[2, ..., 3]. Both nums[2] and nums[3] have a prime score of 2, but nums[2] has the smaller index. Hence, we multipy the score by nums[2]. The score becomes 342 * 14 = 4788.
+It can be proven that 4788 is the highest score one can obtain.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length == n <= 105
+ 1 <= nums[i] <= 105
+ 1 <= k <= min(n * (n + 1) / 2, 109)
+
+",3.0,False,"class Solution {
+public:
+ int maximumScore(vector& nums, int k) {
+
+ }
+};","class Solution {
+ public int maximumScore(List nums, int k) {
+
+ }
+}","class Solution(object):
+ def maximumScore(self, nums, k):
+ """"""
+ :type nums: List[int]
+ :type k: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maximumScore(self, nums: List[int], k: int) -> int:
+ ","int maximumScore(int* nums, int numsSize, int k){
+
+}","public class Solution {
+ public int MaximumScore(IList nums, int k) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number} k
+ * @return {number}
+ */
+var maximumScore = function(nums, k) {
+
+};","# @param {Integer[]} nums
+# @param {Integer} k
+# @return {Integer}
+def maximum_score(nums, k)
+
+end","class Solution {
+ func maximumScore(_ nums: [Int], _ k: Int) -> Int {
+
+ }
+}","func maximumScore(nums []int, k int) int {
+
+}","object Solution {
+ def maximumScore(nums: List[Int], k: Int): Int = {
+
+ }
+}","class Solution {
+ fun maximumScore(nums: List, k: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn maximum_score(nums: Vec, k: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer $k
+ * @return Integer
+ */
+ function maximumScore($nums, $k) {
+
+ }
+}","function maximumScore(nums: number[], k: number): number {
+
+};","(define/contract (maximum-score nums k)
+ (-> (listof exact-integer?) exact-integer? exact-integer?)
+
+ )","-spec maximum_score(Nums :: [integer()], K :: integer()) -> integer().
+maximum_score(Nums, K) ->
+ .","defmodule Solution do
+ @spec maximum_score(nums :: [integer], k :: integer) :: integer
+ def maximum_score(nums, k) do
+
+ end
+end","class Solution {
+ int maximumScore(List nums, int k) {
+
+ }
+}",
+2,account-balance-after-rounded-purchase,Account Balance After Rounded Purchase,2806.0,2955.0,"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 of 10
. In other words, you pay a non-negative amount, roundedAmount
, such that roundedAmount
is a multiple of 10
and abs(roundedAmount - purchaseAmount)
is minimized.
+
+If there is more than one nearest multiple of 10
, the largest multiple is chosen.
+
+Return an integer denoting your account balance after making a purchase worth purchaseAmount
dollars from the store.
+
+Note: 0
is considered to be a multiple of 10
in this problem.
+
+
+Example 1:
+
+
+Input: purchaseAmount = 9
+Output: 90
+Explanation: In this example, the nearest multiple of 10 to 9 is 10. Hence, your account balance becomes 100 - 10 = 90.
+
+
+Example 2:
+
+
+Input: purchaseAmount = 15
+Output: 80
+Explanation: In this example, there are two nearest multiples of 10 to 15: 10 and 20. So, the larger multiple, 20, is chosen.
+Hence, your account balance becomes 100 - 20 = 80.
+
+
+
+Constraints:
+
+
+ 0 <= purchaseAmount <= 100
+
+",1.0,False,"class Solution {
+public:
+ int accountBalanceAfterPurchase(int purchaseAmount) {
+
+ }
+};","class Solution {
+ public int accountBalanceAfterPurchase(int purchaseAmount) {
+
+ }
+}","class Solution(object):
+ def accountBalanceAfterPurchase(self, purchaseAmount):
+ """"""
+ :type purchaseAmount: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:
+ ","int accountBalanceAfterPurchase(int purchaseAmount){
+
+}","public class Solution {
+ public int AccountBalanceAfterPurchase(int purchaseAmount) {
+
+ }
+}","/**
+ * @param {number} purchaseAmount
+ * @return {number}
+ */
+var accountBalanceAfterPurchase = function(purchaseAmount) {
+
+};","# @param {Integer} purchase_amount
+# @return {Integer}
+def account_balance_after_purchase(purchase_amount)
+
+end","class Solution {
+ func accountBalanceAfterPurchase(_ purchaseAmount: Int) -> Int {
+
+ }
+}","func accountBalanceAfterPurchase(purchaseAmount int) int {
+
+}","object Solution {
+ def accountBalanceAfterPurchase(purchaseAmount: Int): Int = {
+
+ }
+}","class Solution {
+ fun accountBalanceAfterPurchase(purchaseAmount: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn account_balance_after_purchase(purchase_amount: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $purchaseAmount
+ * @return Integer
+ */
+ function accountBalanceAfterPurchase($purchaseAmount) {
+
+ }
+}","function accountBalanceAfterPurchase(purchaseAmount: number): number {
+
+};","(define/contract (account-balance-after-purchase purchaseAmount)
+ (-> exact-integer? exact-integer?)
+
+ )","-spec account_balance_after_purchase(PurchaseAmount :: integer()) -> integer().
+account_balance_after_purchase(PurchaseAmount) ->
+ .","defmodule Solution do
+ @spec account_balance_after_purchase(purchase_amount :: integer) :: integer
+ def account_balance_after_purchase(purchase_amount) do
+
+ end
+end","class Solution {
+ int accountBalanceAfterPurchase(int purchaseAmount) {
+
+ }
+}",
+3,minimum-time-to-make-array-sum-at-most-x,Minimum Time to Make Array Sum At Most x,2809.0,2952.0,"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 < nums1.length
and make nums1[i] = 0
.
+
+
+You are also given an integer x
.
+
+Return the minimum time in which you can make the sum of all elements of nums1
to be less than or equal to x
, or -1
if this is not possible.
+
+
+Example 1:
+
+
+Input: nums1 = [1,2,3], nums2 = [1,2,3], x = 4
+Output: 3
+Explanation:
+For the 1st second, we apply the operation on i = 0. Therefore nums1 = [0,2+2,3+3] = [0,4,6].
+For the 2nd second, we apply the operation on i = 1. Therefore nums1 = [0+1,0,6+3] = [1,0,9].
+For the 3rd second, we apply the operation on i = 2. Therefore nums1 = [1+1,0+2,0] = [2,2,0].
+Now sum of nums1 = 4. It can be shown that these operations are optimal, so we return 3.
+
+
+
+Example 2:
+
+
+Input: nums1 = [1,2,3], nums2 = [3,3,3], x = 4
+Output: -1
+Explanation: It can be shown that the sum of nums1 will always be greater than x, no matter which operations are performed.
+
+
+
+Constraints:
+
+
+ 1 <= nums1.length <= 103
+ 1 <= nums1[i] <= 103
+ 0 <= nums2[i] <= 103
+ nums1.length == nums2.length
+ 0 <= x <= 106
+
+",3.0,False,"class Solution {
+public:
+ int minimumTime(vector& nums1, vector& nums2, int x) {
+
+ }
+};","class Solution {
+ public int minimumTime(List nums1, List nums2, int x) {
+
+ }
+}","class Solution(object):
+ def minimumTime(self, nums1, nums2, x):
+ """"""
+ :type nums1: List[int]
+ :type nums2: List[int]
+ :type x: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def minimumTime(self, nums1: List[int], nums2: List[int], x: int) -> int:
+ ","int minimumTime(int* nums1, int nums1Size, int* nums2, int nums2Size, int x){
+
+}","public class Solution {
+ public int MinimumTime(IList nums1, IList nums2, int x) {
+
+ }
+}","/**
+ * @param {number[]} nums1
+ * @param {number[]} nums2
+ * @param {number} x
+ * @return {number}
+ */
+var minimumTime = function(nums1, nums2, x) {
+
+};","# @param {Integer[]} nums1
+# @param {Integer[]} nums2
+# @param {Integer} x
+# @return {Integer}
+def minimum_time(nums1, nums2, x)
+
+end","class Solution {
+ func minimumTime(_ nums1: [Int], _ nums2: [Int], _ x: Int) -> Int {
+
+ }
+}","func minimumTime(nums1 []int, nums2 []int, x int) int {
+
+}","object Solution {
+ def minimumTime(nums1: List[Int], nums2: List[Int], x: Int): Int = {
+
+ }
+}","class Solution {
+ fun minimumTime(nums1: List, nums2: List, x: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn minimum_time(nums1: Vec, nums2: Vec, x: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums1
+ * @param Integer[] $nums2
+ * @param Integer $x
+ * @return Integer
+ */
+ function minimumTime($nums1, $nums2, $x) {
+
+ }
+}","function minimumTime(nums1: number[], nums2: number[], x: number): number {
+
+};","(define/contract (minimum-time nums1 nums2 x)
+ (-> (listof exact-integer?) (listof exact-integer?) exact-integer? exact-integer?)
+
+ )","-spec minimum_time(Nums1 :: [integer()], Nums2 :: [integer()], X :: integer()) -> integer().
+minimum_time(Nums1, Nums2, X) ->
+ .","defmodule Solution do
+ @spec minimum_time(nums1 :: [integer], nums2 :: [integer], x :: integer) :: integer
+ def minimum_time(nums1, nums2, x) do
+
+ end
+end","class Solution {
+ int minimumTime(List nums1, List nums2, int x) {
+
+ }
+}",
+4,count-stepping-numbers-in-range,Count Stepping Numbers in Range,2801.0,2921.0,"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 integer denoting the count of stepping numbers in the inclusive range [low, high]
.
+
+Since the answer may be very large, return it modulo 109 + 7
.
+
+Note: A stepping number should not have a leading zero.
+
+
+Example 1:
+
+
+Input: low = "1", high = "11"
+Output: 10
+Explanation: The stepping numbers in the range [1,11] are 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10. There are a total of 10 stepping numbers in the range. Hence, the output is 10.
+
+Example 2:
+
+
+Input: low = "90", high = "101"
+Output: 2
+Explanation: The stepping numbers in the range [90,101] are 98 and 101. There are a total of 2 stepping numbers in the range. Hence, the output is 2.
+
+
+Constraints:
+
+
+ 1 <= int(low) <= int(high) < 10100
+ 1 <= low.length, high.length <= 100
+ low
and high
consist of only digits.
+ low
and high
don't have any leading zeros.
+
+",3.0,False,"class Solution {
+public:
+ int countSteppingNumbers(string low, string high) {
+
+ }
+};","class Solution {
+ public int countSteppingNumbers(String low, String high) {
+
+ }
+}","class Solution(object):
+ def countSteppingNumbers(self, low, high):
+ """"""
+ :type low: str
+ :type high: str
+ :rtype: int
+ """"""
+ ","class Solution:
+ def countSteppingNumbers(self, low: str, high: str) -> int:
+ ","int countSteppingNumbers(char * low, char * high){
+
+}","public class Solution {
+ public int CountSteppingNumbers(string low, string high) {
+
+ }
+}","/**
+ * @param {string} low
+ * @param {string} high
+ * @return {number}
+ */
+var countSteppingNumbers = function(low, high) {
+
+};","# @param {String} low
+# @param {String} high
+# @return {Integer}
+def count_stepping_numbers(low, high)
+
+end","class Solution {
+ func countSteppingNumbers(_ low: String, _ high: String) -> Int {
+
+ }
+}","func countSteppingNumbers(low string, high string) int {
+
+}","object Solution {
+ def countSteppingNumbers(low: String, high: String): Int = {
+
+ }
+}","class Solution {
+ fun countSteppingNumbers(low: String, high: String): Int {
+
+ }
+}","impl Solution {
+ pub fn count_stepping_numbers(low: String, high: String) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $low
+ * @param String $high
+ * @return Integer
+ */
+ function countSteppingNumbers($low, $high) {
+
+ }
+}","function countSteppingNumbers(low: string, high: string): number {
+
+};","(define/contract (count-stepping-numbers low high)
+ (-> string? string? exact-integer?)
+
+ )","-spec count_stepping_numbers(Low :: unicode:unicode_binary(), High :: unicode:unicode_binary()) -> integer().
+count_stepping_numbers(Low, High) ->
+ .","defmodule Solution do
+ @spec count_stepping_numbers(low :: String.t, high :: String.t) :: integer
+ def count_stepping_numbers(low, high) do
+
+ end
+end","class Solution {
+ int countSteppingNumbers(String low, String high) {
+
+ }
+}",
+5,minimum-seconds-to-equalize-a-circular-array,Minimum Seconds to Equalize a Circular Array,2808.0,2920.0,"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) % n]
.
+
+
+Note that all the elements get replaced simultaneously.
+
+Return the minimum number of seconds needed to make all elements in the array nums
equal.
+
+
+Example 1:
+
+
+Input: nums = [1,2,1,2]
+Output: 1
+Explanation: We can equalize the array in 1 second in the following way:
+- At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2].
+It can be proven that 1 second is the minimum amount of seconds needed for equalizing the array.
+
+
+Example 2:
+
+
+Input: nums = [2,1,3,3,2]
+Output: 2
+Explanation: We can equalize the array in 2 seconds in the following way:
+- At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3].
+- At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3].
+It can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array.
+
+
+Example 3:
+
+
+Input: nums = [5,5,5,5]
+Output: 0
+Explanation: We don't need to perform any operations as all elements in the initial array are the same.
+
+
+
+Constraints:
+
+
+ 1 <= n == nums.length <= 105
+ 1 <= nums[i] <= 109
+
+",2.0,False,"class Solution {
+public:
+ int minimumSeconds(vector& nums) {
+
+ }
+};","class Solution {
+ public int minimumSeconds(List nums) {
+
+ }
+}","class Solution(object):
+ def minimumSeconds(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def minimumSeconds(self, nums: List[int]) -> int:
+ ","int minimumSeconds(int* nums, int numsSize){
+
+}","public class Solution {
+ public int MinimumSeconds(IList nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var minimumSeconds = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def minimum_seconds(nums)
+
+end","class Solution {
+ func minimumSeconds(_ nums: [Int]) -> Int {
+
+ }
+}","func minimumSeconds(nums []int) int {
+
+}","object Solution {
+ def minimumSeconds(nums: List[Int]): Int = {
+
+ }
+}","class Solution {
+ fun minimumSeconds(nums: List): Int {
+
+ }
+}","impl Solution {
+ pub fn minimum_seconds(nums: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function minimumSeconds($nums) {
+
+ }
+}","function minimumSeconds(nums: number[]): number {
+
+};","(define/contract (minimum-seconds nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec minimum_seconds(Nums :: [integer()]) -> integer().
+minimum_seconds(Nums) ->
+ .","defmodule Solution do
+ @spec minimum_seconds(nums :: [integer]) :: integer
+ def minimum_seconds(nums) do
+
+ end
+end","class Solution {
+ int minimumSeconds(List nums) {
+
+ }
+}",
+6,maximum-number-of-groups-with-increasing-length,Maximum Number of Groups With Increasing Length,2790.0,2919.0,"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 following conditions:
+
+
+ - Each group must consist of distinct numbers, meaning that no duplicate numbers are allowed within a single group.
+ - Each group (except the first one) must have a length strictly greater than the previous group.
+
+
+Return an integer denoting the maximum number of groups you can create while satisfying these conditions.
+
+
+Example 1:
+
+
+Input: usageLimits
= [1,2,5]
+Output: 3
+Explanation: In this example, we can use 0 at most once, 1 at most twice, and 2 at most five times.
+One way of creating the maximum number of groups while satisfying the conditions is:
+Group 1 contains the number [2].
+Group 2 contains the numbers [1,2].
+Group 3 contains the numbers [0,1,2].
+It can be shown that the maximum number of groups is 3.
+So, the output is 3.
+
+Example 2:
+
+
+Input: usageLimits
= [2,1,2]
+Output: 2
+Explanation: In this example, we can use 0 at most twice, 1 at most once, and 2 at most twice.
+One way of creating the maximum number of groups while satisfying the conditions is:
+Group 1 contains the number [0].
+Group 2 contains the numbers [1,2].
+It can be shown that the maximum number of groups is 2.
+So, the output is 2.
+
+
+Example 3:
+
+
+Input: usageLimits
= [1,1]
+Output: 1
+Explanation: In this example, we can use both 0 and 1 at most once.
+One way of creating the maximum number of groups while satisfying the conditions is:
+Group 1 contains the number [0].
+It can be shown that the maximum number of groups is 1.
+So, the output is 1.
+
+
+
+Constraints:
+
+
+ 1 <= usageLimits.length <= 105
+ 1 <= usageLimits[i] <= 109
+
+",3.0,False,"class Solution {
+public:
+ int maxIncreasingGroups(vector& usageLimits) {
+
+ }
+};","class Solution {
+ public int maxIncreasingGroups(List usageLimits) {
+
+ }
+}","class Solution(object):
+ def maxIncreasingGroups(self, usageLimits):
+ """"""
+ :type usageLimits: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maxIncreasingGroups(self, usageLimits: List[int]) -> int:
+ ","int maxIncreasingGroups(int* usageLimits, int usageLimitsSize){
+
+}","public class Solution {
+ public int MaxIncreasingGroups(IList usageLimits) {
+
+ }
+}","/**
+ * @param {number[]} usageLimits
+ * @return {number}
+ */
+var maxIncreasingGroups = function(usageLimits) {
+
+};","# @param {Integer[]} usage_limits
+# @return {Integer}
+def max_increasing_groups(usage_limits)
+
+end","class Solution {
+ func maxIncreasingGroups(_ usageLimits: [Int]) -> Int {
+
+ }
+}","func maxIncreasingGroups(usageLimits []int) int {
+
+}","object Solution {
+ def maxIncreasingGroups(usageLimits: List[Int]): Int = {
+
+ }
+}","class Solution {
+ fun maxIncreasingGroups(usageLimits: List): Int {
+
+ }
+}","impl Solution {
+ pub fn max_increasing_groups(usage_limits: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $usageLimits
+ * @return Integer
+ */
+ function maxIncreasingGroups($usageLimits) {
+
+ }
+}","function maxIncreasingGroups(usageLimits: number[]): number {
+
+};","(define/contract (max-increasing-groups usageLimits)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec max_increasing_groups(UsageLimits :: [integer()]) -> integer().
+max_increasing_groups(UsageLimits) ->
+ .","defmodule Solution do
+ @spec max_increasing_groups(usage_limits :: [integer]) :: integer
+ def max_increasing_groups(usage_limits) do
+
+ end
+end","class Solution {
+ int maxIncreasingGroups(List usageLimits) {
+
+ }
+}",
+7,check-if-it-is-possible-to-split-array,Check if it is Possible to Split Array,2811.0,2916.0,"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) with a length of at least two and split it into two subarrays, if, for each resulting subarray, at least one of the following holds:
+
+
+ - The length of the subarray is one, or
+ - The sum of elements of the subarray is greater than or equal to
m
.
+
+
+Return true
if you can split the given array into n
arrays, otherwise return false
.
+
+Note: A subarray is a contiguous non-empty sequence of elements within an array.
+
+
+Example 1:
+
+
+Input: nums = [2, 2, 1], m = 4
+Output: true
+Explanation: We can split the array into [2, 2] and [1] in the first step. Then, in the second step, we can split [2, 2] into [2] and [2]. As a result, the answer is true.
+
+Example 2:
+
+
+Input: nums = [2, 1, 3], m = 5
+Output: false
+Explanation: We can try splitting the array in two different ways: the first way is to have [2, 1] and [3], and the second way is to have [2] and [1, 3]. However, both of these ways are not valid. So, the answer is false.
+
+Example 3:
+
+
+Input: nums = [2, 3, 3, 2, 3], m = 6
+Output: true
+Explanation: We can split the array into [2, 3, 3, 2] and [3] in the first step. Then, in the second step, we can split [2, 3, 3, 2] into [2, 3, 3] and [2]. Then, in the third step, we can split [2, 3, 3] into [2] and [3, 3]. And in the last step we can split [3, 3] into [3] and [3]. As a result, the answer is true.
+
+
+
+Constraints:
+
+
+ 1 <= n == nums.length <= 100
+ 1 <= nums[i] <= 100
+ 1 <= m <= 200
+
+",2.0,False,"class Solution {
+public:
+ bool canSplitArray(vector& nums, int m) {
+
+ }
+};","class Solution {
+ public boolean canSplitArray(List nums, int m) {
+
+ }
+}","class Solution(object):
+ def canSplitArray(self, nums, m):
+ """"""
+ :type nums: List[int]
+ :type m: int
+ :rtype: bool
+ """"""
+ ","class Solution:
+ def canSplitArray(self, nums: List[int], m: int) -> bool:
+ ","bool canSplitArray(int* nums, int numsSize, int m){
+
+}","public class Solution {
+ public bool CanSplitArray(IList nums, int m) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number} m
+ * @return {boolean}
+ */
+var canSplitArray = function(nums, m) {
+
+};","# @param {Integer[]} nums
+# @param {Integer} m
+# @return {Boolean}
+def can_split_array(nums, m)
+
+end","class Solution {
+ func canSplitArray(_ nums: [Int], _ m: Int) -> Bool {
+
+ }
+}","func canSplitArray(nums []int, m int) bool {
+
+}","object Solution {
+ def canSplitArray(nums: List[Int], m: Int): Boolean = {
+
+ }
+}","class Solution {
+ fun canSplitArray(nums: List, m: Int): Boolean {
+
+ }
+}","impl Solution {
+ pub fn can_split_array(nums: Vec, m: i32) -> bool {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer $m
+ * @return Boolean
+ */
+ function canSplitArray($nums, $m) {
+
+ }
+}","function canSplitArray(nums: number[], m: number): boolean {
+
+};","(define/contract (can-split-array nums m)
+ (-> (listof exact-integer?) exact-integer? boolean?)
+
+ )","-spec can_split_array(Nums :: [integer()], M :: integer()) -> boolean().
+can_split_array(Nums, M) ->
+ .","defmodule Solution do
+ @spec can_split_array(nums :: [integer], m :: integer) :: boolean
+ def can_split_array(nums, m) do
+
+ end
+end","class Solution {
+ bool canSplitArray(List nums, int m) {
+
+ }
+}",
+8,find-the-safest-path-in-a-grid,Find the Safest Path in a Grid,2812.0,2914.0,"You are given a 0-indexed 2D matrix grid
of size n x n
, where (r, c)
represents:
+
+
+ - A cell containing a thief if
grid[r][c] = 1
+ - An empty cell if
grid[r][c] = 0
+
+
+You are initially positioned at cell (0, 0)
. In one move, you can move to any adjacent cell in the grid, including cells containing thieves.
+
+The safeness factor of a path on the grid is defined as the minimum manhattan distance from any cell in the path to any thief in the grid.
+
+Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1)
.
+
+An adjacent cell of cell (r, c)
, is one of the cells (r, c + 1)
, (r, c - 1)
, (r + 1, c)
and (r - 1, c)
if it exists.
+
+The Manhattan distance between two cells (a, b)
and (x, y)
is equal to |a - x| + |b - y|
, where |val|
denotes the absolute value of val.
+
+
+Example 1:
+
+
+Input: grid = [[1,0,0],[0,0,0],[0,0,1]]
+Output: 0
+Explanation: All paths from (0, 0) to (n - 1, n - 1) go through the thieves in cells (0, 0) and (n - 1, n - 1).
+
+
+Example 2:
+
+
+Input: grid = [[0,0,1],[0,0,0],[0,0,0]]
+Output: 2
+Explanation: The path depicted in the picture above has a safeness factor of 2 since:
+- The closest cell of the path to the thief at cell (0, 2) is cell (0, 0). The distance between them is | 0 - 0 | + | 0 - 2 | = 2.
+It can be shown that there are no other paths with a higher safeness factor.
+
+
+Example 3:
+
+
+Input: grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]
+Output: 2
+Explanation: The path depicted in the picture above has a safeness factor of 2 since:
+- The closest cell of the path to the thief at cell (0, 3) is cell (1, 2). The distance between them is | 0 - 1 | + | 3 - 2 | = 2.
+- The closest cell of the path to the thief at cell (3, 0) is cell (3, 2). The distance between them is | 3 - 3 | + | 0 - 2 | = 2.
+It can be shown that there are no other paths with a higher safeness factor.
+
+
+
+Constraints:
+
+
+ 1 <= grid.length == n <= 400
+ grid[i].length == n
+ grid[i][j]
is either 0
or 1
.
+ - There is at least one thief in the
grid
.
+
+",2.0,False,"class Solution {
+public:
+ int maximumSafenessFactor(vector>& grid) {
+
+ }
+};","class Solution {
+ public int maximumSafenessFactor(List> grid) {
+
+ }
+}","class Solution(object):
+ def maximumSafenessFactor(self, grid):
+ """"""
+ :type grid: List[List[int]]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maximumSafenessFactor(self, grid: List[List[int]]) -> int:
+ ","int maximumSafenessFactor(int** grid, int gridSize, int* gridColSize){
+
+}","public class Solution {
+ public int MaximumSafenessFactor(IList> grid) {
+
+ }
+}","/**
+ * @param {number[][]} grid
+ * @return {number}
+ */
+var maximumSafenessFactor = function(grid) {
+
+};","# @param {Integer[][]} grid
+# @return {Integer}
+def maximum_safeness_factor(grid)
+
+end","class Solution {
+ func maximumSafenessFactor(_ grid: [[Int]]) -> Int {
+
+ }
+}","func maximumSafenessFactor(grid [][]int) int {
+
+}","object Solution {
+ def maximumSafenessFactor(grid: List[List[Int]]): Int = {
+
+ }
+}","class Solution {
+ fun maximumSafenessFactor(grid: List>): Int {
+
+ }
+}","impl Solution {
+ pub fn maximum_safeness_factor(grid: Vec>) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[][] $grid
+ * @return Integer
+ */
+ function maximumSafenessFactor($grid) {
+
+ }
+}","function maximumSafenessFactor(grid: number[][]): number {
+
+};","(define/contract (maximum-safeness-factor grid)
+ (-> (listof (listof exact-integer?)) exact-integer?)
+
+ )","-spec maximum_safeness_factor(Grid :: [[integer()]]) -> integer().
+maximum_safeness_factor(Grid) ->
+ .","defmodule Solution do
+ @spec maximum_safeness_factor(grid :: [[integer]]) :: integer
+ def maximum_safeness_factor(grid) do
+
+ end
+end","class Solution {
+ int maximumSafenessFactor(List> grid) {
+
+ }
+}",
+9,count-paths-that-can-form-a-palindrome-in-a-tree,Count Paths That Can Form a Palindrome in a Tree,2791.0,2905.0,"You are given a tree (i.e. a connected, undirected graph that has no cycles) rooted at node 0
consisting of n
nodes numbered from 0
to n - 1
. The tree is represented by a 0-indexed array parent
of size n
, where parent[i]
is the parent of node i
. Since node 0
is the root, parent[0] == -1
.
+
+You are also given a string s
of length n
, where s[i]
is the character assigned to the edge between i
and parent[i]
. s[0]
can be ignored.
+
+Return the number of pairs of nodes (u, v)
such that u < v
and the characters assigned to edges on the path from u
to v
can be rearranged to form a palindrome.
+
+A string is a palindrome when it reads the same backwards as forwards.
+
+
+Example 1:
+
+
+
+
+Input: parent = [-1,0,0,1,1,2], s = "acaabc"
+Output: 8
+Explanation: The valid pairs are:
+- All the pairs (0,1), (0,2), (1,3), (1,4) and (2,5) result in one character which is always a palindrome.
+- The pair (2,3) result in the string "aca" which is a palindrome.
+- The pair (1,5) result in the string "cac" which is a palindrome.
+- The pair (3,5) result in the string "acac" which can be rearranged into the palindrome "acca".
+
+
+Example 2:
+
+
+Input: parent = [-1,0,0,0,0], s = "aaaaa"
+Output: 10
+Explanation: Any pair of nodes (u,v) where u < v is valid.
+
+
+
+Constraints:
+
+
+ n == parent.length == s.length
+ 1 <= n <= 105
+ 0 <= parent[i] <= n - 1
for all i >= 1
+ parent[0] == -1
+ parent
represents a valid tree.
+ s
consists of only lowercase English letters.
+
+",3.0,False,"class Solution {
+public:
+ long long countPalindromePaths(vector& parent, string s) {
+
+ }
+};","class Solution {
+ public long countPalindromePaths(List parent, String s) {
+
+ }
+}","class Solution(object):
+ def countPalindromePaths(self, parent, s):
+ """"""
+ :type parent: List[int]
+ :type s: str
+ :rtype: int
+ """"""
+ ","class Solution:
+ def countPalindromePaths(self, parent: List[int], s: str) -> int:
+ ","long long countPalindromePaths(int* parent, int parentSize, char * s){
+
+}","public class Solution {
+ public long CountPalindromePaths(IList parent, string s) {
+
+ }
+}","/**
+ * @param {number[]} parent
+ * @param {string} s
+ * @return {number}
+ */
+var countPalindromePaths = function(parent, s) {
+
+};","# @param {Integer[]} parent
+# @param {String} s
+# @return {Integer}
+def count_palindrome_paths(parent, s)
+
+end","class Solution {
+ func countPalindromePaths(_ parent: [Int], _ s: String) -> Int {
+
+ }
+}","func countPalindromePaths(parent []int, s string) int64 {
+
+}","object Solution {
+ def countPalindromePaths(parent: List[Int], s: String): Long = {
+
+ }
+}","class Solution {
+ fun countPalindromePaths(parent: List, s: String): Long {
+
+ }
+}","impl Solution {
+ pub fn count_palindrome_paths(parent: Vec, s: String) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $parent
+ * @param String $s
+ * @return Integer
+ */
+ function countPalindromePaths($parent, $s) {
+
+ }
+}","function countPalindromePaths(parent: number[], s: string): number {
+
+};","(define/contract (count-palindrome-paths parent s)
+ (-> (listof exact-integer?) string? exact-integer?)
+
+ )","-spec count_palindrome_paths(Parent :: [integer()], S :: unicode:unicode_binary()) -> integer().
+count_palindrome_paths(Parent, S) ->
+ .","defmodule Solution do
+ @spec count_palindrome_paths(parent :: [integer], s :: String.t) :: integer
+ def count_palindrome_paths(parent, s) do
+
+ end
+end","class Solution {
+ int countPalindromePaths(List parent, String s) {
+
+ }
+}",
+10,insert-greatest-common-divisors-in-linked-list,Insert Greatest Common Divisors in Linked List,2807.0,2903.0,"Given the head of a linked list head
, in which each node contains an integer value.
+
+Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.
+
+Return the linked list after insertion.
+
+The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
+
+
+Example 1:
+
+
+Input: head = [18,6,10,3]
+Output: [18,6,6,2,10,1,3]
+Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).
+- We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.
+- We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.
+- We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.
+There are no more adjacent nodes, so we return the linked list.
+
+
+Example 2:
+
+
+Input: head = [7]
+Output: [7]
+Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.
+There are no pairs of adjacent nodes, so we return the initial linked list.
+
+
+
+Constraints:
+
+
+ - The number of nodes in the list is in the range
[1, 5000]
.
+ 1 <= Node.val <= 1000
+
+",2.0,False,"/**
+ * Definition for singly-linked list.
+ * struct ListNode {
+ * int val;
+ * ListNode *next;
+ * ListNode() : val(0), next(nullptr) {}
+ * ListNode(int x) : val(x), next(nullptr) {}
+ * ListNode(int x, ListNode *next) : val(x), next(next) {}
+ * };
+ */
+class Solution {
+public:
+ ListNode* insertGreatestCommonDivisors(ListNode* head) {
+
+ }
+};","/**
+ * Definition for singly-linked list.
+ * public class ListNode {
+ * int val;
+ * ListNode next;
+ * ListNode() {}
+ * ListNode(int val) { this.val = val; }
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
+ * }
+ */
+class Solution {
+ public ListNode insertGreatestCommonDivisors(ListNode head) {
+
+ }
+}","# Definition for singly-linked list.
+# class ListNode(object):
+# def __init__(self, val=0, next=None):
+# self.val = val
+# self.next = next
+class Solution(object):
+ def insertGreatestCommonDivisors(self, head):
+ """"""
+ :type head: Optional[ListNode]
+ :rtype: Optional[ListNode]
+ """"""
+ ","# Definition for singly-linked list.
+# class ListNode:
+# def __init__(self, val=0, next=None):
+# self.val = val
+# self.next = next
+class Solution:
+ def insertGreatestCommonDivisors(self, head: Optional[ListNode]) -> Optional[ListNode]:
+ ","/**
+ * Definition for singly-linked list.
+ * struct ListNode {
+ * int val;
+ * struct ListNode *next;
+ * };
+ */
+struct ListNode* insertGreatestCommonDivisors(struct ListNode* head){
+
+}","/**
+ * Definition for singly-linked list.
+ * public class ListNode {
+ * public int val;
+ * public ListNode next;
+ * public ListNode(int val=0, ListNode next=null) {
+ * this.val = val;
+ * this.next = next;
+ * }
+ * }
+ */
+public class Solution {
+ public ListNode InsertGreatestCommonDivisors(ListNode head) {
+
+ }
+}","/**
+ * Definition for singly-linked list.
+ * function ListNode(val, next) {
+ * this.val = (val===undefined ? 0 : val)
+ * this.next = (next===undefined ? null : next)
+ * }
+ */
+/**
+ * @param {ListNode} head
+ * @return {ListNode}
+ */
+var insertGreatestCommonDivisors = function(head) {
+
+};","# Definition for singly-linked list.
+# class ListNode
+# attr_accessor :val, :next
+# def initialize(val = 0, _next = nil)
+# @val = val
+# @next = _next
+# end
+# end
+# @param {ListNode} head
+# @return {ListNode}
+def insert_greatest_common_divisors(head)
+
+end","/**
+ * Definition for singly-linked list.
+ * public class ListNode {
+ * public var val: Int
+ * public var next: ListNode?
+ * public init() { self.val = 0; self.next = nil; }
+ * public init(_ val: Int) { self.val = val; self.next = nil; }
+ * public init(_ val: Int, _ next: ListNode?) { self.val = val; self.next = next; }
+ * }
+ */
+class Solution {
+ func insertGreatestCommonDivisors(_ head: ListNode?) -> ListNode? {
+
+ }
+}","/**
+ * Definition for singly-linked list.
+ * type ListNode struct {
+ * Val int
+ * Next *ListNode
+ * }
+ */
+func insertGreatestCommonDivisors(head *ListNode) *ListNode {
+
+}","/**
+ * Definition for singly-linked list.
+ * class ListNode(_x: Int = 0, _next: ListNode = null) {
+ * var next: ListNode = _next
+ * var x: Int = _x
+ * }
+ */
+object Solution {
+ def insertGreatestCommonDivisors(head: ListNode): ListNode = {
+
+ }
+}","/**
+ * Example:
+ * var li = ListNode(5)
+ * var v = li.`val`
+ * Definition for singly-linked list.
+ * class ListNode(var `val`: Int) {
+ * var next: ListNode? = null
+ * }
+ */
+class Solution {
+ fun insertGreatestCommonDivisors(head: ListNode?): ListNode? {
+
+ }
+}","// Definition for singly-linked list.
+// #[derive(PartialEq, Eq, Clone, Debug)]
+// pub struct ListNode {
+// pub val: i32,
+// pub next: Option>
+// }
+//
+// impl ListNode {
+// #[inline]
+// fn new(val: i32) -> Self {
+// ListNode {
+// next: None,
+// val
+// }
+// }
+// }
+impl Solution {
+ pub fn insert_greatest_common_divisors(head: Option>) -> Option> {
+
+ }
+}","/**
+ * Definition for a singly-linked list.
+ * class ListNode {
+ * public $val = 0;
+ * public $next = null;
+ * function __construct($val = 0, $next = null) {
+ * $this->val = $val;
+ * $this->next = $next;
+ * }
+ * }
+ */
+class Solution {
+
+ /**
+ * @param ListNode $head
+ * @return ListNode
+ */
+ function insertGreatestCommonDivisors($head) {
+
+ }
+}","/**
+ * Definition for singly-linked list.
+ * class ListNode {
+ * val: number
+ * next: ListNode | null
+ * constructor(val?: number, next?: ListNode | null) {
+ * this.val = (val===undefined ? 0 : val)
+ * this.next = (next===undefined ? null : next)
+ * }
+ * }
+ */
+
+function insertGreatestCommonDivisors(head: ListNode | null): ListNode | null {
+
+};","; Definition for singly-linked list:
+#|
+
+; val : integer?
+; next : (or/c list-node? #f)
+(struct list-node
+ (val next) #:mutable #:transparent)
+
+; constructor
+(define (make-list-node [val 0])
+ (list-node val #f))
+
+|#
+
+(define/contract (insert-greatest-common-divisors head)
+ (-> (or/c list-node? #f) (or/c list-node? #f))
+
+ )","%% Definition for singly-linked list.
+%%
+%% -record(list_node, {val = 0 :: integer(),
+%% next = null :: 'null' | #list_node{}}).
+
+-spec insert_greatest_common_divisors(Head :: #list_node{} | null) -> #list_node{} | null.
+insert_greatest_common_divisors(Head) ->
+ .","# Definition for singly-linked list.
+#
+# defmodule ListNode do
+# @type t :: %__MODULE__{
+# val: integer,
+# next: ListNode.t() | nil
+# }
+# defstruct val: 0, next: nil
+# end
+
+defmodule Solution do
+ @spec insert_greatest_common_divisors(head :: ListNode.t | nil) :: ListNode.t | nil
+ def insert_greatest_common_divisors(head) do
+
+ end
+end","/**
+ * Definition for singly-linked list.
+ * class ListNode {
+ * int val;
+ * ListNode? next;
+ * ListNode([this.val = 0, this.next]);
+ * }
+ */
+class Solution {
+ ListNode? insertGreatestCommonDivisors(ListNode? head) {
+
+ }
+}",
+12,maximum-elegance-of-a-k-length-subsequence,Maximum Elegance of a K-Length Subsequence,2813.0,2894.0,"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 of items
as total_profit + distinct_categories2
, where total_profit
is the sum of all profits in the subsequence, and distinct_categories
is the number of distinct categories from all the categories in the selected subsequence.
+
+Your task is to find the maximum elegance from all subsequences of size k
in items
.
+
+Return an integer denoting the maximum elegance of a subsequence of items
with size exactly k
.
+
+Note: A subsequence of an array is a new array generated from the original array by deleting some elements (possibly none) without changing the remaining elements' relative order.
+
+
+Example 1:
+
+
+Input: items = [[3,2],[5,1],[10,1]], k = 2
+Output: 17
+Explanation: In this example, we have to select a subsequence of size 2.
+We can select items[0] = [3,2] and items[2] = [10,1].
+The total profit in this subsequence is 3 + 10 = 13, and the subsequence contains 2 distinct categories [2,1].
+Hence, the elegance is 13 + 22 = 17, and we can show that it is the maximum achievable elegance.
+
+
+Example 2:
+
+
+Input: items = [[3,1],[3,1],[2,2],[5,3]], k = 3
+Output: 19
+Explanation: In this example, we have to select a subsequence of size 3.
+We can select items[0] = [3,1], items[2] = [2,2], and items[3] = [5,3].
+The total profit in this subsequence is 3 + 2 + 5 = 10, and the subsequence contains 3 distinct categories [1,2,3].
+Hence, the elegance is 10 + 32 = 19, and we can show that it is the maximum achievable elegance.
+
+Example 3:
+
+
+Input: items = [[1,1],[2,1],[3,1]], k = 3
+Output: 7
+Explanation: In this example, we have to select a subsequence of size 3.
+We should select all the items.
+The total profit will be 1 + 2 + 3 = 6, and the subsequence contains 1 distinct category [1].
+Hence, the maximum elegance is 6 + 12 = 7.
+
+
+Constraints:
+
+
+ 1 <= items.length == n <= 105
+ items[i].length == 2
+ items[i][0] == profiti
+ items[i][1] == categoryi
+ 1 <= profiti <= 109
+ 1 <= categoryi <= n
+ 1 <= k <= n
+
+",3.0,False,"class Solution {
+public:
+ long long findMaximumElegance(vector>& items, int k) {
+
+ }
+};","class Solution {
+ public long findMaximumElegance(int[][] items, int k) {
+
+ }
+}","class Solution(object):
+ def findMaximumElegance(self, items, k):
+ """"""
+ :type items: List[List[int]]
+ :type k: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def findMaximumElegance(self, items: List[List[int]], k: int) -> int:
+ ","long long findMaximumElegance(int** items, int itemsSize, int* itemsColSize, int k){
+
+}","public class Solution {
+ public long FindMaximumElegance(int[][] items, int k) {
+
+ }
+}","/**
+ * @param {number[][]} items
+ * @param {number} k
+ * @return {number}
+ */
+var findMaximumElegance = function(items, k) {
+
+};","# @param {Integer[][]} items
+# @param {Integer} k
+# @return {Integer}
+def find_maximum_elegance(items, k)
+
+end","class Solution {
+ func findMaximumElegance(_ items: [[Int]], _ k: Int) -> Int {
+
+ }
+}","func findMaximumElegance(items [][]int, k int) int64 {
+
+}","object Solution {
+ def findMaximumElegance(items: Array[Array[Int]], k: Int): Long = {
+
+ }
+}","class Solution {
+ fun findMaximumElegance(items: Array, k: Int): Long {
+
+ }
+}","impl Solution {
+ pub fn find_maximum_elegance(items: Vec>, k: i32) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[][] $items
+ * @param Integer $k
+ * @return Integer
+ */
+ function findMaximumElegance($items, $k) {
+
+ }
+}","function findMaximumElegance(items: number[][], k: number): number {
+
+};","(define/contract (find-maximum-elegance items k)
+ (-> (listof (listof exact-integer?)) exact-integer? exact-integer?)
+
+ )","-spec find_maximum_elegance(Items :: [[integer()]], K :: integer()) -> integer().
+find_maximum_elegance(Items, K) ->
+ .","defmodule Solution do
+ @spec find_maximum_elegance(items :: [[integer]], k :: integer) :: integer
+ def find_maximum_elegance(items, k) do
+
+ end
+end","class Solution {
+ int findMaximumElegance(List> items, int k) {
+
+ }
+}",
+14,check-if-array-is-good,Check if Array is Good,2784.0,2892.0,"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, base[1] = [1, 1]
and base[3] = [1, 2, 3, 3]
.
+
+Return true
if the given array is good, otherwise return false
.
+
+Note: A permutation of integers represents an arrangement of these numbers.
+
+
+Example 1:
+
+
+Input: nums = [2, 1, 3]
+Output: false
+Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false.
+
+
+Example 2:
+
+
+Input: nums = [1, 3, 3, 2]
+Output: true
+Explanation: Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true.
+
+Example 3:
+
+
+Input: nums = [1, 1]
+Output: true
+Explanation: Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true.
+
+Example 4:
+
+
+Input: nums = [3, 4, 4, 1, 2, 1]
+Output: false
+Explanation: Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 100
+ 1 <= num[i] <= 200
+
+",1.0,False,"class Solution {
+public:
+ bool isGood(vector& nums) {
+
+ }
+};","class Solution {
+ public boolean isGood(int[] nums) {
+
+ }
+}","class Solution(object):
+ def isGood(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: bool
+ """"""
+ ","class Solution:
+ def isGood(self, nums: List[int]) -> bool:
+ ","bool isGood(int* nums, int numsSize){
+
+}","public class Solution {
+ public bool IsGood(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {boolean}
+ */
+var isGood = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Boolean}
+def is_good(nums)
+
+end","class Solution {
+ func isGood(_ nums: [Int]) -> Bool {
+
+ }
+}","func isGood(nums []int) bool {
+
+}","object Solution {
+ def isGood(nums: Array[Int]): Boolean = {
+
+ }
+}","class Solution {
+ fun isGood(nums: IntArray): Boolean {
+
+ }
+}","impl Solution {
+ pub fn is_good(nums: Vec) -> bool {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Boolean
+ */
+ function isGood($nums) {
+
+ }
+}","function isGood(nums: number[]): boolean {
+
+};","(define/contract (is-good nums)
+ (-> (listof exact-integer?) boolean?)
+
+ )","-spec is_good(Nums :: [integer()]) -> boolean().
+is_good(Nums) ->
+ .","defmodule Solution do
+ @spec is_good(nums :: [integer]) :: boolean
+ def is_good(nums) do
+
+ end
+end","class Solution {
+ bool isGood(List nums) {
+
+ }
+}",
+16,number-of-black-blocks,Number of Black Blocks,2768.0,2889.0,"You are given two integers m
and n
representing the dimensions of a 0-indexed m x n
grid.
+
+You are also given a 0-indexed 2D integer matrix coordinates
, where coordinates[i] = [x, y]
indicates that the cell with coordinates [x, y]
is colored black. All cells in the grid that do not appear in coordinates
are white.
+
+A block is defined as a 2 x 2
submatrix of the grid. More formally, a block with cell [x, y]
as its top-left corner where 0 <= x < m - 1
and 0 <= y < n - 1
contains the coordinates [x, y]
, [x + 1, y]
, [x, y + 1]
, and [x + 1, y + 1]
.
+
+Return a 0-indexed integer array arr
of size 5
such that arr[i]
is the number of blocks that contains exactly i
black cells.
+
+
+Example 1:
+
+
+Input: m = 3, n = 3, coordinates = [[0,0]]
+Output: [3,1,0,0,0]
+Explanation: The grid looks like this:
+
+There is only 1 block with one black cell, and it is the block starting with cell [0,0].
+The other 3 blocks start with cells [0,1], [1,0] and [1,1]. They all have zero black cells.
+Thus, we return [3,1,0,0,0].
+
+
+Example 2:
+
+
+Input: m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]
+Output: [0,2,2,0,0]
+Explanation: The grid looks like this:
+
+There are 2 blocks with two black cells (the ones starting with cell coordinates [0,0] and [0,1]).
+The other 2 blocks have starting cell coordinates of [1,0] and [1,1]. They both have 1 black cell.
+Therefore, we return [0,2,2,0,0].
+
+
+
+Constraints:
+
+
+ 2 <= m <= 105
+ 2 <= n <= 105
+ 0 <= coordinates.length <= 104
+ coordinates[i].length == 2
+ 0 <= coordinates[i][0] < m
+ 0 <= coordinates[i][1] < n
+ - It is guaranteed that
coordinates
contains pairwise distinct coordinates.
+
+",2.0,False,"class Solution {
+public:
+ vector countBlackBlocks(int m, int n, vector>& coordinates) {
+
+ }
+};","class Solution {
+ public long[] countBlackBlocks(int m, int n, int[][] coordinates) {
+
+ }
+}","class Solution(object):
+ def countBlackBlocks(self, m, n, coordinates):
+ """"""
+ :type m: int
+ :type n: int
+ :type coordinates: List[List[int]]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def countBlackBlocks(self, m: int, n: int, coordinates: List[List[int]]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+long long* countBlackBlocks(int m, int n, int** coordinates, int coordinatesSize, int* coordinatesColSize, int* returnSize){
+
+}","public class Solution {
+ public long[] CountBlackBlocks(int m, int n, int[][] coordinates) {
+
+ }
+}","/**
+ * @param {number} m
+ * @param {number} n
+ * @param {number[][]} coordinates
+ * @return {number[]}
+ */
+var countBlackBlocks = function(m, n, coordinates) {
+
+};","# @param {Integer} m
+# @param {Integer} n
+# @param {Integer[][]} coordinates
+# @return {Integer[]}
+def count_black_blocks(m, n, coordinates)
+
+end","class Solution {
+ func countBlackBlocks(_ m: Int, _ n: Int, _ coordinates: [[Int]]) -> [Int] {
+
+ }
+}","func countBlackBlocks(m int, n int, coordinates [][]int) []int64 {
+
+}","object Solution {
+ def countBlackBlocks(m: Int, n: Int, coordinates: Array[Array[Int]]): Array[Long] = {
+
+ }
+}","class Solution {
+ fun countBlackBlocks(m: Int, n: Int, coordinates: Array): LongArray {
+
+ }
+}","impl Solution {
+ pub fn count_black_blocks(m: i32, n: i32, coordinates: Vec>) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $m
+ * @param Integer $n
+ * @param Integer[][] $coordinates
+ * @return Integer[]
+ */
+ function countBlackBlocks($m, $n, $coordinates) {
+
+ }
+}","function countBlackBlocks(m: number, n: number, coordinates: number[][]): number[] {
+
+};","(define/contract (count-black-blocks m n coordinates)
+ (-> exact-integer? exact-integer? (listof (listof exact-integer?)) (listof exact-integer?))
+
+ )","-spec count_black_blocks(M :: integer(), N :: integer(), Coordinates :: [[integer()]]) -> [integer()].
+count_black_blocks(M, N, Coordinates) ->
+ .","defmodule Solution do
+ @spec count_black_blocks(m :: integer, n :: integer, coordinates :: [[integer]]) :: [integer]
+ def count_black_blocks(m, n, coordinates) do
+
+ end
+end","class Solution {
+ List countBlackBlocks(int m, int n, List> coordinates) {
+
+ }
+}",
+18,sort-vowels-in-a-string,Sort Vowels in a String,2785.0,2887.0,"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 nondecreasing order of their ASCII values. More formally, for pairs of indices
i
, j
with 0 <= i < j < s.length
such that s[i]
and s[j]
are vowels, then t[i]
must not have a higher ASCII value than t[j]
.
+
+
+Return the resulting string.
+
+The vowels are 'a'
, 'e'
, 'i'
, 'o'
, and 'u'
, and they can appear in lowercase or uppercase. Consonants comprise all letters that are not vowels.
+
+
+Example 1:
+
+
+Input: s = "lEetcOde"
+Output: "lEOtcede"
+Explanation: 'E', 'O', and 'e' are the vowels in s; 'l', 't', 'c', and 'd' are all consonants. The vowels are sorted according to their ASCII values, and the consonants remain in the same places.
+
+
+Example 2:
+
+
+Input: s = "lYmpH"
+Output: "lYmpH"
+Explanation: There are no vowels in s (all characters in s are consonants), so we return "lYmpH".
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 105
+ s
consists only of letters of the English alphabet in uppercase and lowercase.
+
+",2.0,False,"class Solution {
+public:
+ string sortVowels(string s) {
+
+ }
+};","class Solution {
+ public String sortVowels(String s) {
+
+ }
+}","class Solution(object):
+ def sortVowels(self, s):
+ """"""
+ :type s: str
+ :rtype: str
+ """"""
+ ","class Solution:
+ def sortVowels(self, s: str) -> str:
+ ","char * sortVowels(char * s){
+
+}","public class Solution {
+ public string SortVowels(string s) {
+
+ }
+}","/**
+ * @param {string} s
+ * @return {string}
+ */
+var sortVowels = function(s) {
+
+};","# @param {String} s
+# @return {String}
+def sort_vowels(s)
+
+end","class Solution {
+ func sortVowels(_ s: String) -> String {
+
+ }
+}","func sortVowels(s string) string {
+
+}","object Solution {
+ def sortVowels(s: String): String = {
+
+ }
+}","class Solution {
+ fun sortVowels(s: String): String {
+
+ }
+}","impl Solution {
+ pub fn sort_vowels(s: String) -> String {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @return String
+ */
+ function sortVowels($s) {
+
+ }
+}","function sortVowels(s: string): string {
+
+};","(define/contract (sort-vowels s)
+ (-> string? string?)
+
+ )","-spec sort_vowels(S :: unicode:unicode_binary()) -> unicode:unicode_binary().
+sort_vowels(S) ->
+ .","defmodule Solution do
+ @spec sort_vowels(s :: String.t) :: String.t
+ def sort_vowels(s) do
+
+ end
+end","class Solution {
+ String sortVowels(String s) {
+
+ }
+}",
+20,length-of-the-longest-valid-substring,Length of the Longest Valid Substring,2781.0,2884.0,"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 characters in a string, possibly empty.
+
+
+Example 1:
+
+
+Input: word = "cbaaaabc", forbidden = ["aaa","cb"]
+Output: 4
+Explanation: There are 11 valid substrings in word: "c", "b", "a", "ba", "aa", "bc", "baa", "aab", "ab", "abc"and "aabc". The length of the longest valid substring is 4.
+It can be shown that all other substrings contain either "aaa" or "cb" as a substring.
+
+Example 2:
+
+
+Input: word = "leetcode", forbidden = ["de","le","e"]
+Output: 4
+Explanation: There are 11 valid substrings in word: "l", "t", "c", "o", "d", "tc", "co", "od", "tco", "cod", and "tcod". The length of the longest valid substring is 4.
+It can be shown that all other substrings contain either "de", "le", or "e" as a substring.
+
+
+
+Constraints:
+
+
+ 1 <= word.length <= 105
+ word
consists only of lowercase English letters.
+ 1 <= forbidden.length <= 105
+ 1 <= forbidden[i].length <= 10
+ forbidden[i]
consists only of lowercase English letters.
+
+",3.0,False,"class Solution {
+public:
+ int longestValidSubstring(string word, vector& forbidden) {
+
+ }
+};","class Solution {
+ public int longestValidSubstring(String word, List forbidden) {
+
+ }
+}","class Solution(object):
+ def longestValidSubstring(self, word, forbidden):
+ """"""
+ :type word: str
+ :type forbidden: List[str]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def longestValidSubstring(self, word: str, forbidden: List[str]) -> int:
+ ","int longestValidSubstring(char * word, char ** forbidden, int forbiddenSize){
+
+}","public class Solution {
+ public int LongestValidSubstring(string word, IList forbidden) {
+
+ }
+}","/**
+ * @param {string} word
+ * @param {string[]} forbidden
+ * @return {number}
+ */
+var longestValidSubstring = function(word, forbidden) {
+
+};","# @param {String} word
+# @param {String[]} forbidden
+# @return {Integer}
+def longest_valid_substring(word, forbidden)
+
+end","class Solution {
+ func longestValidSubstring(_ word: String, _ forbidden: [String]) -> Int {
+
+ }
+}","func longestValidSubstring(word string, forbidden []string) int {
+
+}","object Solution {
+ def longestValidSubstring(word: String, forbidden: List[String]): Int = {
+
+ }
+}","class Solution {
+ fun longestValidSubstring(word: String, forbidden: List): Int {
+
+ }
+}","impl Solution {
+ pub fn longest_valid_substring(word: String, forbidden: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $word
+ * @param String[] $forbidden
+ * @return Integer
+ */
+ function longestValidSubstring($word, $forbidden) {
+
+ }
+}","function longestValidSubstring(word: string, forbidden: string[]): number {
+
+};","(define/contract (longest-valid-substring word forbidden)
+ (-> string? (listof string?) exact-integer?)
+
+ )","-spec longest_valid_substring(Word :: unicode:unicode_binary(), Forbidden :: [unicode:unicode_binary()]) -> integer().
+longest_valid_substring(Word, Forbidden) ->
+ .","defmodule Solution do
+ @spec longest_valid_substring(word :: String.t, forbidden :: [String.t]) :: integer
+ def longest_valid_substring(word, forbidden) do
+
+ end
+end","class Solution {
+ int longestValidSubstring(String word, List forbidden) {
+
+ }
+}",
+22,ways-to-express-an-integer-as-sum-of-powers,Ways to Express an Integer as Sum of Powers,2787.0,2882.0,"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
.
+
+Since the result can be very large, return it modulo 109 + 7
.
+
+For example, if n = 160
and x = 3
, one way to express n
is n = 23 + 33 + 53
.
+
+
+Example 1:
+
+
+Input: n = 10, x = 2
+Output: 1
+Explanation: We can express n as the following: n = 32 + 12 = 10.
+It can be shown that it is the only way to express 10 as the sum of the 2nd power of unique integers.
+
+
+Example 2:
+
+
+Input: n = 4, x = 1
+Output: 2
+Explanation: We can express n in the following ways:
+- n = 41 = 4.
+- n = 31 + 11 = 4.
+
+
+
+Constraints:
+
+
+ 1 <= n <= 300
+ 1 <= x <= 5
+
+",2.0,False,"class Solution {
+public:
+ int numberOfWays(int n, int x) {
+
+ }
+};","class Solution {
+ public int numberOfWays(int n, int x) {
+
+ }
+}","class Solution(object):
+ def numberOfWays(self, n, x):
+ """"""
+ :type n: int
+ :type x: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def numberOfWays(self, n: int, x: int) -> int:
+ ","int numberOfWays(int n, int x){
+
+}","public class Solution {
+ public int NumberOfWays(int n, int x) {
+
+ }
+}","/**
+ * @param {number} n
+ * @param {number} x
+ * @return {number}
+ */
+var numberOfWays = function(n, x) {
+
+};","# @param {Integer} n
+# @param {Integer} x
+# @return {Integer}
+def number_of_ways(n, x)
+
+end","class Solution {
+ func numberOfWays(_ n: Int, _ x: Int) -> Int {
+
+ }
+}","func numberOfWays(n int, x int) int {
+
+}","object Solution {
+ def numberOfWays(n: Int, x: Int): Int = {
+
+ }
+}","class Solution {
+ fun numberOfWays(n: Int, x: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn number_of_ways(n: i32, x: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @param Integer $x
+ * @return Integer
+ */
+ function numberOfWays($n, $x) {
+
+ }
+}","function numberOfWays(n: number, x: number): number {
+
+};","(define/contract (number-of-ways n x)
+ (-> exact-integer? exact-integer? exact-integer?)
+
+ )","-spec number_of_ways(N :: integer(), X :: integer()) -> integer().
+number_of_ways(N, X) ->
+ .","defmodule Solution do
+ @spec number_of_ways(n :: integer, x :: integer) :: integer
+ def number_of_ways(n, x) do
+
+ end
+end","class Solution {
+ int numberOfWays(int n, int x) {
+
+ }
+}",
+23,split-strings-by-separator,Split Strings by Separator,2788.0,2881.0,"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 should occur, but it is not included as part of the resulting strings.
+ - A split may result in more than two strings.
+ - The resulting strings must maintain the same order as they were initially given.
+
+
+
+Example 1:
+
+
+Input: words = ["one.two.three","four.five","six"], separator = "."
+Output: ["one","two","three","four","five","six"]
+Explanation: In this example we split as follows:
+
+"one.two.three" splits into "one", "two", "three"
+"four.five" splits into "four", "five"
+"six" splits into "six"
+
+Hence, the resulting array is ["one","two","three","four","five","six"].
+
+Example 2:
+
+
+Input: words = ["$easy$","$problem$"], separator = "$"
+Output: ["easy","problem"]
+Explanation: In this example we split as follows:
+
+"$easy$" splits into "easy" (excluding empty strings)
+"$problem$" splits into "problem" (excluding empty strings)
+
+Hence, the resulting array is ["easy","problem"].
+
+
+Example 3:
+
+
+Input: words = ["|||"], separator = "|"
+Output: []
+Explanation: In this example the resulting split of "|||" will contain only empty strings, so we return an empty array [].
+
+
+Constraints:
+
+
+ 1 <= words.length <= 100
+ 1 <= words[i].length <= 20
+ - characters in
words[i]
are either lowercase English letters or characters from the string ".,|$#@"
(excluding the quotes)
+ separator
is a character from the string ".,|$#@"
(excluding the quotes)
+
+",1.0,False,"class Solution {
+public:
+ vector splitWordsBySeparator(vector& words, char separator) {
+
+ }
+};","class Solution {
+ public List splitWordsBySeparator(List words, char separator) {
+
+ }
+}","class Solution(object):
+ def splitWordsBySeparator(self, words, separator):
+ """"""
+ :type words: List[str]
+ :type separator: str
+ :rtype: List[str]
+ """"""
+ ","class Solution:
+ def splitWordsBySeparator(self, words: List[str], separator: str) -> List[str]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+char ** splitWordsBySeparator(char ** words, int wordsSize, char separator, int* returnSize){
+
+}","public class Solution {
+ public IList SplitWordsBySeparator(IList words, char separator) {
+
+ }
+}","/**
+ * @param {string[]} words
+ * @param {character} separator
+ * @return {string[]}
+ */
+var splitWordsBySeparator = function(words, separator) {
+
+};","# @param {String[]} words
+# @param {Character} separator
+# @return {String[]}
+def split_words_by_separator(words, separator)
+
+end","class Solution {
+ func splitWordsBySeparator(_ words: [String], _ separator: Character) -> [String] {
+
+ }
+}","func splitWordsBySeparator(words []string, separator byte) []string {
+
+}","object Solution {
+ def splitWordsBySeparator(words: List[String], separator: Char): List[String] = {
+
+ }
+}","class Solution {
+ fun splitWordsBySeparator(words: List, separator: Char): List {
+
+ }
+}","impl Solution {
+ pub fn split_words_by_separator(words: Vec, separator: char) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String[] $words
+ * @param String $separator
+ * @return String[]
+ */
+ function splitWordsBySeparator($words, $separator) {
+
+ }
+}","function splitWordsBySeparator(words: string[], separator: string): string[] {
+
+};","(define/contract (split-words-by-separator words separator)
+ (-> (listof string?) char? (listof string?))
+
+ )","-spec split_words_by_separator(Words :: [unicode:unicode_binary()], Separator :: char()) -> [unicode:unicode_binary()].
+split_words_by_separator(Words, Separator) ->
+ .","defmodule Solution do
+ @spec split_words_by_separator(words :: [String.t], separator :: char) :: [String.t]
+ def split_words_by_separator(words, separator) do
+
+ end
+end","class Solution {
+ List splitWordsBySeparator(List words, String separator) {
+
+ }
+}",
+24,apply-operations-to-make-all-array-elements-equal-to-zero,Apply Operations to Make All Array Elements Equal to Zero,2772.0,2878.0,"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
.
+
+
+Return true
if you can make all the array elements equal to 0
, or false
otherwise.
+
+A subarray is a contiguous non-empty part of an array.
+
+
+Example 1:
+
+
+Input: nums = [2,2,3,1,1,0], k = 3
+Output: true
+Explanation: We can do the following operations:
+- Choose the subarray [2,2,3]. The resulting array will be nums = [1,1,2,1,1,0].
+- Choose the subarray [2,1,1]. The resulting array will be nums = [1,1,1,0,0,0].
+- Choose the subarray [1,1,1]. The resulting array will be nums = [0,0,0,0,0,0].
+
+
+Example 2:
+
+
+Input: nums = [1,3,1,1], k = 2
+Output: false
+Explanation: It is not possible to make all the array elements equal to 0.
+
+
+
+Constraints:
+
+
+ 1 <= k <= nums.length <= 105
+ 0 <= nums[i] <= 106
+
+",2.0,False,"class Solution {
+public:
+ bool checkArray(vector& nums, int k) {
+
+ }
+};","class Solution {
+ public boolean checkArray(int[] nums, int k) {
+
+ }
+}","class Solution(object):
+ def checkArray(self, nums, k):
+ """"""
+ :type nums: List[int]
+ :type k: int
+ :rtype: bool
+ """"""
+ ","class Solution:
+ def checkArray(self, nums: List[int], k: int) -> bool:
+ ","bool checkArray(int* nums, int numsSize, int k){
+
+}","public class Solution {
+ public bool CheckArray(int[] nums, int k) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number} k
+ * @return {boolean}
+ */
+var checkArray = function(nums, k) {
+
+};","# @param {Integer[]} nums
+# @param {Integer} k
+# @return {Boolean}
+def check_array(nums, k)
+
+end","class Solution {
+ func checkArray(_ nums: [Int], _ k: Int) -> Bool {
+
+ }
+}","func checkArray(nums []int, k int) bool {
+
+}","object Solution {
+ def checkArray(nums: Array[Int], k: Int): Boolean = {
+
+ }
+}","class Solution {
+ fun checkArray(nums: IntArray, k: Int): Boolean {
+
+ }
+}","impl Solution {
+ pub fn check_array(nums: Vec, k: i32) -> bool {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer $k
+ * @return Boolean
+ */
+ function checkArray($nums, $k) {
+
+ }
+}","function checkArray(nums: number[], k: number): boolean {
+
+};","(define/contract (check-array nums k)
+ (-> (listof exact-integer?) exact-integer? boolean?)
+
+ )","-spec check_array(Nums :: [integer()], K :: integer()) -> boolean().
+check_array(Nums, K) ->
+ .","defmodule Solution do
+ @spec check_array(nums :: [integer], k :: integer) :: boolean
+ def check_array(nums, k) do
+
+ end
+end","class Solution {
+ bool checkArray(List nums, int k) {
+
+ }
+}",
+25,shortest-string-that-contains-three-strings,Shortest String That Contains Three Strings,2800.0,2877.0,"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 lexicographically smallest one.
+
+Return a string denoting the answer to the problem.
+
+Notes
+
+
+ - A string
a
is lexicographically smaller than a string b
(of the same length) if in the first position where a
and b
differ, string a
has a letter that appears earlier in the alphabet than the corresponding letter in b
.
+ - A substring is a contiguous sequence of characters within a string.
+
+
+
+Example 1:
+
+
+Input: a = "abc", b = "bca", c = "aaa"
+Output: "aaabca"
+Explanation: We show that "aaabca" contains all the given strings: a = ans[2...4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and "aaabca" is the lexicographically smallest one.
+
+Example 2:
+
+
+Input: a = "ab", b = "ba", c = "aba"
+Output: "aba"
+Explanation: We show that the string "aba" contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that "aba" is the lexicographically smallest one.
+
+
+
+Constraints:
+
+
+ 1 <= a.length, b.length, c.length <= 100
+ a
, b
, c
consist only of lowercase English letters.
+
+",2.0,False,"class Solution {
+public:
+ string minimumString(string a, string b, string c) {
+
+ }
+};","class Solution {
+ public String minimumString(String a, String b, String c) {
+
+ }
+}","class Solution(object):
+ def minimumString(self, a, b, c):
+ """"""
+ :type a: str
+ :type b: str
+ :type c: str
+ :rtype: str
+ """"""
+ ","class Solution:
+ def minimumString(self, a: str, b: str, c: str) -> str:
+ ","char * minimumString(char * a, char * b, char * c){
+
+}","public class Solution {
+ public string MinimumString(string a, string b, string c) {
+
+ }
+}","/**
+ * @param {string} a
+ * @param {string} b
+ * @param {string} c
+ * @return {string}
+ */
+var minimumString = function(a, b, c) {
+
+};","# @param {String} a
+# @param {String} b
+# @param {String} c
+# @return {String}
+def minimum_string(a, b, c)
+
+end","class Solution {
+ func minimumString(_ a: String, _ b: String, _ c: String) -> String {
+
+ }
+}","func minimumString(a string, b string, c string) string {
+
+}","object Solution {
+ def minimumString(a: String, b: String, c: String): String = {
+
+ }
+}","class Solution {
+ fun minimumString(a: String, b: String, c: String): String {
+
+ }
+}","impl Solution {
+ pub fn minimum_string(a: String, b: String, c: String) -> String {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $a
+ * @param String $b
+ * @param String $c
+ * @return String
+ */
+ function minimumString($a, $b, $c) {
+
+ }
+}","function minimumString(a: string, b: string, c: string): string {
+
+};","(define/contract (minimum-string a b c)
+ (-> string? string? string? string?)
+
+ )","-spec minimum_string(A :: unicode:unicode_binary(), B :: unicode:unicode_binary(), C :: unicode:unicode_binary()) -> unicode:unicode_binary().
+minimum_string(A, B, C) ->
+ .","defmodule Solution do
+ @spec minimum_string(a :: String.t, b :: String.t, c :: String.t) :: String.t
+ def minimum_string(a, b, c) do
+
+ end
+end","class Solution {
+ String minimumString(String a, String b, String c) {
+
+ }
+}",
+31,longest-non-decreasing-subarray-from-two-arrays,Longest Non-decreasing Subarray From Two Arrays,2771.0,2869.0,"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]
.
+
+Your task is to maximize the length of the longest non-decreasing subarray in nums3
by choosing its values optimally.
+
+Return an integer representing the length of the longest non-decreasing subarray in nums3
.
+
+Note: A subarray is a contiguous non-empty sequence of elements within an array.
+
+
+Example 1:
+
+
+Input: nums1 = [2,3,1], nums2 = [1,2,1]
+Output: 2
+Explanation: One way to construct nums3 is:
+nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1].
+The subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2.
+We can show that 2 is the maximum achievable length.
+
+Example 2:
+
+
+Input: nums1 = [1,3,2,1], nums2 = [2,2,3,4]
+Output: 4
+Explanation: One way to construct nums3 is:
+nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4].
+The entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.
+
+
+Example 3:
+
+
+Input: nums1 = [1,1], nums2 = [2,2]
+Output: 2
+Explanation: One way to construct nums3 is:
+nums3 = [nums1[0], nums1[1]] => [1,1].
+The entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.
+
+
+
+Constraints:
+
+
+ 1 <= nums1.length == nums2.length == n <= 105
+ 1 <= nums1[i], nums2[i] <= 109
+
+",2.0,False,"class Solution {
+public:
+ int maxNonDecreasingLength(vector& nums1, vector& nums2) {
+
+ }
+};","class Solution {
+ public int maxNonDecreasingLength(int[] nums1, int[] nums2) {
+
+ }
+}","class Solution(object):
+ def maxNonDecreasingLength(self, nums1, nums2):
+ """"""
+ :type nums1: List[int]
+ :type nums2: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:
+ ","int maxNonDecreasingLength(int* nums1, int nums1Size, int* nums2, int nums2Size){
+
+}","public class Solution {
+ public int MaxNonDecreasingLength(int[] nums1, int[] nums2) {
+
+ }
+}","/**
+ * @param {number[]} nums1
+ * @param {number[]} nums2
+ * @return {number}
+ */
+var maxNonDecreasingLength = function(nums1, nums2) {
+
+};","# @param {Integer[]} nums1
+# @param {Integer[]} nums2
+# @return {Integer}
+def max_non_decreasing_length(nums1, nums2)
+
+end","class Solution {
+ func maxNonDecreasingLength(_ nums1: [Int], _ nums2: [Int]) -> Int {
+
+ }
+}","func maxNonDecreasingLength(nums1 []int, nums2 []int) int {
+
+}","object Solution {
+ def maxNonDecreasingLength(nums1: Array[Int], nums2: Array[Int]): Int = {
+
+ }
+}","class Solution {
+ fun maxNonDecreasingLength(nums1: IntArray, nums2: IntArray): Int {
+
+ }
+}","impl Solution {
+ pub fn max_non_decreasing_length(nums1: Vec, nums2: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums1
+ * @param Integer[] $nums2
+ * @return Integer
+ */
+ function maxNonDecreasingLength($nums1, $nums2) {
+
+ }
+}","function maxNonDecreasingLength(nums1: number[], nums2: number[]): number {
+
+};","(define/contract (max-non-decreasing-length nums1 nums2)
+ (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)
+
+ )","-spec max_non_decreasing_length(Nums1 :: [integer()], Nums2 :: [integer()]) -> integer().
+max_non_decreasing_length(Nums1, Nums2) ->
+ .","defmodule Solution do
+ @spec max_non_decreasing_length(nums1 :: [integer], nums2 :: [integer]) :: integer
+ def max_non_decreasing_length(nums1, nums2) do
+
+ end
+end","class Solution {
+ int maxNonDecreasingLength(List nums1, List nums2) {
+
+ }
+}",
+32,continuous-subarrays,Continuous Subarrays,2762.0,2868.0,"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 subarrays.
+
+A subarray is a contiguous non-empty sequence of elements within an array.
+
+
+Example 1:
+
+
+Input: nums = [5,4,2,4]
+Output: 8
+Explanation:
+Continuous subarray of size 1: [5], [4], [2], [4].
+Continuous subarray of size 2: [5,4], [4,2], [2,4].
+Continuous subarray of size 3: [4,2,4].
+Thereare no subarrys of size 4.
+Total continuous subarrays = 4 + 3 + 1 = 8.
+It can be shown that there are no more continuous subarrays.
+
+
+
+
+Example 2:
+
+
+Input: nums = [1,2,3]
+Output: 6
+Explanation:
+Continuous subarray of size 1: [1], [2], [3].
+Continuous subarray of size 2: [1,2], [2,3].
+Continuous subarray of size 3: [1,2,3].
+Total continuous subarrays = 3 + 2 + 1 = 6.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ 1 <= nums[i] <= 109
+
+",2.0,False,"class Solution {
+public:
+ long long continuousSubarrays(vector& nums) {
+
+ }
+};","class Solution {
+ public long continuousSubarrays(int[] nums) {
+
+ }
+}","class Solution(object):
+ def continuousSubarrays(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def continuousSubarrays(self, nums: List[int]) -> int:
+ ","long long continuousSubarrays(int* nums, int numsSize){
+
+}","public class Solution {
+ public long ContinuousSubarrays(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var continuousSubarrays = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def continuous_subarrays(nums)
+
+end","class Solution {
+ func continuousSubarrays(_ nums: [Int]) -> Int {
+
+ }
+}","func continuousSubarrays(nums []int) int64 {
+
+}","object Solution {
+ def continuousSubarrays(nums: Array[Int]): Long = {
+
+ }
+}","class Solution {
+ fun continuousSubarrays(nums: IntArray): Long {
+
+ }
+}","impl Solution {
+ pub fn continuous_subarrays(nums: Vec) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function continuousSubarrays($nums) {
+
+ }
+}","function continuousSubarrays(nums: number[]): number {
+
+};","(define/contract (continuous-subarrays nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec continuous_subarrays(Nums :: [integer()]) -> integer().
+continuous_subarrays(Nums) ->
+ .","defmodule Solution do
+ @spec continuous_subarrays(nums :: [integer]) :: integer
+ def continuous_subarrays(nums) do
+
+ end
+end","class Solution {
+ int continuousSubarrays(List nums) {
+
+ }
+}",
+33,ways-to-split-array-into-good-subarrays,Ways to Split Array Into Good Subarrays,2750.0,2867.0,"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, return it modulo 109 + 7
.
+
+A subarray is a contiguous non-empty sequence of elements within an array.
+
+
+Example 1:
+
+
+Input: nums = [0,1,0,0,1]
+Output: 3
+Explanation: There are 3 ways to split nums into good subarrays:
+- [0,1] [0,0,1]
+- [0,1,0] [0,1]
+- [0,1,0,0] [1]
+
+
+Example 2:
+
+
+Input: nums = [0,1,0]
+Output: 1
+Explanation: There is 1 way to split nums into good subarrays:
+- [0,1,0]
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ 0 <= nums[i] <= 1
+
+",2.0,False,"class Solution {
+public:
+ int numberOfGoodSubarraySplits(vector& nums) {
+
+ }
+};","class Solution {
+ public int numberOfGoodSubarraySplits(int[] nums) {
+
+ }
+}","class Solution(object):
+ def numberOfGoodSubarraySplits(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def numberOfGoodSubarraySplits(self, nums: List[int]) -> int:
+ ","int numberOfGoodSubarraySplits(int* nums, int numsSize){
+
+}","public class Solution {
+ public int NumberOfGoodSubarraySplits(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var numberOfGoodSubarraySplits = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def number_of_good_subarray_splits(nums)
+
+end","class Solution {
+ func numberOfGoodSubarraySplits(_ nums: [Int]) -> Int {
+
+ }
+}","func numberOfGoodSubarraySplits(nums []int) int {
+
+}","object Solution {
+ def numberOfGoodSubarraySplits(nums: Array[Int]): Int = {
+
+ }
+}","class Solution {
+ fun numberOfGoodSubarraySplits(nums: IntArray): Int {
+
+ }
+}","impl Solution {
+ pub fn number_of_good_subarray_splits(nums: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function numberOfGoodSubarraySplits($nums) {
+
+ }
+}","function numberOfGoodSubarraySplits(nums: number[]): number {
+
+};","(define/contract (number-of-good-subarray-splits nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec number_of_good_subarray_splits(Nums :: [integer()]) -> integer().
+number_of_good_subarray_splits(Nums) ->
+ .","defmodule Solution do
+ @spec number_of_good_subarray_splits(nums :: [integer]) :: integer
+ def number_of_good_subarray_splits(nums) do
+
+ end
+end","class Solution {
+ int numberOfGoodSubarraySplits(List nums) {
+
+ }
+}",
+36,count-complete-subarrays-in-an-array,Count Complete Subarrays in an Array,2799.0,2856.0,"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.
+
+
+Return the number of complete subarrays.
+
+A subarray is a contiguous non-empty part of an array.
+
+
+Example 1:
+
+
+Input: nums = [1,3,1,2,2]
+Output: 4
+Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].
+
+
+Example 2:
+
+
+Input: nums = [5,5,5,5]
+Output: 10
+Explanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 1000
+ 1 <= nums[i] <= 2000
+
+",2.0,False,"class Solution {
+public:
+ int countCompleteSubarrays(vector& nums) {
+
+ }
+};","class Solution {
+ public int countCompleteSubarrays(int[] nums) {
+
+ }
+}","class Solution(object):
+ def countCompleteSubarrays(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def countCompleteSubarrays(self, nums: List[int]) -> int:
+ ","int countCompleteSubarrays(int* nums, int numsSize){
+
+}","public class Solution {
+ public int CountCompleteSubarrays(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var countCompleteSubarrays = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def count_complete_subarrays(nums)
+
+end","class Solution {
+ func countCompleteSubarrays(_ nums: [Int]) -> Int {
+
+ }
+}","func countCompleteSubarrays(nums []int) int {
+
+}","object Solution {
+ def countCompleteSubarrays(nums: Array[Int]): Int = {
+
+ }
+}","class Solution {
+ fun countCompleteSubarrays(nums: IntArray): Int {
+
+ }
+}","impl Solution {
+ pub fn count_complete_subarrays(nums: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function countCompleteSubarrays($nums) {
+
+ }
+}","function countCompleteSubarrays(nums: number[]): number {
+
+};","(define/contract (count-complete-subarrays nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec count_complete_subarrays(Nums :: [integer()]) -> integer().
+count_complete_subarrays(Nums) ->
+ .","defmodule Solution do
+ @spec count_complete_subarrays(nums :: [integer]) :: integer
+ def count_complete_subarrays(nums) do
+
+ end
+end","class Solution {
+ int countCompleteSubarrays(List nums) {
+
+ }
+}",
+37,maximum-number-of-jumps-to-reach-the-last-index,Maximum Number of Jumps to Reach the Last Index,2770.0,2855.0,"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
+
+
+Return the maximum number of jumps you can make to reach index n - 1
.
+
+If there is no way to reach index n - 1
, return -1
.
+
+
+Example 1:
+
+
+Input: nums = [1,3,6,4,1,2], target = 2
+Output: 3
+Explanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
+- Jump from index 0 to index 1.
+- Jump from index 1 to index 3.
+- Jump from index 3 to index 5.
+It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 3 jumps. Hence, the answer is 3.
+
+Example 2:
+
+
+Input: nums = [1,3,6,4,1,2], target = 3
+Output: 5
+Explanation: To go from index 0 to index n - 1 with the maximum number of jumps, you can perform the following jumping sequence:
+- Jump from index 0 to index 1.
+- Jump from index 1 to index 2.
+- Jump from index 2 to index 3.
+- Jump from index 3 to index 4.
+- Jump from index 4 to index 5.
+It can be proven that there is no other jumping sequence that goes from 0 to n - 1 with more than 5 jumps. Hence, the answer is 5.
+
+Example 3:
+
+
+Input: nums = [1,3,6,4,1,2], target = 0
+Output: -1
+Explanation: It can be proven that there is no jumping sequence that goes from 0 to n - 1. Hence, the answer is -1.
+
+
+
+Constraints:
+
+
+ 2 <= nums.length == n <= 1000
+ -109 <= nums[i] <= 109
+ 0 <= target <= 2 * 109
+
+",2.0,False,"class Solution {
+public:
+ int maximumJumps(vector& nums, int target) {
+
+ }
+};","class Solution {
+ public int maximumJumps(int[] nums, int target) {
+
+ }
+}","class Solution(object):
+ def maximumJumps(self, nums, target):
+ """"""
+ :type nums: List[int]
+ :type target: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maximumJumps(self, nums: List[int], target: int) -> int:
+ ","int maximumJumps(int* nums, int numsSize, int target){
+
+}","public class Solution {
+ public int MaximumJumps(int[] nums, int target) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number} target
+ * @return {number}
+ */
+var maximumJumps = function(nums, target) {
+
+};","# @param {Integer[]} nums
+# @param {Integer} target
+# @return {Integer}
+def maximum_jumps(nums, target)
+
+end","class Solution {
+ func maximumJumps(_ nums: [Int], _ target: Int) -> Int {
+
+ }
+}","func maximumJumps(nums []int, target int) int {
+
+}","object Solution {
+ def maximumJumps(nums: Array[Int], target: Int): Int = {
+
+ }
+}","class Solution {
+ fun maximumJumps(nums: IntArray, target: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn maximum_jumps(nums: Vec, target: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer $target
+ * @return Integer
+ */
+ function maximumJumps($nums, $target) {
+
+ }
+}","function maximumJumps(nums: number[], target: number): number {
+
+};","(define/contract (maximum-jumps nums target)
+ (-> (listof exact-integer?) exact-integer? exact-integer?)
+
+ )","-spec maximum_jumps(Nums :: [integer()], Target :: integer()) -> integer().
+maximum_jumps(Nums, Target) ->
+ .","defmodule Solution do
+ @spec maximum_jumps(nums :: [integer], target :: integer) :: integer
+ def maximum_jumps(nums, target) do
+
+ end
+end","class Solution {
+ int maximumJumps(List nums, int target) {
+
+ }
+}",
+40,sum-of-imbalance-numbers-of-all-subarrays,Sum of Imbalance Numbers of All Subarrays,2763.0,2849.0,"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 arr
.
+
+Given a 0-indexed integer array nums
, return the sum of imbalance numbers of all its subarrays.
+
+A subarray is a contiguous non-empty sequence of elements within an array.
+
+
+Example 1:
+
+
+Input: nums = [2,3,1,4]
+Output: 3
+Explanation: There are 3 subarrays with non-zero imbalance numbers:
+- Subarray [3, 1] with an imbalance number of 1.
+- Subarray [3, 1, 4] with an imbalance number of 1.
+- Subarray [1, 4] with an imbalance number of 1.
+The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 3.
+
+
+Example 2:
+
+
+Input: nums = [1,3,3,3,5]
+Output: 8
+Explanation: There are 7 subarrays with non-zero imbalance numbers:
+- Subarray [1, 3] with an imbalance number of 1.
+- Subarray [1, 3, 3] with an imbalance number of 1.
+- Subarray [1, 3, 3, 3] with an imbalance number of 1.
+- Subarray [1, 3, 3, 3, 5] with an imbalance number of 2.
+- Subarray [3, 3, 3, 5] with an imbalance number of 1.
+- Subarray [3, 3, 5] with an imbalance number of 1.
+- Subarray [3, 5] with an imbalance number of 1.
+The imbalance number of all other subarrays is 0. Hence, the sum of imbalance numbers of all the subarrays of nums is 8.
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 1000
+ 1 <= nums[i] <= nums.length
+
+",3.0,False,"class Solution {
+public:
+ int sumImbalanceNumbers(vector& nums) {
+
+ }
+};","class Solution {
+ public int sumImbalanceNumbers(int[] nums) {
+
+ }
+}","class Solution(object):
+ def sumImbalanceNumbers(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def sumImbalanceNumbers(self, nums: List[int]) -> int:
+ ","int sumImbalanceNumbers(int* nums, int numsSize){
+
+}","public class Solution {
+ public int SumImbalanceNumbers(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var sumImbalanceNumbers = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def sum_imbalance_numbers(nums)
+
+end","class Solution {
+ func sumImbalanceNumbers(_ nums: [Int]) -> Int {
+
+ }
+}","func sumImbalanceNumbers(nums []int) int {
+
+}","object Solution {
+ def sumImbalanceNumbers(nums: Array[Int]): Int = {
+
+ }
+}","class Solution {
+ fun sumImbalanceNumbers(nums: IntArray): Int {
+
+ }
+}","impl Solution {
+ pub fn sum_imbalance_numbers(nums: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function sumImbalanceNumbers($nums) {
+
+ }
+}","function sumImbalanceNumbers(nums: number[]): number {
+
+};","(define/contract (sum-imbalance-numbers nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec sum_imbalance_numbers(Nums :: [integer()]) -> integer().
+sum_imbalance_numbers(Nums) ->
+ .","defmodule Solution do
+ @spec sum_imbalance_numbers(nums :: [integer]) :: integer
+ def sum_imbalance_numbers(nums) do
+
+ end
+end","class Solution {
+ int sumImbalanceNumbers(List nums) {
+
+ }
+}",
+42,find-maximum-number-of-string-pairs,Find Maximum Number of String Pairs,2744.0,2847.0,"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 number of pairs that can be formed from the array words
.
+
+Note that each string can belong in at most one pair.
+
+
+Example 1:
+
+
+Input: words = ["cd","ac","dc","ca","zz"]
+Output: 2
+Explanation: In this example, we can form 2 pair of strings in the following way:
+- We pair the 0th string with the 2nd string, as the reversed string of word[0] is "dc" and is equal to words[2].
+- We pair the 1st string with the 3rd string, as the reversed string of word[1] is "ca" and is equal to words[3].
+It can be proven that 2 is the maximum number of pairs that can be formed.
+
+Example 2:
+
+
+Input: words = ["ab","ba","cc"]
+Output: 1
+Explanation: In this example, we can form 1 pair of strings in the following way:
+- We pair the 0th string with the 1st string, as the reversed string of words[1] is "ab" and is equal to words[0].
+It can be proven that 1 is the maximum number of pairs that can be formed.
+
+
+Example 3:
+
+
+Input: words = ["aa","ab"]
+Output: 0
+Explanation: In this example, we are unable to form any pair of strings.
+
+
+
+Constraints:
+
+
+ 1 <= words.length <= 50
+ words[i].length == 2
+ words
consists of distinct strings.
+ words[i]
contains only lowercase English letters.
+
+",1.0,False,"class Solution {
+public:
+ int maximumNumberOfStringPairs(vector& words) {
+
+ }
+};","class Solution {
+ public int maximumNumberOfStringPairs(String[] words) {
+
+ }
+}","class Solution(object):
+ def maximumNumberOfStringPairs(self, words):
+ """"""
+ :type words: List[str]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maximumNumberOfStringPairs(self, words: List[str]) -> int:
+ ","int maximumNumberOfStringPairs(char ** words, int wordsSize){
+
+}","public class Solution {
+ public int MaximumNumberOfStringPairs(string[] words) {
+
+ }
+}","/**
+ * @param {string[]} words
+ * @return {number}
+ */
+var maximumNumberOfStringPairs = function(words) {
+
+};","# @param {String[]} words
+# @return {Integer}
+def maximum_number_of_string_pairs(words)
+
+end","class Solution {
+ func maximumNumberOfStringPairs(_ words: [String]) -> Int {
+
+ }
+}","func maximumNumberOfStringPairs(words []string) int {
+
+}","object Solution {
+ def maximumNumberOfStringPairs(words: Array[String]): Int = {
+
+ }
+}","class Solution {
+ fun maximumNumberOfStringPairs(words: Array): Int {
+
+ }
+}","impl Solution {
+ pub fn maximum_number_of_string_pairs(words: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String[] $words
+ * @return Integer
+ */
+ function maximumNumberOfStringPairs($words) {
+
+ }
+}","function maximumNumberOfStringPairs(words: string[]): number {
+
+};","(define/contract (maximum-number-of-string-pairs words)
+ (-> (listof string?) exact-integer?)
+
+ )","-spec maximum_number_of_string_pairs(Words :: [unicode:unicode_binary()]) -> integer().
+maximum_number_of_string_pairs(Words) ->
+ .","defmodule Solution do
+ @spec maximum_number_of_string_pairs(words :: [String.t]) :: integer
+ def maximum_number_of_string_pairs(words) do
+
+ end
+end","class Solution {
+ int maximumNumberOfStringPairs(List words) {
+
+ }
+}",
+43,robot-collisions,Robot Collisions,2751.0,2846.0,"There are n
1-indexed robots, each having a position on a line, health, and movement direction.
+
+You are given 0-indexed integer arrays positions
, healths
, and a string directions
(directions[i]
is either 'L' for left or 'R' for right). All integers in positions
are unique.
+
+All robots start moving on the line simultaneously at the same speed in their given directions. If two robots ever share the same position while moving, they will collide.
+
+If two robots collide, the robot with lower health is removed from the line, and the health of the other robot decreases by one. The surviving robot continues in the same direction it was going. If both robots have the same health, they are both removed from the line.
+
+Your task is to determine the health of the robots that survive the collisions, in the same order that the robots were given, i.e. final heath of robot 1 (if survived), final health of robot 2 (if survived), and so on. If there are no survivors, return an empty array.
+
+Return an array containing the health of the remaining robots (in the order they were given in the input), after no further collisions can occur.
+
+Note: The positions may be unsorted.
+
+
+
+
+Example 1:
+
+
+
+
+Input: positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = "RRRRR"
+Output: [2,17,9,15,10]
+Explanation: No collision occurs in this example, since all robots are moving in the same direction. So, the health of the robots in order from the first robot is returned, [2, 17, 9, 15, 10].
+
+
+Example 2:
+
+
+
+
+Input: positions = [3,5,2,6], healths = [10,10,15,12], directions = "RLRL"
+Output: [14]
+Explanation: There are 2 collisions in this example. Firstly, robot 1 and robot 2 will collide, and since both have the same health, they will be removed from the line. Next, robot 3 and robot 4 will collide and since robot 4's health is smaller, it gets removed, and robot 3's health becomes 15 - 1 = 14. Only robot 3 remains, so we return [14].
+
+
+Example 3:
+
+
+
+
+Input: positions = [1,2,5,6], healths = [10,10,11,11], directions = "RLRL"
+Output: []
+Explanation: Robot 1 and robot 2 will collide and since both have the same health, they are both removed. Robot 3 and 4 will collide and since both have the same health, they are both removed. So, we return an empty array, [].
+
+
+Constraints:
+
+
+ 1 <= positions.length == healths.length == directions.length == n <= 105
+ 1 <= positions[i], healths[i] <= 109
+ directions[i] == 'L'
or directions[i] == 'R'
+ - All values in
positions
are distinct
+
+",3.0,False,"class Solution {
+public:
+ vector survivedRobotsHealths(vector& positions, vector& healths, string directions) {
+
+ }
+};","class Solution {
+ public List survivedRobotsHealths(int[] positions, int[] healths, String directions) {
+
+ }
+}","class Solution(object):
+ def survivedRobotsHealths(self, positions, healths, directions):
+ """"""
+ :type positions: List[int]
+ :type healths: List[int]
+ :type directions: str
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def survivedRobotsHealths(self, positions: List[int], healths: List[int], directions: str) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* survivedRobotsHealths(int* positions, int positionsSize, int* healths, int healthsSize, char * directions, int* returnSize){
+
+}","public class Solution {
+ public IList SurvivedRobotsHealths(int[] positions, int[] healths, string directions) {
+
+ }
+}","/**
+ * @param {number[]} positions
+ * @param {number[]} healths
+ * @param {string} directions
+ * @return {number[]}
+ */
+var survivedRobotsHealths = function(positions, healths, directions) {
+
+};","# @param {Integer[]} positions
+# @param {Integer[]} healths
+# @param {String} directions
+# @return {Integer[]}
+def survived_robots_healths(positions, healths, directions)
+
+end","class Solution {
+ func survivedRobotsHealths(_ positions: [Int], _ healths: [Int], _ directions: String) -> [Int] {
+
+ }
+}","func survivedRobotsHealths(positions []int, healths []int, directions string) []int {
+
+}","object Solution {
+ def survivedRobotsHealths(positions: Array[Int], healths: Array[Int], directions: String): List[Int] = {
+
+ }
+}","class Solution {
+ fun survivedRobotsHealths(positions: IntArray, healths: IntArray, directions: String): List {
+
+ }
+}","impl Solution {
+ pub fn survived_robots_healths(positions: Vec, healths: Vec, directions: String) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $positions
+ * @param Integer[] $healths
+ * @param String $directions
+ * @return Integer[]
+ */
+ function survivedRobotsHealths($positions, $healths, $directions) {
+
+ }
+}","function survivedRobotsHealths(positions: number[], healths: number[], directions: string): number[] {
+
+};","(define/contract (survived-robots-healths positions healths directions)
+ (-> (listof exact-integer?) (listof exact-integer?) string? (listof exact-integer?))
+
+ )","-spec survived_robots_healths(Positions :: [integer()], Healths :: [integer()], Directions :: unicode:unicode_binary()) -> [integer()].
+survived_robots_healths(Positions, Healths, Directions) ->
+ .","defmodule Solution do
+ @spec survived_robots_healths(positions :: [integer], healths :: [integer], directions :: String.t) :: [integer]
+ def survived_robots_healths(positions, healths, directions) do
+
+ end
+end","class Solution {
+ List survivedRobotsHealths(List positions, List healths, String directions) {
+
+ }
+}",
+46,maximum-sum-queries,Maximum Sum Queries,2736.0,2839.0,"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 nums2[j] >= yi
, or -1 if there is no j
satisfying the constraints.
+
+Return an array answer
where answer[i]
is the answer to the ith
query.
+
+
+Example 1:
+
+
+Input: nums1 = [4,3,1,2], nums2 = [2,4,9,5], queries = [[4,1],[1,3],[2,5]]
+Output: [6,10,7]
+Explanation:
+For the 1st query xi = 4
and yi = 1
, we can select index j = 0
since nums1[j] >= 4
and nums2[j] >= 1
. The sum nums1[j] + nums2[j]
is 6, and we can show that 6 is the maximum we can obtain.
+
+For the 2nd query xi = 1
and yi = 3
, we can select index j = 2
since nums1[j] >= 1
and nums2[j] >= 3
. The sum nums1[j] + nums2[j]
is 10, and we can show that 10 is the maximum we can obtain.
+
+For the 3rd query xi = 2
and yi = 5
, we can select index j = 3
since nums1[j] >= 2
and nums2[j] >= 5
. The sum nums1[j] + nums2[j]
is 7, and we can show that 7 is the maximum we can obtain.
+
+Therefore, we return [6,10,7]
.
+
+
+Example 2:
+
+
+Input: nums1 = [3,2,5], nums2 = [2,3,4], queries = [[4,4],[3,2],[1,1]]
+Output: [9,9,9]
+Explanation: For this example, we can use index j = 2
for all the queries since it satisfies the constraints for each query.
+
+
+Example 3:
+
+
+Input: nums1 = [2,1], nums2 = [2,3], queries = [[3,3]]
+Output: [-1]
+Explanation: There is one query in this example with xi
= 3 and yi
= 3. For every index, j, either nums1[j] < xi
or nums2[j] < yi
. Hence, there is no solution.
+
+
+
+Constraints:
+
+
+ nums1.length == nums2.length
+ n == nums1.length
+ 1 <= n <= 105
+ 1 <= nums1[i], nums2[i] <= 109
+ 1 <= queries.length <= 105
+ queries[i].length == 2
+ xi == queries[i][1]
+ yi == queries[i][2]
+ 1 <= xi, yi <= 109
+
+",3.0,False,"class Solution {
+public:
+ vector maximumSumQueries(vector& nums1, vector& nums2, vector>& queries) {
+
+ }
+};","class Solution {
+ public int[] maximumSumQueries(int[] nums1, int[] nums2, int[][] queries) {
+
+ }
+}","class Solution(object):
+ def maximumSumQueries(self, nums1, nums2, queries):
+ """"""
+ :type nums1: List[int]
+ :type nums2: List[int]
+ :type queries: List[List[int]]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def maximumSumQueries(self, nums1: List[int], nums2: List[int], queries: List[List[int]]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* maximumSumQueries(int* nums1, int nums1Size, int* nums2, int nums2Size, int** queries, int queriesSize, int* queriesColSize, int* returnSize){
+
+}","public class Solution {
+ public int[] MaximumSumQueries(int[] nums1, int[] nums2, int[][] queries) {
+
+ }
+}","/**
+ * @param {number[]} nums1
+ * @param {number[]} nums2
+ * @param {number[][]} queries
+ * @return {number[]}
+ */
+var maximumSumQueries = function(nums1, nums2, queries) {
+
+};","# @param {Integer[]} nums1
+# @param {Integer[]} nums2
+# @param {Integer[][]} queries
+# @return {Integer[]}
+def maximum_sum_queries(nums1, nums2, queries)
+
+end","class Solution {
+ func maximumSumQueries(_ nums1: [Int], _ nums2: [Int], _ queries: [[Int]]) -> [Int] {
+
+ }
+}","func maximumSumQueries(nums1 []int, nums2 []int, queries [][]int) []int {
+
+}","object Solution {
+ def maximumSumQueries(nums1: Array[Int], nums2: Array[Int], queries: Array[Array[Int]]): Array[Int] = {
+
+ }
+}","class Solution {
+ fun maximumSumQueries(nums1: IntArray, nums2: IntArray, queries: Array): IntArray {
+
+ }
+}","impl Solution {
+ pub fn maximum_sum_queries(nums1: Vec, nums2: Vec, queries: Vec>) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums1
+ * @param Integer[] $nums2
+ * @param Integer[][] $queries
+ * @return Integer[]
+ */
+ function maximumSumQueries($nums1, $nums2, $queries) {
+
+ }
+}","function maximumSumQueries(nums1: number[], nums2: number[], queries: number[][]): number[] {
+
+};","(define/contract (maximum-sum-queries nums1 nums2 queries)
+ (-> (listof exact-integer?) (listof exact-integer?) (listof (listof exact-integer?)) (listof exact-integer?))
+
+ )","-spec maximum_sum_queries(Nums1 :: [integer()], Nums2 :: [integer()], Queries :: [[integer()]]) -> [integer()].
+maximum_sum_queries(Nums1, Nums2, Queries) ->
+ .","defmodule Solution do
+ @spec maximum_sum_queries(nums1 :: [integer], nums2 :: [integer], queries :: [[integer]]) :: [integer]
+ def maximum_sum_queries(nums1, nums2, queries) do
+
+ end
+end","class Solution {
+ List maximumSumQueries(List nums1, List nums2, List> queries) {
+
+ }
+}",
+48,minimum-operations-to-make-the-integer-zero,Minimum Operations to Make the Integer Zero,2749.0,2837.0,"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 impossible to make num1
equal to 0
, return -1
.
+
+
+Example 1:
+
+
+Input: num1 = 3, num2 = -2
+Output: 3
+Explanation: We can make 3 equal to 0 with the following operations:
+- We choose i = 2 and substract 22 + (-2) from 3, 3 - (4 + (-2)) = 1.
+- We choose i = 2 and substract 22 + (-2) from 1, 1 - (4 + (-2)) = -1.
+- We choose i = 0 and substract 20 + (-2) from -1, (-1) - (1 + (-2)) = 0.
+It can be proven, that 3 is the minimum number of operations that we need to perform.
+
+
+Example 2:
+
+
+Input: num1 = 5, num2 = 7
+Output: -1
+Explanation: It can be proven, that it is impossible to make 5 equal to 0 with the given operation.
+
+
+
+Constraints:
+
+
+ 1 <= num1 <= 109
+ -109 <= num2 <= 109
+
+",2.0,False,"class Solution {
+public:
+ int makeTheIntegerZero(int num1, int num2) {
+
+ }
+};","class Solution {
+ public int makeTheIntegerZero(int num1, int num2) {
+
+ }
+}","class Solution(object):
+ def makeTheIntegerZero(self, num1, num2):
+ """"""
+ :type num1: int
+ :type num2: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def makeTheIntegerZero(self, num1: int, num2: int) -> int:
+ ","int makeTheIntegerZero(int num1, int num2){
+
+}","public class Solution {
+ public int MakeTheIntegerZero(int num1, int num2) {
+
+ }
+}","/**
+ * @param {number} num1
+ * @param {number} num2
+ * @return {number}
+ */
+var makeTheIntegerZero = function(num1, num2) {
+
+};","# @param {Integer} num1
+# @param {Integer} num2
+# @return {Integer}
+def make_the_integer_zero(num1, num2)
+
+end","class Solution {
+ func makeTheIntegerZero(_ num1: Int, _ num2: Int) -> Int {
+
+ }
+}","func makeTheIntegerZero(num1 int, num2 int) int {
+
+}","object Solution {
+ def makeTheIntegerZero(num1: Int, num2: Int): Int = {
+
+ }
+}","class Solution {
+ fun makeTheIntegerZero(num1: Int, num2: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn make_the_integer_zero(num1: i32, num2: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $num1
+ * @param Integer $num2
+ * @return Integer
+ */
+ function makeTheIntegerZero($num1, $num2) {
+
+ }
+}","function makeTheIntegerZero(num1: number, num2: number): number {
+
+};","(define/contract (make-the-integer-zero num1 num2)
+ (-> exact-integer? exact-integer? exact-integer?)
+
+ )","-spec make_the_integer_zero(Num1 :: integer(), Num2 :: integer()) -> integer().
+make_the_integer_zero(Num1, Num2) ->
+ .","defmodule Solution do
+ @spec make_the_integer_zero(num1 :: integer, num2 :: integer) :: integer
+ def make_the_integer_zero(num1, num2) do
+
+ end
+end","class Solution {
+ int makeTheIntegerZero(int num1, int num2) {
+
+ }
+}",
+50,relocate-marbles,Relocate Marbles,2766.0,2834.0,"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
step, you will move all marbles at position moveFrom[i]
to position moveTo[i]
.
+
+After completing all the steps, return the sorted list of occupied positions.
+
+Notes:
+
+
+ - We call a position occupied if there is at least one marble in that position.
+ - There may be multiple marbles in a single position.
+
+
+
+Example 1:
+
+
+Input: nums = [1,6,7,8], moveFrom = [1,7,2], moveTo = [2,9,5]
+Output: [5,6,8,9]
+Explanation: Initially, the marbles are at positions 1,6,7,8.
+At the i = 0th step, we move the marbles at position 1 to position 2. Then, positions 2,6,7,8 are occupied.
+At the i = 1st step, we move the marbles at position 7 to position 9. Then, positions 2,6,8,9 are occupied.
+At the i = 2nd step, we move the marbles at position 2 to position 5. Then, positions 5,6,8,9 are occupied.
+At the end, the final positions containing at least one marbles are [5,6,8,9].
+
+Example 2:
+
+
+Input: nums = [1,1,3,3], moveFrom = [1,3], moveTo = [2,2]
+Output: [2]
+Explanation: Initially, the marbles are at positions [1,1,3,3].
+At the i = 0th step, we move all the marbles at position 1 to position 2. Then, the marbles are at positions [2,2,3,3].
+At the i = 1st step, we move all the marbles at position 3 to position 2. Then, the marbles are at positions [2,2,2,2].
+Since 2 is the only occupied position, we return [2].
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ 1 <= moveFrom.length <= 105
+ moveFrom.length == moveTo.length
+ 1 <= nums[i], moveFrom[i], moveTo[i] <= 109
+ - The test cases are generated such that there is at least a marble in
moveFrom[i]
at the moment we want to apply the ith
move.
+
+",2.0,False,"class Solution {
+public:
+ vector relocateMarbles(vector& nums, vector& moveFrom, vector& moveTo) {
+
+ }
+};","class Solution {
+ public List relocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) {
+
+ }
+}","class Solution(object):
+ def relocateMarbles(self, nums, moveFrom, moveTo):
+ """"""
+ :type nums: List[int]
+ :type moveFrom: List[int]
+ :type moveTo: List[int]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def relocateMarbles(self, nums: List[int], moveFrom: List[int], moveTo: List[int]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* relocateMarbles(int* nums, int numsSize, int* moveFrom, int moveFromSize, int* moveTo, int moveToSize, int* returnSize){
+
+}","public class Solution {
+ public IList RelocateMarbles(int[] nums, int[] moveFrom, int[] moveTo) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number[]} moveFrom
+ * @param {number[]} moveTo
+ * @return {number[]}
+ */
+var relocateMarbles = function(nums, moveFrom, moveTo) {
+
+};","# @param {Integer[]} nums
+# @param {Integer[]} move_from
+# @param {Integer[]} move_to
+# @return {Integer[]}
+def relocate_marbles(nums, move_from, move_to)
+
+end","class Solution {
+ func relocateMarbles(_ nums: [Int], _ moveFrom: [Int], _ moveTo: [Int]) -> [Int] {
+
+ }
+}","func relocateMarbles(nums []int, moveFrom []int, moveTo []int) []int {
+
+}","object Solution {
+ def relocateMarbles(nums: Array[Int], moveFrom: Array[Int], moveTo: Array[Int]): List[Int] = {
+
+ }
+}","class Solution {
+ fun relocateMarbles(nums: IntArray, moveFrom: IntArray, moveTo: IntArray): List {
+
+ }
+}","impl Solution {
+ pub fn relocate_marbles(nums: Vec, move_from: Vec, move_to: Vec) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer[] $moveFrom
+ * @param Integer[] $moveTo
+ * @return Integer[]
+ */
+ function relocateMarbles($nums, $moveFrom, $moveTo) {
+
+ }
+}","function relocateMarbles(nums: number[], moveFrom: number[], moveTo: number[]): number[] {
+
+};","(define/contract (relocate-marbles nums moveFrom moveTo)
+ (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))
+
+ )","-spec relocate_marbles(Nums :: [integer()], MoveFrom :: [integer()], MoveTo :: [integer()]) -> [integer()].
+relocate_marbles(Nums, MoveFrom, MoveTo) ->
+ .","defmodule Solution do
+ @spec relocate_marbles(nums :: [integer], move_from :: [integer], move_to :: [integer]) :: [integer]
+ def relocate_marbles(nums, move_from, move_to) do
+
+ end
+end","class Solution {
+ List relocateMarbles(List nums, List moveFrom, List moveTo) {
+
+ }
+}",
+51,count-zero-request-servers,Count Zero Request Servers,2747.0,2833.0,"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 integer array queries
.
+
+Return a 0-indexed integer array arr
of length queries.length
where arr[i]
represents the number of servers that did not receive any requests during the time interval [queries[i] - x, queries[i]]
.
+
+Note that the time intervals are inclusive.
+
+
+Example 1:
+
+
+Input: n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]
+Output: [1,2]
+Explanation:
+For queries[0]: The servers with ids 1 and 2 get requests in the duration of [5, 10]. Hence, only server 3 gets zero requests.
+For queries[1]: Only the server with id 2 gets a request in duration of [6,11]. Hence, the servers with ids 1 and 3 are the only servers that do not receive any requests during that time period.
+
+
+
+Example 2:
+
+
+Input: n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]
+Output: [0,1]
+Explanation:
+For queries[0]: All servers get at least one request in the duration of [1, 3].
+For queries[1]: Only server with id 3 gets no request in the duration [2,4].
+
+
+
+
+Constraints:
+
+
+ 1 <= n <= 105
+ 1 <= logs.length <= 105
+ 1 <= queries.length <= 105
+ logs[i].length == 2
+ 1 <= logs[i][0] <= n
+ 1 <= logs[i][1] <= 106
+ 1 <= x <= 105
+ x < queries[i] <= 106
+
+",2.0,False,"class Solution {
+public:
+ vector countServers(int n, vector>& logs, int x, vector& queries) {
+
+ }
+};","class Solution {
+ public int[] countServers(int n, int[][] logs, int x, int[] queries) {
+
+ }
+}","class Solution(object):
+ def countServers(self, n, logs, x, queries):
+ """"""
+ :type n: int
+ :type logs: List[List[int]]
+ :type x: int
+ :type queries: List[int]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def countServers(self, n: int, logs: List[List[int]], x: int, queries: List[int]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* countServers(int n, int** logs, int logsSize, int* logsColSize, int x, int* queries, int queriesSize, int* returnSize){
+
+}","public class Solution {
+ public int[] CountServers(int n, int[][] logs, int x, int[] queries) {
+
+ }
+}","/**
+ * @param {number} n
+ * @param {number[][]} logs
+ * @param {number} x
+ * @param {number[]} queries
+ * @return {number[]}
+ */
+var countServers = function(n, logs, x, queries) {
+
+};","# @param {Integer} n
+# @param {Integer[][]} logs
+# @param {Integer} x
+# @param {Integer[]} queries
+# @return {Integer[]}
+def count_servers(n, logs, x, queries)
+
+end","class Solution {
+ func countServers(_ n: Int, _ logs: [[Int]], _ x: Int, _ queries: [Int]) -> [Int] {
+
+ }
+}","func countServers(n int, logs [][]int, x int, queries []int) []int {
+
+}","object Solution {
+ def countServers(n: Int, logs: Array[Array[Int]], x: Int, queries: Array[Int]): Array[Int] = {
+
+ }
+}","class Solution {
+ fun countServers(n: Int, logs: Array, x: Int, queries: IntArray): IntArray {
+
+ }
+}","impl Solution {
+ pub fn count_servers(n: i32, logs: Vec>, x: i32, queries: Vec) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @param Integer[][] $logs
+ * @param Integer $x
+ * @param Integer[] $queries
+ * @return Integer[]
+ */
+ function countServers($n, $logs, $x, $queries) {
+
+ }
+}","function countServers(n: number, logs: number[][], x: number, queries: number[]): number[] {
+
+};","(define/contract (count-servers n logs x queries)
+ (-> exact-integer? (listof (listof exact-integer?)) exact-integer? (listof exact-integer?) (listof exact-integer?))
+
+ )","-spec count_servers(N :: integer(), Logs :: [[integer()]], X :: integer(), Queries :: [integer()]) -> [integer()].
+count_servers(N, Logs, X, Queries) ->
+ .","defmodule Solution do
+ @spec count_servers(n :: integer, logs :: [[integer]], x :: integer, queries :: [integer]) :: [integer]
+ def count_servers(n, logs, x, queries) do
+
+ end
+end","class Solution {
+ List countServers(int n, List> logs, int x, List queries) {
+
+ }
+}",
+53,lexicographically-smallest-string-after-substring-operation,Lexicographically Smallest String After Substring Operation,2734.0,2828.0,"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 of the English alphabet. For example, 'b' is converted to 'a', and 'a' is converted to 'z'.
+
+
+Return the lexicographically smallest string you can obtain after performing the above operation exactly once.
+
+A substring is a contiguous sequence of characters in a string.
+A string x
is lexicographically smaller than a string y
of the same length if x[i]
comes before y[i]
in alphabetic order for the first position i
such that x[i] != y[i]
.
+
+Example 1:
+
+
+Input: s = "cbabc"
+Output: "baabc"
+Explanation: We apply the operation on the substring starting at index 0, and ending at index 1 inclusive.
+It can be proven that the resulting string is the lexicographically smallest.
+
+
+Example 2:
+
+
+Input: s = "acbbc"
+Output: "abaab"
+Explanation: We apply the operation on the substring starting at index 1, and ending at index 4 inclusive.
+It can be proven that the resulting string is the lexicographically smallest.
+
+
+Example 3:
+
+
+Input: s = "leetcode"
+Output: "kddsbncd"
+Explanation: We apply the operation on the entire string.
+It can be proven that the resulting string is the lexicographically smallest.
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 3 * 105
+ s
consists of lowercase English letters
+
+",2.0,False,"class Solution {
+public:
+ string smallestString(string s) {
+
+ }
+};","class Solution {
+ public String smallestString(String s) {
+
+ }
+}","class Solution(object):
+ def smallestString(self, s):
+ """"""
+ :type s: str
+ :rtype: str
+ """"""
+ ","class Solution:
+ def smallestString(self, s: str) -> str:
+ ","char * smallestString(char * s){
+
+}","public class Solution {
+ public string SmallestString(string s) {
+
+ }
+}","/**
+ * @param {string} s
+ * @return {string}
+ */
+var smallestString = function(s) {
+
+};","# @param {String} s
+# @return {String}
+def smallest_string(s)
+
+end","class Solution {
+ func smallestString(_ s: String) -> String {
+
+ }
+}","func smallestString(s string) string {
+
+}","object Solution {
+ def smallestString(s: String): String = {
+
+ }
+}","class Solution {
+ fun smallestString(s: String): String {
+
+ }
+}","impl Solution {
+ pub fn smallest_string(s: String) -> String {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @return String
+ */
+ function smallestString($s) {
+
+ }
+}","function smallestString(s: string): string {
+
+};","(define/contract (smallest-string s)
+ (-> string? string?)
+
+ )","-spec smallest_string(S :: unicode:unicode_binary()) -> unicode:unicode_binary().
+smallest_string(S) ->
+ .","defmodule Solution do
+ @spec smallest_string(s :: String.t) :: String.t
+ def smallest_string(s) do
+
+ end
+end","class Solution {
+ String smallestString(String s) {
+
+ }
+}",
+54,greatest-common-divisor-traversal,Greatest Common Divisor Traversal,2709.0,2827.0,"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 determine if for every pair of indices i
and j
in nums, where i < j
, there exists a sequence of traversals that can take us from i
to j
.
+
+Return true
if it is possible to traverse between all such pairs of indices, or false
otherwise.
+
+
+Example 1:
+
+
+Input: nums = [2,3,6]
+Output: true
+Explanation: In this example, there are 3 possible pairs of indices: (0, 1), (0, 2), and (1, 2).
+To go from index 0 to index 1, we can use the sequence of traversals 0 -> 2 -> 1, where we move from index 0 to index 2 because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1, and then move from index 2 to index 1 because gcd(nums[2], nums[1]) = gcd(6, 3) = 3 > 1.
+To go from index 0 to index 2, we can just go directly because gcd(nums[0], nums[2]) = gcd(2, 6) = 2 > 1. Likewise, to go from index 1 to index 2, we can just go directly because gcd(nums[1], nums[2]) = gcd(3, 6) = 3 > 1.
+
+
+Example 2:
+
+
+Input: nums = [3,9,5]
+Output: false
+Explanation: No sequence of traversals can take us from index 0 to index 2 in this example. So, we return false.
+
+
+Example 3:
+
+
+Input: nums = [4,3,12,8]
+Output: true
+Explanation: There are 6 possible pairs of indices to traverse between: (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), and (2, 3). A valid sequence of traversals exists for each pair, so we return true.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ 1 <= nums[i] <= 105
+
+",3.0,False,"class Solution {
+public:
+ bool canTraverseAllPairs(vector& nums) {
+
+ }
+};","class Solution {
+ public boolean canTraverseAllPairs(int[] nums) {
+
+ }
+}","class Solution(object):
+ def canTraverseAllPairs(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: bool
+ """"""
+ ","class Solution:
+ def canTraverseAllPairs(self, nums: List[int]) -> bool:
+ ","bool canTraverseAllPairs(int* nums, int numsSize){
+
+}","public class Solution {
+ public bool CanTraverseAllPairs(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {boolean}
+ */
+var canTraverseAllPairs = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Boolean}
+def can_traverse_all_pairs(nums)
+
+end","class Solution {
+ func canTraverseAllPairs(_ nums: [Int]) -> Bool {
+
+ }
+}","func canTraverseAllPairs(nums []int) bool {
+
+}","object Solution {
+ def canTraverseAllPairs(nums: Array[Int]): Boolean = {
+
+ }
+}","class Solution {
+ fun canTraverseAllPairs(nums: IntArray): Boolean {
+
+ }
+}","impl Solution {
+ pub fn can_traverse_all_pairs(nums: Vec) -> bool {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Boolean
+ */
+ function canTraverseAllPairs($nums) {
+
+ }
+}","function canTraverseAllPairs(nums: number[]): boolean {
+
+};","(define/contract (can-traverse-all-pairs nums)
+ (-> (listof exact-integer?) boolean?)
+
+ )","-spec can_traverse_all_pairs(Nums :: [integer()]) -> boolean().
+can_traverse_all_pairs(Nums) ->
+ .","defmodule Solution do
+ @spec can_traverse_all_pairs(nums :: [integer]) :: boolean
+ def can_traverse_all_pairs(nums) do
+
+ end
+end","class Solution {
+ bool canTraverseAllPairs(List nums) {
+
+ }
+}",
+55,find-a-good-subset-of-the-matrix,Find a Good Subset of the Matrix,2732.0,2826.0,"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 each column should be at most floor(k / 2)
.
+
+Return an integer array that contains row indices of a good subset sorted in ascending order.
+
+If there are multiple good subsets, you can return any of them. If there are no good subsets, return an empty array.
+
+A subset of rows of the matrix grid
is any matrix that can be obtained by deleting some (possibly none or all) rows from grid
.
+
+
+Example 1:
+
+
+Input: grid = [[0,1,1,0],[0,0,0,1],[1,1,1,1]]
+Output: [0,1]
+Explanation: We can choose the 0th and 1st rows to create a good subset of rows.
+The length of the chosen subset is 2.
+- The sum of the 0th column is 0 + 0 = 0, which is at most half of the length of the subset.
+- The sum of the 1st column is 1 + 0 = 1, which is at most half of the length of the subset.
+- The sum of the 2nd column is 1 + 0 = 1, which is at most half of the length of the subset.
+- The sum of the 3rd column is 0 + 1 = 1, which is at most half of the length of the subset.
+
+
+Example 2:
+
+
+Input: grid = [[0]]
+Output: [0]
+Explanation: We can choose the 0th row to create a good subset of rows.
+The length of the chosen subset is 1.
+- The sum of the 0th column is 0, which is at most half of the length of the subset.
+
+
+Example 3:
+
+
+Input: grid = [[1,1,1],[1,1,1]]
+Output: []
+Explanation: It is impossible to choose any subset of rows to create a good subset.
+
+
+
+Constraints:
+
+
+ m == grid.length
+ n == grid[i].length
+ 1 <= m <= 104
+ 1 <= n <= 5
+ grid[i][j]
is either 0
or 1
.
+
+",3.0,False,"class Solution {
+public:
+ vector goodSubsetofBinaryMatrix(vector>& grid) {
+
+ }
+};","class Solution {
+ public List goodSubsetofBinaryMatrix(int[][] grid) {
+
+ }
+}","class Solution(object):
+ def goodSubsetofBinaryMatrix(self, grid):
+ """"""
+ :type grid: List[List[int]]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def goodSubsetofBinaryMatrix(self, grid: List[List[int]]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* goodSubsetofBinaryMatrix(int** grid, int gridSize, int* gridColSize, int* returnSize){
+
+}","public class Solution {
+ public IList GoodSubsetofBinaryMatrix(int[][] grid) {
+
+ }
+}","/**
+ * @param {number[][]} grid
+ * @return {number[]}
+ */
+var goodSubsetofBinaryMatrix = function(grid) {
+
+};","# @param {Integer[][]} grid
+# @return {Integer[]}
+def good_subsetof_binary_matrix(grid)
+
+end","class Solution {
+ func goodSubsetofBinaryMatrix(_ grid: [[Int]]) -> [Int] {
+
+ }
+}","func goodSubsetofBinaryMatrix(grid [][]int) []int {
+
+}","object Solution {
+ def goodSubsetofBinaryMatrix(grid: Array[Array[Int]]): List[Int] = {
+
+ }
+}","class Solution {
+ fun goodSubsetofBinaryMatrix(grid: Array): List {
+
+ }
+}","impl Solution {
+ pub fn good_subsetof_binary_matrix(grid: Vec>) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[][] $grid
+ * @return Integer[]
+ */
+ function goodSubsetofBinaryMatrix($grid) {
+
+ }
+}","function goodSubsetofBinaryMatrix(grid: number[][]): number[] {
+
+};","(define/contract (good-subsetof-binary-matrix grid)
+ (-> (listof (listof exact-integer?)) (listof exact-integer?))
+
+ )","-spec good_subsetof_binary_matrix(Grid :: [[integer()]]) -> [integer()].
+good_subsetof_binary_matrix(Grid) ->
+ .","defmodule Solution do
+ @spec good_subsetof_binary_matrix(grid :: [[integer]]) :: [integer]
+ def good_subsetof_binary_matrix(grid) do
+
+ end
+end","class Solution {
+ List goodSubsetofBinaryMatrix(List> grid) {
+
+ }
+}",
+56,minimize-string-length,Minimize String Length,2716.0,2825.0,"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 of c
to the right of i
(if any).
+
+
+Your task is to minimize the length of s
by performing the above operation any number of times.
+
+Return an integer denoting the length of the minimized string.
+
+
+Example 1:
+
+
+Input: s = "aaabc"
+Output: 3
+Explanation: In this example, s is "aaabc". We can start by selecting the character 'a' at index 1. We then remove the closest 'a' to the left of index 1, which is at index 0, and the closest 'a' to the right of index 1, which is at index 2. After this operation, the string becomes "abc". Any further operation we perform on the string will leave it unchanged. Therefore, the length of the minimized string is 3.
+
+Example 2:
+
+
+Input: s = "cbbd"
+Output: 3
+Explanation: For this we can start with character 'b' at index 1. There is no occurrence of 'b' to the left of index 1, but there is one to the right at index 2, so we delete the 'b' at index 2. The string becomes "cbd" and further operations will leave it unchanged. Hence, the minimized length is 3.
+
+
+Example 3:
+
+
+Input: s = "dddaaa"
+Output: 2
+Explanation: For this, we can start with the character 'd' at index 1. The closest occurrence of a 'd' to its left is at index 0, and the closest occurrence of a 'd' to its right is at index 2. We delete both index 0 and 2, so the string becomes "daaa". In the new string, we can select the character 'a' at index 2. The closest occurrence of an 'a' to its left is at index 1, and the closest occurrence of an 'a' to its right is at index 3. We delete both of them, and the string becomes "da". We cannot minimize this further, so the minimized length is 2.
+
+
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 100
+ s
contains only lowercase English letters
+
+",1.0,False,"class Solution {
+public:
+ int minimizedStringLength(string s) {
+
+ }
+};","class Solution {
+ public int minimizedStringLength(String s) {
+
+ }
+}","class Solution(object):
+ def minimizedStringLength(self, s):
+ """"""
+ :type s: str
+ :rtype: int
+ """"""
+ ","class Solution:
+ def minimizedStringLength(self, s: str) -> int:
+ ","int minimizedStringLength(char * s){
+
+}","public class Solution {
+ public int MinimizedStringLength(string s) {
+
+ }
+}","/**
+ * @param {string} s
+ * @return {number}
+ */
+var minimizedStringLength = function(s) {
+
+};","# @param {String} s
+# @return {Integer}
+def minimized_string_length(s)
+
+end","class Solution {
+ func minimizedStringLength(_ s: String) -> Int {
+
+ }
+}","func minimizedStringLength(s string) int {
+
+}","object Solution {
+ def minimizedStringLength(s: String): Int = {
+
+ }
+}","class Solution {
+ fun minimizedStringLength(s: String): Int {
+
+ }
+}","impl Solution {
+ pub fn minimized_string_length(s: String) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @return Integer
+ */
+ function minimizedStringLength($s) {
+
+ }
+}","function minimizedStringLength(s: string): number {
+
+};","(define/contract (minimized-string-length s)
+ (-> string? exact-integer?)
+
+ )","-spec minimized_string_length(S :: unicode:unicode_binary()) -> integer().
+minimized_string_length(S) ->
+ .","defmodule Solution do
+ @spec minimized_string_length(s :: String.t) :: integer
+ def minimized_string_length(s) do
+
+ end
+end","class Solution {
+ int minimizedStringLength(String s) {
+
+ }
+}",
+57,check-if-the-number-is-fascinating,Check if The Number is Fascinating,2729.0,2824.0,"You are given an integer n
that consists of exactly 3
digits.
+
+We call the number n
fascinating if, after the following modification, the resulting number contains all the digits from 1
to 9
exactly once and does not contain any 0
's:
+
+
+ - Concatenate
n
with the numbers 2 * n
and 3 * n
.
+
+
+Return true
if n
is fascinating, or false
otherwise.
+
+Concatenating two numbers means joining them together. For example, the concatenation of 121
and 371
is 121371
.
+
+
+Example 1:
+
+
+Input: n = 192
+Output: true
+Explanation: We concatenate the numbers n = 192 and 2 * n = 384 and 3 * n = 576. The resulting number is 192384576. This number contains all the digits from 1 to 9 exactly once.
+
+
+Example 2:
+
+
+Input: n = 100
+Output: false
+Explanation: We concatenate the numbers n = 100 and 2 * n = 200 and 3 * n = 300. The resulting number is 100200300. This number does not satisfy any of the conditions.
+
+
+
+Constraints:
+
+
+",1.0,False,"class Solution {
+public:
+ bool isFascinating(int n) {
+
+ }
+};","class Solution {
+ public boolean isFascinating(int n) {
+
+ }
+}","class Solution(object):
+ def isFascinating(self, n):
+ """"""
+ :type n: int
+ :rtype: bool
+ """"""
+ ","class Solution:
+ def isFascinating(self, n: int) -> bool:
+ ","bool isFascinating(int n){
+
+}","public class Solution {
+ public bool IsFascinating(int n) {
+
+ }
+}","/**
+ * @param {number} n
+ * @return {boolean}
+ */
+var isFascinating = function(n) {
+
+};","# @param {Integer} n
+# @return {Boolean}
+def is_fascinating(n)
+
+end","class Solution {
+ func isFascinating(_ n: Int) -> Bool {
+
+ }
+}","func isFascinating(n int) bool {
+
+}","object Solution {
+ def isFascinating(n: Int): Boolean = {
+
+ }
+}","class Solution {
+ fun isFascinating(n: Int): Boolean {
+
+ }
+}","impl Solution {
+ pub fn is_fascinating(n: i32) -> bool {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @return Boolean
+ */
+ function isFascinating($n) {
+
+ }
+}","function isFascinating(n: number): boolean {
+
+};","(define/contract (is-fascinating n)
+ (-> exact-integer? boolean?)
+
+ )","-spec is_fascinating(N :: integer()) -> boolean().
+is_fascinating(N) ->
+ .","defmodule Solution do
+ @spec is_fascinating(n :: integer) :: boolean
+ def is_fascinating(n) do
+
+ end
+end","class Solution {
+ bool isFascinating(int n) {
+
+ }
+}",
+59,maximum-strictly-increasing-cells-in-a-matrix,Maximum Strictly Increasing Cells in a Matrix,2713.0,2818.0,"Given a 1-indexed m x n
integer matrix mat
, you can select any cell in the matrix as your starting cell.
+
+From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.
+
+Your task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.
+
+Return an integer denoting the maximum number of cells that can be visited.
+
+
+Example 1:
+
+
+
+
+Input: mat = [[3,1],[3,4]]
+Output: 2
+Explanation: The image shows how we can visit 2 cells starting from row 1, column 2. It can be shown that we cannot visit more than 2 cells no matter where we start from, so the answer is 2.
+
+
+Example 2:
+
+
+
+
+Input: mat = [[1,1],[1,1]]
+Output: 1
+Explanation: Since the cells must be strictly increasing, we can only visit one cell in this example.
+
+
+Example 3:
+
+
+
+
+Input: mat = [[3,1,6],[-9,5,7]]
+Output: 4
+Explanation: The image above shows how we can visit 4 cells starting from row 2, column 1. It can be shown that we cannot visit more than 4 cells no matter where we start from, so the answer is 4.
+
+
+
+Constraints:
+
+
+ m == mat.length
+ n == mat[i].length
+ 1 <= m, n <= 105
+ 1 <= m * n <= 105
+ -105 <= mat[i][j] <= 105
+
+",3.0,False,"class Solution {
+public:
+ int maxIncreasingCells(vector>& mat) {
+
+ }
+};","class Solution {
+ public int maxIncreasingCells(int[][] mat) {
+
+ }
+}","class Solution(object):
+ def maxIncreasingCells(self, mat):
+ """"""
+ :type mat: List[List[int]]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maxIncreasingCells(self, mat: List[List[int]]) -> int:
+ ","int maxIncreasingCells(int** mat, int matSize, int* matColSize){
+
+}","public class Solution {
+ public int MaxIncreasingCells(int[][] mat) {
+
+ }
+}","/**
+ * @param {number[][]} mat
+ * @return {number}
+ */
+var maxIncreasingCells = function(mat) {
+
+};","# @param {Integer[][]} mat
+# @return {Integer}
+def max_increasing_cells(mat)
+
+end","class Solution {
+ func maxIncreasingCells(_ mat: [[Int]]) -> Int {
+
+ }
+}","func maxIncreasingCells(mat [][]int) int {
+
+}","object Solution {
+ def maxIncreasingCells(mat: Array[Array[Int]]): Int = {
+
+ }
+}","class Solution {
+ fun maxIncreasingCells(mat: Array): Int {
+
+ }
+}","impl Solution {
+ pub fn max_increasing_cells(mat: Vec>) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[][] $mat
+ * @return Integer
+ */
+ function maxIncreasingCells($mat) {
+
+ }
+}","function maxIncreasingCells(mat: number[][]): number {
+
+};","(define/contract (max-increasing-cells mat)
+ (-> (listof (listof exact-integer?)) exact-integer?)
+
+ )","-spec max_increasing_cells(Mat :: [[integer()]]) -> integer().
+max_increasing_cells(Mat) ->
+ .","defmodule Solution do
+ @spec max_increasing_cells(mat :: [[integer]]) :: integer
+ def max_increasing_cells(mat) do
+
+ end
+end","class Solution {
+ int maxIncreasingCells(List> mat) {
+
+ }
+}",
+60,minimum-cost-to-make-all-characters-equal,Minimum Cost to Make All Characters Equal,2712.0,2817.0,"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 characters from index i
to index n - 1
(both inclusive), with a cost of n - i
+
+
+Return the minimum cost to make all characters of the string equal.
+
+Invert a character means if its value is '0' it becomes '1' and vice-versa.
+
+
+Example 1:
+
+
+Input: s = "0011"
+Output: 2
+Explanation: Apply the second operation with i = 2
to obtain s = "0000" for a cost of 2
. It can be shown that 2 is the minimum cost to make all characters equal.
+
+
+Example 2:
+
+
+Input: s = "010101"
+Output: 9
+Explanation: Apply the first operation with i = 2 to obtain s = "101101" for a cost of 3.
+Apply the first operation with i = 1 to obtain s = "011101" for a cost of 2.
+Apply the first operation with i = 0 to obtain s = "111101" for a cost of 1.
+Apply the second operation with i = 4 to obtain s = "111110" for a cost of 2.
+Apply the second operation with i = 5 to obtain s = "111111" for a cost of 1.
+The total cost to make all characters equal is 9. It can be shown that 9 is the minimum cost to make all characters equal.
+
+
+
+Constraints:
+
+
+ 1 <= s.length == n <= 105
+ s[i]
is either '0'
or '1'
+
+",2.0,False,"class Solution {
+public:
+ long long minimumCost(string s) {
+
+ }
+};","class Solution {
+ public long minimumCost(String s) {
+
+ }
+}","class Solution(object):
+ def minimumCost(self, s):
+ """"""
+ :type s: str
+ :rtype: int
+ """"""
+ ","class Solution:
+ def minimumCost(self, s: str) -> int:
+ ","long long minimumCost(char * s){
+
+}","public class Solution {
+ public long MinimumCost(string s) {
+
+ }
+}","/**
+ * @param {string} s
+ * @return {number}
+ */
+var minimumCost = function(s) {
+
+};","# @param {String} s
+# @return {Integer}
+def minimum_cost(s)
+
+end","class Solution {
+ func minimumCost(_ s: String) -> Int {
+
+ }
+}","func minimumCost(s string) int64 {
+
+}","object Solution {
+ def minimumCost(s: String): Long = {
+
+ }
+}","class Solution {
+ fun minimumCost(s: String): Long {
+
+ }
+}","impl Solution {
+ pub fn minimum_cost(s: String) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @return Integer
+ */
+ function minimumCost($s) {
+
+ }
+}","function minimumCost(s: string): number {
+
+};","(define/contract (minimum-cost s)
+ (-> string? exact-integer?)
+
+ )","-spec minimum_cost(S :: unicode:unicode_binary()) -> integer().
+minimum_cost(S) ->
+ .","defmodule Solution do
+ @spec minimum_cost(s :: String.t) :: integer
+ def minimum_cost(s) do
+
+ end
+end","class Solution {
+ int minimumCost(String s) {
+
+ }
+}",
+61,lexicographically-smallest-palindrome,Lexicographically Smallest Palindrome,2697.0,2816.0,"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 number of operations possible. If there are multiple palindromes that can be made using the minimum number of operations, make the lexicographically smallest one.
+
+A string a
is lexicographically smaller than a string b
(of the same length) if in the first position where a
and b
differ, string a
has a letter that appears earlier in the alphabet than the corresponding letter in b
.
+
+Return the resulting palindrome string.
+
+
+Example 1:
+
+
+Input: s = "egcfe"
+Output: "efcfe"
+Explanation: The minimum number of operations to make "egcfe" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "efcfe", by changing 'g'.
+
+
+Example 2:
+
+
+Input: s = "abcd"
+Output: "abba"
+Explanation: The minimum number of operations to make "abcd" a palindrome is 2, and the lexicographically smallest palindrome string we can get by modifying two characters is "abba".
+
+
+Example 3:
+
+
+Input: s = "seven"
+Output: "neven"
+Explanation: The minimum number of operations to make "seven" a palindrome is 1, and the lexicographically smallest palindrome string we can get by modifying one character is "neven".
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 1000
+ s
consists of only lowercase English letters.
+
+",1.0,False,"class Solution {
+public:
+ string makeSmallestPalindrome(string s) {
+
+ }
+};","class Solution {
+ public String makeSmallestPalindrome(String s) {
+
+ }
+}","class Solution(object):
+ def makeSmallestPalindrome(self, s):
+ """"""
+ :type s: str
+ :rtype: str
+ """"""
+ ","class Solution:
+ def makeSmallestPalindrome(self, s: str) -> str:
+ ","char * makeSmallestPalindrome(char * s){
+
+}","public class Solution {
+ public string MakeSmallestPalindrome(string s) {
+
+ }
+}","/**
+ * @param {string} s
+ * @return {string}
+ */
+var makeSmallestPalindrome = function(s) {
+
+};","# @param {String} s
+# @return {String}
+def make_smallest_palindrome(s)
+
+end","class Solution {
+ func makeSmallestPalindrome(_ s: String) -> String {
+
+ }
+}","func makeSmallestPalindrome(s string) string {
+
+}","object Solution {
+ def makeSmallestPalindrome(s: String): String = {
+
+ }
+}","class Solution {
+ fun makeSmallestPalindrome(s: String): String {
+
+ }
+}","impl Solution {
+ pub fn make_smallest_palindrome(s: String) -> String {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @return String
+ */
+ function makeSmallestPalindrome($s) {
+
+ }
+}","function makeSmallestPalindrome(s: string): string {
+
+};","(define/contract (make-smallest-palindrome s)
+ (-> string? string?)
+
+ )","-spec make_smallest_palindrome(S :: unicode:unicode_binary()) -> unicode:unicode_binary().
+make_smallest_palindrome(S) ->
+ .","defmodule Solution do
+ @spec make_smallest_palindrome(s :: String.t) :: String.t
+ def make_smallest_palindrome(s) do
+
+ end
+end","class Solution {
+ String makeSmallestPalindrome(String s) {
+
+ }
+}",
+64,painting-the-walls,Painting the Walls,2742.0,2808.0,"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]
units of money.
+ - A free painter that paints any wall in
1
unit of time at a cost of 0
. But the free painter can only be used if the paid painter is already occupied.
+
+
+Return the minimum amount of money required to paint the n
walls.
+
+
+Example 1:
+
+
+Input: cost = [1,2,3,2], time = [1,2,3,2]
+Output: 3
+Explanation: The walls at index 0 and 1 will be painted by the paid painter, and it will take 3 units of time; meanwhile, the free painter will paint the walls at index 2 and 3, free of cost in 2 units of time. Thus, the total cost is 1 + 2 = 3.
+
+
+Example 2:
+
+
+Input: cost = [2,3,4,2], time = [1,1,1,1]
+Output: 4
+Explanation: The walls at index 0 and 3 will be painted by the paid painter, and it will take 2 units of time; meanwhile, the free painter will paint the walls at index 1 and 2, free of cost in 2 units of time. Thus, the total cost is 2 + 2 = 4.
+
+
+
+Constraints:
+
+
+ 1 <= cost.length <= 500
+ cost.length == time.length
+ 1 <= cost[i] <= 106
+ 1 <= time[i] <= 500
+
+",3.0,False,"class Solution {
+public:
+ int paintWalls(vector& cost, vector& time) {
+
+ }
+};","class Solution {
+ public int paintWalls(int[] cost, int[] time) {
+
+ }
+}","class Solution(object):
+ def paintWalls(self, cost, time):
+ """"""
+ :type cost: List[int]
+ :type time: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def paintWalls(self, cost: List[int], time: List[int]) -> int:
+ ","int paintWalls(int* cost, int costSize, int* time, int timeSize){
+
+}","public class Solution {
+ public int PaintWalls(int[] cost, int[] time) {
+
+ }
+}","/**
+ * @param {number[]} cost
+ * @param {number[]} time
+ * @return {number}
+ */
+var paintWalls = function(cost, time) {
+
+};","# @param {Integer[]} cost
+# @param {Integer[]} time
+# @return {Integer}
+def paint_walls(cost, time)
+
+end","class Solution {
+ func paintWalls(_ cost: [Int], _ time: [Int]) -> Int {
+
+ }
+}","func paintWalls(cost []int, time []int) int {
+
+}","object Solution {
+ def paintWalls(cost: Array[Int], time: Array[Int]): Int = {
+
+ }
+}","class Solution {
+ fun paintWalls(cost: IntArray, time: IntArray): Int {
+
+ }
+}","impl Solution {
+ pub fn paint_walls(cost: Vec, time: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $cost
+ * @param Integer[] $time
+ * @return Integer
+ */
+ function paintWalls($cost, $time) {
+
+ }
+}","function paintWalls(cost: number[], time: number[]): number {
+
+};","(define/contract (paint-walls cost time)
+ (-> (listof exact-integer?) (listof exact-integer?) exact-integer?)
+
+ )","-spec paint_walls(Cost :: [integer()], Time :: [integer()]) -> integer().
+paint_walls(Cost, Time) ->
+ .","defmodule Solution do
+ @spec paint_walls(cost :: [integer], time :: [integer]) :: integer
+ def paint_walls(cost, time) do
+
+ end
+end","class Solution {
+ int paintWalls(List cost, List time) {
+
+ }
+}",
+65,modify-graph-edge-weights,Modify Graph Edge Weights,2699.0,2803.0,"You are given an undirected weighted connected graph containing n
nodes labeled from 0
to n - 1
, and an integer array edges
where edges[i] = [ai, bi, wi]
indicates that there is an edge between nodes ai
and bi
with weight wi
.
+
+Some edges have a weight of -1
(wi = -1
), while others have a positive weight (wi > 0
).
+
+Your task is to modify all edges with a weight of -1
by assigning them positive integer values in the range [1, 2 * 109]
so that the shortest distance between the nodes source
and destination
becomes equal to an integer target
. If there are multiple modifications that make the shortest distance between source
and destination
equal to target
, any of them will be considered correct.
+
+Return an array containing all edges (even unmodified ones) in any order if it is possible to make the shortest distance from source
to destination
equal to target
, or an empty array if it's impossible.
+
+Note: You are not allowed to modify the weights of edges with initial positive weights.
+
+
+Example 1:
+
+
+
+
+Input: n = 5, edges = [[4,1,-1],[2,0,-1],[0,3,-1],[4,3,-1]], source = 0, destination = 1, target = 5
+Output: [[4,1,1],[2,0,1],[0,3,3],[4,3,1]]
+Explanation: The graph above shows a possible modification to the edges, making the distance from 0 to 1 equal to 5.
+
+
+Example 2:
+
+
+
+
+Input: n = 3, edges = [[0,1,-1],[0,2,5]], source = 0, destination = 2, target = 6
+Output: []
+Explanation: The graph above contains the initial edges. It is not possible to make the distance from 0 to 2 equal to 6 by modifying the edge with weight -1. So, an empty array is returned.
+
+
+Example 3:
+
+
+
+
+Input: n = 4, edges = [[1,0,4],[1,2,3],[2,3,5],[0,3,-1]], source = 0, destination = 2, target = 6
+Output: [[1,0,4],[1,2,3],[2,3,5],[0,3,1]]
+Explanation: The graph above shows a modified graph having the shortest distance from 0 to 2 as 6.
+
+
+
+Constraints:
+
+
+ 1 <= n <= 100
+ 1 <= edges.length <= n * (n - 1) / 2
+ edges[i].length == 3
+ 0 <= ai, bi < n
+ wi = -1
or 1 <= wi <= 107
+ ai != bi
+ 0 <= source, destination < n
+ source != destination
+ 1 <= target <= 109
+ - The graph is connected, and there are no self-loops or repeated edges
+
+",3.0,False,"class Solution {
+public:
+ vector> modifiedGraphEdges(int n, vector>& edges, int source, int destination, int target) {
+
+ }
+};","class Solution {
+ public int[][] modifiedGraphEdges(int n, int[][] edges, int source, int destination, int target) {
+
+ }
+}","class Solution(object):
+ def modifiedGraphEdges(self, n, edges, source, destination, target):
+ """"""
+ :type n: int
+ :type edges: List[List[int]]
+ :type source: int
+ :type destination: int
+ :type target: int
+ :rtype: List[List[int]]
+ """"""
+ ","class Solution:
+ def modifiedGraphEdges(self, n: int, edges: List[List[int]], source: int, destination: int, target: int) -> List[List[int]]:
+ ","/**
+ * Return an array of arrays of size *returnSize.
+ * The sizes of the arrays are returned as *returnColumnSizes array.
+ * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
+ */
+int** modifiedGraphEdges(int n, int** edges, int edgesSize, int* edgesColSize, int source, int destination, int target, int* returnSize, int** returnColumnSizes){
+
+}","public class Solution {
+ public int[][] ModifiedGraphEdges(int n, int[][] edges, int source, int destination, int target) {
+
+ }
+}","/**
+ * @param {number} n
+ * @param {number[][]} edges
+ * @param {number} source
+ * @param {number} destination
+ * @param {number} target
+ * @return {number[][]}
+ */
+var modifiedGraphEdges = function(n, edges, source, destination, target) {
+
+};","# @param {Integer} n
+# @param {Integer[][]} edges
+# @param {Integer} source
+# @param {Integer} destination
+# @param {Integer} target
+# @return {Integer[][]}
+def modified_graph_edges(n, edges, source, destination, target)
+
+end","class Solution {
+ func modifiedGraphEdges(_ n: Int, _ edges: [[Int]], _ source: Int, _ destination: Int, _ target: Int) -> [[Int]] {
+
+ }
+}","func modifiedGraphEdges(n int, edges [][]int, source int, destination int, target int) [][]int {
+
+}","object Solution {
+ def modifiedGraphEdges(n: Int, edges: Array[Array[Int]], source: Int, destination: Int, target: Int): Array[Array[Int]] = {
+
+ }
+}","class Solution {
+ fun modifiedGraphEdges(n: Int, edges: Array, source: Int, destination: Int, target: Int): Array {
+
+ }
+}","impl Solution {
+ pub fn modified_graph_edges(n: i32, edges: Vec>, source: i32, destination: i32, target: i32) -> Vec> {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @param Integer[][] $edges
+ * @param Integer $source
+ * @param Integer $destination
+ * @param Integer $target
+ * @return Integer[][]
+ */
+ function modifiedGraphEdges($n, $edges, $source, $destination, $target) {
+
+ }
+}","function modifiedGraphEdges(n: number, edges: number[][], source: number, destination: number, target: number): number[][] {
+
+};","(define/contract (modified-graph-edges n edges source destination target)
+ (-> exact-integer? (listof (listof exact-integer?)) exact-integer? exact-integer? exact-integer? (listof (listof exact-integer?)))
+
+ )","-spec modified_graph_edges(N :: integer(), Edges :: [[integer()]], Source :: integer(), Destination :: integer(), Target :: integer()) -> [[integer()]].
+modified_graph_edges(N, Edges, Source, Destination, Target) ->
+ .","defmodule Solution do
+ @spec modified_graph_edges(n :: integer, edges :: [[integer]], source :: integer, destination :: integer, target :: integer) :: [[integer]]
+ def modified_graph_edges(n, edges, source, destination, target) do
+
+ end
+end","class Solution {
+ List> modifiedGraphEdges(int n, List> edges, int source, int destination, int target) {
+
+ }
+}",
+66,find-the-punishment-number-of-an-integer,Find the Punishment Number of an Integer,2698.0,2802.0,"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 substrings such that the sum of the integer values of these substrings equals i
.
+
+
+
+Example 1:
+
+
+Input: n = 10
+Output: 182
+Explanation: There are exactly 3 integers i that satisfy the conditions in the statement:
+- 1 since 1 * 1 = 1
+- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.
+- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.
+Hence, the punishment number of 10 is 1 + 81 + 100 = 182
+
+
+Example 2:
+
+
+Input: n = 37
+Output: 1478
+Explanation: There are exactly 4 integers i that satisfy the conditions in the statement:
+- 1 since 1 * 1 = 1.
+- 9 since 9 * 9 = 81 and 81 can be partitioned into 8 + 1.
+- 10 since 10 * 10 = 100 and 100 can be partitioned into 10 + 0.
+- 36 since 36 * 36 = 1296 and 1296 can be partitioned into 1 + 29 + 6.
+Hence, the punishment number of 37 is 1 + 81 + 100 + 1296 = 1478
+
+
+
+Constraints:
+
+
+",2.0,False,"class Solution {
+public:
+ int punishmentNumber(int n) {
+
+ }
+};","class Solution {
+ public int punishmentNumber(int n) {
+
+ }
+}","class Solution(object):
+ def punishmentNumber(self, n):
+ """"""
+ :type n: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def punishmentNumber(self, n: int) -> int:
+ ","int punishmentNumber(int n){
+
+}","public class Solution {
+ public int PunishmentNumber(int n) {
+
+ }
+}","/**
+ * @param {number} n
+ * @return {number}
+ */
+var punishmentNumber = function(n) {
+
+};","# @param {Integer} n
+# @return {Integer}
+def punishment_number(n)
+
+end","class Solution {
+ func punishmentNumber(_ n: Int) -> Int {
+
+ }
+}","func punishmentNumber(n int) int {
+
+}","object Solution {
+ def punishmentNumber(n: Int): Int = {
+
+ }
+}","class Solution {
+ fun punishmentNumber(n: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn punishment_number(n: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @return Integer
+ */
+ function punishmentNumber($n) {
+
+ }
+}","function punishmentNumber(n: number): number {
+
+};","(define/contract (punishment-number n)
+ (-> exact-integer? exact-integer?)
+
+ )","-spec punishment_number(N :: integer()) -> integer().
+punishment_number(N) ->
+ .","defmodule Solution do
+ @spec punishment_number(n :: integer) :: integer
+ def punishment_number(n) do
+
+ end
+end","class Solution {
+ int punishmentNumber(int n) {
+
+ }
+}",
+74,find-the-longest-semi-repetitive-substring,Find the Longest Semi-Repetitive Substring,2730.0,2786.0,"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-repetitive while 00101022
, and 1101234883
are not.
+
+Return the length of the longest semi-repetitive substring inside s
.
+
+A substring is a contiguous non-empty sequence of characters within a string.
+
+
+Example 1:
+
+
+Input: s = "52233"
+Output: 4
+Explanation: The longest semi-repetitive substring is "5223", which starts at i = 0 and ends at j = 3.
+
+
+Example 2:
+
+
+Input: s = "5494"
+Output: 4
+Explanation: s is a semi-reptitive string, so the answer is 4.
+
+
+Example 3:
+
+
+Input: s = "1111111"
+Output: 2
+Explanation: The longest semi-repetitive substring is "11", which starts at i = 0 and ends at j = 1.
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 50
+ '0' <= s[i] <= '9'
+
+",2.0,False,"class Solution {
+public:
+ int longestSemiRepetitiveSubstring(string s) {
+
+ }
+};","class Solution {
+ public int longestSemiRepetitiveSubstring(String s) {
+
+ }
+}","class Solution(object):
+ def longestSemiRepetitiveSubstring(self, s):
+ """"""
+ :type s: str
+ :rtype: int
+ """"""
+ ","class Solution:
+ def longestSemiRepetitiveSubstring(self, s: str) -> int:
+ ","int longestSemiRepetitiveSubstring(char * s){
+
+}","public class Solution {
+ public int LongestSemiRepetitiveSubstring(string s) {
+
+ }
+}","/**
+ * @param {string} s
+ * @return {number}
+ */
+var longestSemiRepetitiveSubstring = function(s) {
+
+};","# @param {String} s
+# @return {Integer}
+def longest_semi_repetitive_substring(s)
+
+end","class Solution {
+ func longestSemiRepetitiveSubstring(_ s: String) -> Int {
+
+ }
+}","func longestSemiRepetitiveSubstring(s string) int {
+
+}","object Solution {
+ def longestSemiRepetitiveSubstring(s: String): Int = {
+
+ }
+}","class Solution {
+ fun longestSemiRepetitiveSubstring(s: String): Int {
+
+ }
+}","impl Solution {
+ pub fn longest_semi_repetitive_substring(s: String) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @return Integer
+ */
+ function longestSemiRepetitiveSubstring($s) {
+
+ }
+}","function longestSemiRepetitiveSubstring(s: string): number {
+
+};","(define/contract (longest-semi-repetitive-substring s)
+ (-> string? exact-integer?)
+
+ )","-spec longest_semi_repetitive_substring(S :: unicode:unicode_binary()) -> integer().
+longest_semi_repetitive_substring(S) ->
+ .","defmodule Solution do
+ @spec longest_semi_repetitive_substring(s :: String.t) :: integer
+ def longest_semi_repetitive_substring(s) do
+
+ end
+end","class Solution {
+ int longestSemiRepetitiveSubstring(String s) {
+
+ }
+}",
+76,power-of-heroes,Power of Heroes,2681.0,2784.0,"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(nums[i0], nums[i1], ... ,nums[ik])
.
+
+
+Return the sum of the power of all non-empty groups of heroes possible. Since the sum could be very large, return it modulo 109 + 7
.
+
+
+Example 1:
+
+
+Input: nums = [2,1,4]
+Output: 141
+Explanation:
+1st group: [2] has power = 22 * 2 = 8.
+2nd group: [1] has power = 12 * 1 = 1.
+3rd group: [4] has power = 42 * 4 = 64.
+4th group: [2,1] has power = 22 * 1 = 4.
+5th group: [2,4] has power = 42 * 2 = 32.
+6th group: [1,4] has power = 42 * 1 = 16.
+7th group: [2,1,4] has power = 42 * 1 = 16.
+The sum of powers of all groups is 8 + 1 + 64 + 4 + 32 + 16 + 16 = 141.
+
+
+
+Example 2:
+
+
+Input: nums = [1,1,1]
+Output: 7
+Explanation: A total of 7 groups are possible, and the power of each group will be 1. Therefore, the sum of the powers of all groups is 7.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ 1 <= nums[i] <= 109
+
+",3.0,False,"class Solution {
+public:
+ int sumOfPower(vector& nums) {
+
+ }
+};","class Solution {
+ public int sumOfPower(int[] nums) {
+
+ }
+}","class Solution(object):
+ def sumOfPower(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def sumOfPower(self, nums: List[int]) -> int:
+ ","int sumOfPower(int* nums, int numsSize){
+
+}","public class Solution {
+ public int SumOfPower(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var sumOfPower = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def sum_of_power(nums)
+
+end","class Solution {
+ func sumOfPower(_ nums: [Int]) -> Int {
+
+ }
+}","func sumOfPower(nums []int) int {
+
+}","object Solution {
+ def sumOfPower(nums: Array[Int]): Int = {
+
+ }
+}","class Solution {
+ fun sumOfPower(nums: IntArray): Int {
+
+ }
+}","impl Solution {
+ pub fn sum_of_power(nums: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function sumOfPower($nums) {
+
+ }
+}","function sumOfPower(nums: number[]): number {
+
+};","(define/contract (sum-of-power nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec sum_of_power(Nums :: [integer()]) -> integer().
+sum_of_power(Nums) ->
+ .","defmodule Solution do
+ @spec sum_of_power(nums :: [integer]) :: integer
+ def sum_of_power(nums) do
+
+ end
+end","class Solution {
+ int sumOfPower(List nums) {
+
+ }
+}",
+80,find-the-distinct-difference-array,Find the Distinct Difference Array,2670.0,2777.0,"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 distinct elements in the prefix nums[0, ..., i]
.
+
+Return the distinct difference array of nums
.
+
+Note that nums[i, ..., j]
denotes the subarray of nums
starting at index i
and ending at index j
inclusive. Particularly, if i > j
then nums[i, ..., j]
denotes an empty subarray.
+
+
+Example 1:
+
+
+Input: nums = [1,2,3,4,5]
+Output: [-3,-1,1,3,5]
+Explanation: For index i = 0, there is 1 element in the prefix and 4 distinct elements in the suffix. Thus, diff[0] = 1 - 4 = -3.
+For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.
+For index i = 2, there are 3 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 3 - 2 = 1.
+For index i = 3, there are 4 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 4 - 1 = 3.
+For index i = 4, there are 5 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 5 - 0 = 5.
+
+
+Example 2:
+
+
+Input: nums = [3,2,3,4,2]
+Output: [-2,-1,0,2,3]
+Explanation: For index i = 0, there is 1 element in the prefix and 3 distinct elements in the suffix. Thus, diff[0] = 1 - 3 = -2.
+For index i = 1, there are 2 distinct elements in the prefix and 3 distinct elements in the suffix. Thus, diff[1] = 2 - 3 = -1.
+For index i = 2, there are 2 distinct elements in the prefix and 2 distinct elements in the suffix. Thus, diff[2] = 2 - 2 = 0.
+For index i = 3, there are 3 distinct elements in the prefix and 1 distinct element in the suffix. Thus, diff[3] = 3 - 1 = 2.
+For index i = 4, there are 3 distinct elements in the prefix and no elements in the suffix. Thus, diff[4] = 3 - 0 = 3.
+
+
+
+Constraints:
+
+
+ 1 <= n == nums.length <= 50
+ 1 <= nums[i] <= 50
+
+",1.0,False,"class Solution {
+public:
+ vector distinctDifferenceArray(vector& nums) {
+
+ }
+};","class Solution {
+ public int[] distinctDifferenceArray(int[] nums) {
+
+ }
+}","class Solution(object):
+ def distinctDifferenceArray(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def distinctDifferenceArray(self, nums: List[int]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* distinctDifferenceArray(int* nums, int numsSize, int* returnSize){
+
+}","public class Solution {
+ public int[] DistinctDifferenceArray(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number[]}
+ */
+var distinctDifferenceArray = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer[]}
+def distinct_difference_array(nums)
+
+end","class Solution {
+ func distinctDifferenceArray(_ nums: [Int]) -> [Int] {
+
+ }
+}","func distinctDifferenceArray(nums []int) []int {
+
+}","object Solution {
+ def distinctDifferenceArray(nums: Array[Int]): Array[Int] = {
+
+ }
+}","class Solution {
+ fun distinctDifferenceArray(nums: IntArray): IntArray {
+
+ }
+}","impl Solution {
+ pub fn distinct_difference_array(nums: Vec) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer[]
+ */
+ function distinctDifferenceArray($nums) {
+
+ }
+}","function distinctDifferenceArray(nums: number[]): number[] {
+
+};","(define/contract (distinct-difference-array nums)
+ (-> (listof exact-integer?) (listof exact-integer?))
+
+ )","-spec distinct_difference_array(Nums :: [integer()]) -> [integer()].
+distinct_difference_array(Nums) ->
+ .","defmodule Solution do
+ @spec distinct_difference_array(nums :: [integer]) :: [integer]
+ def distinct_difference_array(nums) do
+
+ end
+end","class Solution {
+ List distinctDifferenceArray(List nums) {
+
+ }
+}",
+82,find-the-prefix-common-array-of-two-arrays,Find the Prefix Common Array of Two Arrays,2657.0,2766.0,"You are given two 0-indexed integer permutations 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 prefix common array of A
and B
.
+
+A sequence of n
integers is called a permutation if it contains all integers from 1
to n
exactly once.
+
+
+Example 1:
+
+
+Input: A = [1,3,2,4], B = [3,1,2,4]
+Output: [0,2,3,4]
+Explanation: At i = 0: no number is common, so C[0] = 0.
+At i = 1: 1 and 3 are common in A and B, so C[1] = 2.
+At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
+At i = 3: 1, 2, 3, and 4 are common in A and B, so C[3] = 4.
+
+
+Example 2:
+
+
+Input: A = [2,3,1], B = [3,1,2]
+Output: [0,1,3]
+Explanation: At i = 0: no number is common, so C[0] = 0.
+At i = 1: only 3 is common in A and B, so C[1] = 1.
+At i = 2: 1, 2, and 3 are common in A and B, so C[2] = 3.
+
+
+
+Constraints:
+
+
+ 1 <= A.length == B.length == n <= 50
+ 1 <= A[i], B[i] <= n
+ It is guaranteed that A and B are both a permutation of n integers.
+
+",2.0,False,"class Solution {
+public:
+ vector findThePrefixCommonArray(vector& A, vector& B) {
+
+ }
+};","class Solution {
+ public int[] findThePrefixCommonArray(int[] A, int[] B) {
+
+ }
+}","class Solution(object):
+ def findThePrefixCommonArray(self, A, B):
+ """"""
+ :type A: List[int]
+ :type B: List[int]
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def findThePrefixCommonArray(self, A: List[int], B: List[int]) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* findThePrefixCommonArray(int* A, int ASize, int* B, int BSize, int* returnSize){
+
+}","public class Solution {
+ public int[] FindThePrefixCommonArray(int[] A, int[] B) {
+
+ }
+}","/**
+ * @param {number[]} A
+ * @param {number[]} B
+ * @return {number[]}
+ */
+var findThePrefixCommonArray = function(A, B) {
+
+};","# @param {Integer[]} a
+# @param {Integer[]} b
+# @return {Integer[]}
+def find_the_prefix_common_array(a, b)
+
+end","class Solution {
+ func findThePrefixCommonArray(_ A: [Int], _ B: [Int]) -> [Int] {
+
+ }
+}","func findThePrefixCommonArray(A []int, B []int) []int {
+
+}","object Solution {
+ def findThePrefixCommonArray(A: Array[Int], B: Array[Int]): Array[Int] = {
+
+ }
+}","class Solution {
+ fun findThePrefixCommonArray(A: IntArray, B: IntArray): IntArray {
+
+ }
+}","impl Solution {
+ pub fn find_the_prefix_common_array(a: Vec, b: Vec) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $A
+ * @param Integer[] $B
+ * @return Integer[]
+ */
+ function findThePrefixCommonArray($A, $B) {
+
+ }
+}","function findThePrefixCommonArray(A: number[], B: number[]): number[] {
+
+};","(define/contract (find-the-prefix-common-array A B)
+ (-> (listof exact-integer?) (listof exact-integer?) (listof exact-integer?))
+
+ )","-spec find_the_prefix_common_array(A :: [integer()], B :: [integer()]) -> [integer()].
+find_the_prefix_common_array(A, B) ->
+ .","defmodule Solution do
+ @spec find_the_prefix_common_array(a :: [integer], b :: [integer]) :: [integer]
+ def find_the_prefix_common_array(a, b) do
+
+ end
+end","class Solution {
+ List findThePrefixCommonArray(List A, List B) {
+
+ }
+}",
+83,make-array-empty,Make Array Empty,2659.0,2765.0,"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 denoting the number of operations it takes to make nums
empty.
+
+
+Example 1:
+
+
+Input: nums = [3,4,-1]
+Output: 5
+
+
+
+
+
+ Operation |
+ Array |
+
+
+
+
+ 1 |
+ [4, -1, 3] |
+
+
+ 2 |
+ [-1, 3, 4] |
+
+
+ 3 |
+ [3, 4] |
+
+
+ 4 |
+ [4] |
+
+
+ 5 |
+ [] |
+
+
+
+
+Example 2:
+
+
+Input: nums = [1,2,4,3]
+Output: 5
+
+
+
+
+
+ Operation |
+ Array |
+
+
+
+
+ 1 |
+ [2, 4, 3] |
+
+
+ 2 |
+ [4, 3] |
+
+
+ 3 |
+ [3, 4] |
+
+
+ 4 |
+ [4] |
+
+
+ 5 |
+ [] |
+
+
+
+
+Example 3:
+
+
+Input: nums = [1,2,3]
+Output: 3
+
+
+
+
+
+ Operation |
+ Array |
+
+
+
+
+ 1 |
+ [2, 3] |
+
+
+ 2 |
+ [3] |
+
+
+ 3 |
+ [] |
+
+
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ -109 <= nums[i] <= 109
+ - All values in
nums
are distinct.
+
+",3.0,False,"class Solution {
+public:
+ long long countOperationsToEmptyArray(vector& nums) {
+
+ }
+};","class Solution {
+ public long countOperationsToEmptyArray(int[] nums) {
+
+ }
+}","class Solution(object):
+ def countOperationsToEmptyArray(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def countOperationsToEmptyArray(self, nums: List[int]) -> int:
+ ","long long countOperationsToEmptyArray(int* nums, int numsSize){
+
+}","public class Solution {
+ public long CountOperationsToEmptyArray(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var countOperationsToEmptyArray = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def count_operations_to_empty_array(nums)
+
+end","class Solution {
+ func countOperationsToEmptyArray(_ nums: [Int]) -> Int {
+
+ }
+}","func countOperationsToEmptyArray(nums []int) int64 {
+
+}","object Solution {
+ def countOperationsToEmptyArray(nums: Array[Int]): Long = {
+
+ }
+}","class Solution {
+ fun countOperationsToEmptyArray(nums: IntArray): Long {
+
+ }
+}","impl Solution {
+ pub fn count_operations_to_empty_array(nums: Vec) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function countOperationsToEmptyArray($nums) {
+
+ }
+}","function countOperationsToEmptyArray(nums: number[]): number {
+
+};","(define/contract (count-operations-to-empty-array nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec count_operations_to_empty_array(Nums :: [integer()]) -> integer().
+count_operations_to_empty_array(Nums) ->
+ .","defmodule Solution do
+ @spec count_operations_to_empty_array(nums :: [integer]) :: integer
+ def count_operations_to_empty_array(nums) do
+
+ end
+end","class Solution {
+ int countOperationsToEmptyArray(List nums) {
+
+ }
+}",
+84,maximum-number-of-fish-in-a-grid,Maximum Number of Fish in a Grid,2658.0,2764.0,"You are given a 0-indexed 2D matrix grid
of size m x n
, where (r, c)
represents:
+
+
+ - A land cell if
grid[r][c] = 0
, or
+ - A water cell containing
grid[r][c]
fish, if grid[r][c] > 0
.
+
+
+A fisher can start at any water cell (r, c)
and can do the following operations any number of times:
+
+
+ - Catch all the fish at cell
(r, c)
, or
+ - Move to any adjacent water cell.
+
+
+Return the maximum number of fish the fisher can catch if he chooses his starting cell optimally, or 0
if no water cell exists.
+
+An adjacent cell of the cell (r, c)
, is one of the cells (r, c + 1)
, (r, c - 1)
, (r + 1, c)
or (r - 1, c)
if it exists.
+
+
+Example 1:
+
+
+Input: grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]
+Output: 7
+Explanation: The fisher can start at cell (1,3)
and collect 3 fish, then move to cell (2,3)
and collect 4 fish.
+
+
+Example 2:
+
+
+Input: grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]
+Output: 1
+Explanation: The fisher can start at cells (0,0) or (3,3) and collect a single fish.
+
+
+
+Constraints:
+
+
+ m == grid.length
+ n == grid[i].length
+ 1 <= m, n <= 10
+ 0 <= grid[i][j] <= 10
+
+",2.0,False,"class Solution {
+public:
+ int findMaxFish(vector>& grid) {
+
+ }
+};","class Solution {
+ public int findMaxFish(int[][] grid) {
+
+ }
+}","class Solution(object):
+ def findMaxFish(self, grid):
+ """"""
+ :type grid: List[List[int]]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def findMaxFish(self, grid: List[List[int]]) -> int:
+ ","int findMaxFish(int** grid, int gridSize, int* gridColSize){
+
+}","public class Solution {
+ public int FindMaxFish(int[][] grid) {
+
+ }
+}","/**
+ * @param {number[][]} grid
+ * @return {number}
+ */
+var findMaxFish = function(grid) {
+
+};","# @param {Integer[][]} grid
+# @return {Integer}
+def find_max_fish(grid)
+
+end","class Solution {
+ func findMaxFish(_ grid: [[Int]]) -> Int {
+
+ }
+}","func findMaxFish(grid [][]int) int {
+
+}","object Solution {
+ def findMaxFish(grid: Array[Array[Int]]): Int = {
+
+ }
+}","class Solution {
+ fun findMaxFish(grid: Array): Int {
+
+ }
+}","impl Solution {
+ pub fn find_max_fish(grid: Vec>) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[][] $grid
+ * @return Integer
+ */
+ function findMaxFish($grid) {
+
+ }
+}","function findMaxFish(grid: number[][]): number {
+
+};","(define/contract (find-max-fish grid)
+ (-> (listof (listof exact-integer?)) exact-integer?)
+
+ )","-spec find_max_fish(Grid :: [[integer()]]) -> integer().
+find_max_fish(Grid) ->
+ .","defmodule Solution do
+ @spec find_max_fish(grid :: [[integer]]) :: integer
+ def find_max_fish(grid) do
+
+ end
+end","class Solution {
+ int findMaxFish(List> grid) {
+
+ }
+}",
+85,count-of-integers,Count of Integers,2719.0,2757.0,"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
.
+
+Note that digit_sum(x)
denotes the sum of the digits of x
.
+
+
+Example 1:
+
+
+Input: num1 = "1", num2 = "12", min_sum
= 1, max_sum = 8
+Output: 11
+Explanation: There are 11 integers whose sum of digits lies between 1 and 8 are 1,2,3,4,5,6,7,8,10,11, and 12. Thus, we return 11.
+
+
+Example 2:
+
+
+Input: num1 = "1", num2 = "5", min_sum
= 1, max_sum = 5
+Output: 5
+Explanation: The 5 integers whose sum of digits lies between 1 and 5 are 1,2,3,4, and 5. Thus, we return 5.
+
+
+
+Constraints:
+
+
+ 1 <= num1 <= num2 <= 1022
+ 1 <= min_sum <= max_sum <= 400
+
+",3.0,False,"class Solution {
+public:
+ int count(string num1, string num2, int min_sum, int max_sum) {
+
+ }
+};","class Solution {
+ public int count(String num1, String num2, int min_sum, int max_sum) {
+
+ }
+}","class Solution(object):
+ def count(self, num1, num2, min_sum, max_sum):
+ """"""
+ :type num1: str
+ :type num2: str
+ :type min_sum: int
+ :type max_sum: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def count(self, num1: str, num2: str, min_sum: int, max_sum: int) -> int:
+ ","int count(char * num1, char * num2, int min_sum, int max_sum){
+
+}","public class Solution {
+ public int Count(string num1, string num2, int min_sum, int max_sum) {
+
+ }
+}","/**
+ * @param {string} num1
+ * @param {string} num2
+ * @param {number} min_sum
+ * @param {number} max_sum
+ * @return {number}
+ */
+var count = function(num1, num2, min_sum, max_sum) {
+
+};","# @param {String} num1
+# @param {String} num2
+# @param {Integer} min_sum
+# @param {Integer} max_sum
+# @return {Integer}
+def count(num1, num2, min_sum, max_sum)
+
+end","class Solution {
+ func count(_ num1: String, _ num2: String, _ min_sum: Int, _ max_sum: Int) -> Int {
+
+ }
+}","func count(num1 string, num2 string, min_sum int, max_sum int) int {
+
+}","object Solution {
+ def count(num1: String, num2: String, min_sum: Int, max_sum: Int): Int = {
+
+ }
+}","class Solution {
+ fun count(num1: String, num2: String, min_sum: Int, max_sum: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn count(num1: String, num2: String, min_sum: i32, max_sum: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $num1
+ * @param String $num2
+ * @param Integer $min_sum
+ * @param Integer $max_sum
+ * @return Integer
+ */
+ function count($num1, $num2, $min_sum, $max_sum) {
+
+ }
+}","function count(num1: string, num2: string, min_sum: number, max_sum: number): number {
+
+};","(define/contract (count num1 num2 min_sum max_sum)
+ (-> string? string? exact-integer? exact-integer? exact-integer?)
+
+ )","-spec count(Num1 :: unicode:unicode_binary(), Num2 :: unicode:unicode_binary(), Min_sum :: integer(), Max_sum :: integer()) -> integer().
+count(Num1, Num2, Min_sum, Max_sum) ->
+ .","defmodule Solution do
+ @spec count(num1 :: String.t, num2 :: String.t, min_sum :: integer, max_sum :: integer) :: integer
+ def count(num1, num2, min_sum, max_sum) do
+
+ end
+end","class Solution {
+ int count(String num1, String num2, int min_sum, int max_sum) {
+
+ }
+}",
+87,extra-characters-in-a-string,Extra Characters in a String,2707.0,2755.0,"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 substrings.
+
+Return the minimum number of extra characters left over if you break up s
optimally.
+
+
+Example 1:
+
+
+Input: s = "leetscode", dictionary = ["leet","code","leetcode"]
+Output: 1
+Explanation: We can break s in two substrings: "leet" from index 0 to 3 and "code" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.
+
+
+
+Example 2:
+
+
+Input: s = "sayhelloworld", dictionary = ["hello","world"]
+Output: 3
+Explanation: We can break s in two substrings: "hello" from index 3 to 7 and "world" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.
+
+
+
+Constraints:
+
+
+ 1 <= s.length <= 50
+ 1 <= dictionary.length <= 50
+ 1 <= dictionary[i].length <= 50
+ dictionary[i]
and s
consists of only lowercase English letters
+ dictionary
contains distinct words
+
+",2.0,False,"class Solution {
+public:
+ int minExtraChar(string s, vector& dictionary) {
+
+ }
+};","class Solution {
+ public int minExtraChar(String s, String[] dictionary) {
+
+ }
+}","class Solution(object):
+ def minExtraChar(self, s, dictionary):
+ """"""
+ :type s: str
+ :type dictionary: List[str]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def minExtraChar(self, s: str, dictionary: List[str]) -> int:
+ ","int minExtraChar(char * s, char ** dictionary, int dictionarySize){
+
+}","public class Solution {
+ public int MinExtraChar(string s, string[] dictionary) {
+
+ }
+}","/**
+ * @param {string} s
+ * @param {string[]} dictionary
+ * @return {number}
+ */
+var minExtraChar = function(s, dictionary) {
+
+};","# @param {String} s
+# @param {String[]} dictionary
+# @return {Integer}
+def min_extra_char(s, dictionary)
+
+end","class Solution {
+ func minExtraChar(_ s: String, _ dictionary: [String]) -> Int {
+
+ }
+}","func minExtraChar(s string, dictionary []string) int {
+
+}","object Solution {
+ def minExtraChar(s: String, dictionary: Array[String]): Int = {
+
+ }
+}","class Solution {
+ fun minExtraChar(s: String, dictionary: Array): Int {
+
+ }
+}","impl Solution {
+ pub fn min_extra_char(s: String, dictionary: Vec) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $s
+ * @param String[] $dictionary
+ * @return Integer
+ */
+ function minExtraChar($s, $dictionary) {
+
+ }
+}","function minExtraChar(s: string, dictionary: string[]): number {
+
+};","(define/contract (min-extra-char s dictionary)
+ (-> string? (listof string?) exact-integer?)
+
+ )","-spec min_extra_char(S :: unicode:unicode_binary(), Dictionary :: [unicode:unicode_binary()]) -> integer().
+min_extra_char(S, Dictionary) ->
+ .","defmodule Solution do
+ @spec min_extra_char(s :: String.t, dictionary :: [String.t]) :: integer
+ def min_extra_char(s, dictionary) do
+
+ end
+end","class Solution {
+ int minExtraChar(String s, List dictionary) {
+
+ }
+}",
+88,maximum-strength-of-a-group,Maximum Strength of a Group,2708.0,2754.0,"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 nums[i0] * nums[i1] * nums[i2] * ... * nums[ik]
.
+
+Return the maximum strength of a group the teacher can create.
+
+
+Example 1:
+
+
+Input: nums = [3,-1,-5,2,5,-9]
+Output: 1350
+Explanation: One way to form a group of maximal strength is to group the students at indices [0,2,3,4,5]. Their strength is 3 * (-5) * 2 * 5 * (-9) = 1350, which we can show is optimal.
+
+
+Example 2:
+
+
+Input: nums = [-4,-5,-4]
+Output: 20
+Explanation: Group the students at indices [0, 1] . Then, we’ll have a resulting strength of 20. We cannot achieve greater strength.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 13
+ -9 <= nums[i] <= 9
+
+",2.0,False,"class Solution {
+public:
+ long long maxStrength(vector& nums) {
+
+ }
+};","class Solution {
+ public long maxStrength(int[] nums) {
+
+ }
+}","class Solution(object):
+ def maxStrength(self, nums):
+ """"""
+ :type nums: List[int]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maxStrength(self, nums: List[int]) -> int:
+ ","long long maxStrength(int* nums, int numsSize){
+
+}","public class Solution {
+ public long MaxStrength(int[] nums) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @return {number}
+ */
+var maxStrength = function(nums) {
+
+};","# @param {Integer[]} nums
+# @return {Integer}
+def max_strength(nums)
+
+end","class Solution {
+ func maxStrength(_ nums: [Int]) -> Int {
+
+ }
+}","func maxStrength(nums []int) int64 {
+
+}","object Solution {
+ def maxStrength(nums: Array[Int]): Long = {
+
+ }
+}","class Solution {
+ fun maxStrength(nums: IntArray): Long {
+
+ }
+}","impl Solution {
+ pub fn max_strength(nums: Vec) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @return Integer
+ */
+ function maxStrength($nums) {
+
+ }
+}","function maxStrength(nums: number[]): number {
+
+};","(define/contract (max-strength nums)
+ (-> (listof exact-integer?) exact-integer?)
+
+ )","-spec max_strength(Nums :: [integer()]) -> integer().
+max_strength(Nums) ->
+ .","defmodule Solution do
+ @spec max_strength(nums :: [integer]) :: integer
+ def max_strength(nums) do
+
+ end
+end","class Solution {
+ int maxStrength(List nums) {
+
+ }
+}",
+90,sum-multiples,Sum Multiples,2652.0,2752.0,"Given a positive integer n
, find the sum of all integers in the range [1, n]
inclusive that are divisible by 3
, 5
, or 7
.
+
+Return an integer denoting the sum of all numbers in the given range satisfying the constraint.
+
+
+Example 1:
+
+
+Input: n = 7
+Output: 21
+Explanation: Numbers in the range [1, 7]
that are divisible by 3
, 5,
or 7
are 3, 5, 6, 7
. The sum of these numbers is 21
.
+
+
+Example 2:
+
+
+Input: n = 10
+Output: 40
+Explanation: Numbers in the range [1, 10] that are
divisible by 3
, 5,
or 7
are 3, 5, 6, 7, 9, 10
. The sum of these numbers is 40.
+
+
+Example 3:
+
+
+Input: n = 9
+Output: 30
+Explanation: Numbers in the range [1, 9]
that are divisible by 3
, 5
, or 7
are 3, 5, 6, 7, 9
. The sum of these numbers is 30
.
+
+
+
+Constraints:
+
+
+",1.0,False,"class Solution {
+public:
+ int sumOfMultiples(int n) {
+
+ }
+};","class Solution {
+ public int sumOfMultiples(int n) {
+
+ }
+}","class Solution(object):
+ def sumOfMultiples(self, n):
+ """"""
+ :type n: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def sumOfMultiples(self, n: int) -> int:
+ ","int sumOfMultiples(int n){
+
+}","public class Solution {
+ public int SumOfMultiples(int n) {
+
+ }
+}","/**
+ * @param {number} n
+ * @return {number}
+ */
+var sumOfMultiples = function(n) {
+
+};","# @param {Integer} n
+# @return {Integer}
+def sum_of_multiples(n)
+
+end","class Solution {
+ func sumOfMultiples(_ n: Int) -> Int {
+
+ }
+}","func sumOfMultiples(n int) int {
+
+}","object Solution {
+ def sumOfMultiples(n: Int): Int = {
+
+ }
+}","class Solution {
+ fun sumOfMultiples(n: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn sum_of_multiples(n: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @return Integer
+ */
+ function sumOfMultiples($n) {
+
+ }
+}","function sumOfMultiples(n: number): number {
+
+};","(define/contract (sum-of-multiples n)
+ (-> exact-integer? exact-integer?)
+
+ )","-spec sum_of_multiples(N :: integer()) -> integer().
+sum_of_multiples(N) ->
+ .","defmodule Solution do
+ @spec sum_of_multiples(n :: integer) :: integer
+ def sum_of_multiples(n) do
+
+ end
+end","class Solution {
+ int sumOfMultiples(int n) {
+
+ }
+}",
+91,sliding-subarray-beauty,Sliding Subarray Beauty,2653.0,2751.0,"Given an integer array nums
containing n
integers, find the beauty of each subarray of size k
.
+
+The beauty of a subarray is the xth
smallest integer in the subarray if it is negative, or 0
if there are fewer than x
negative integers.
+
+Return an integer array containing n - k + 1
integers, which denote the beauty of the subarrays in order from the first index in the array.
+
+
+
+
+Example 1:
+
+
+Input: nums = [1,-1,-3,-2,3], k = 3, x = 2
+Output: [-1,-2,-2]
+Explanation: There are 3 subarrays with size k = 3.
+The first subarray is [1, -1, -3]
and the 2nd smallest negative integer is -1.
+The second subarray is [-1, -3, -2]
and the 2nd smallest negative integer is -2.
+The third subarray is [-3, -2, 3]
and the 2nd smallest negative integer is -2.
+
+Example 2:
+
+
+Input: nums = [-1,-2,-3,-4,-5], k = 2, x = 2
+Output: [-1,-2,-3,-4]
+Explanation: There are 4 subarrays with size k = 2.
+For [-1, -2]
, the 2nd smallest negative integer is -1.
+For [-2, -3]
, the 2nd smallest negative integer is -2.
+For [-3, -4]
, the 2nd smallest negative integer is -3.
+For [-4, -5]
, the 2nd smallest negative integer is -4.
+
+Example 3:
+
+
+Input: nums = [-3,1,2,-3,0,-3], k = 2, x = 1
+Output: [-3,0,-3,-3,-3]
+Explanation: There are 5 subarrays with size k = 2.
+For [-3, 1]
, the 1st smallest negative integer is -3.
+For [1, 2]
, there is no negative integer so the beauty is 0.
+For [2, -3]
, the 1st smallest negative integer is -3.
+For [-3, 0]
, the 1st smallest negative integer is -3.
+For [0, -3]
, the 1st smallest negative integer is -3.
+
+
+Constraints:
+
+
+ n == nums.length
+ 1 <= n <= 105
+ 1 <= k <= n
+ 1 <= x <= k
+ -50 <= nums[i] <= 50
+
+",2.0,False,"class Solution {
+public:
+ vector getSubarrayBeauty(vector& nums, int k, int x) {
+
+ }
+};","class Solution {
+ public int[] getSubarrayBeauty(int[] nums, int k, int x) {
+
+ }
+}","class Solution(object):
+ def getSubarrayBeauty(self, nums, k, x):
+ """"""
+ :type nums: List[int]
+ :type k: int
+ :type x: int
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def getSubarrayBeauty(self, nums: List[int], k: int, x: int) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* getSubarrayBeauty(int* nums, int numsSize, int k, int x, int* returnSize){
+
+}","public class Solution {
+ public int[] GetSubarrayBeauty(int[] nums, int k, int x) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number} k
+ * @param {number} x
+ * @return {number[]}
+ */
+var getSubarrayBeauty = function(nums, k, x) {
+
+};","# @param {Integer[]} nums
+# @param {Integer} k
+# @param {Integer} x
+# @return {Integer[]}
+def get_subarray_beauty(nums, k, x)
+
+end","class Solution {
+ func getSubarrayBeauty(_ nums: [Int], _ k: Int, _ x: Int) -> [Int] {
+
+ }
+}","func getSubarrayBeauty(nums []int, k int, x int) []int {
+
+}","object Solution {
+ def getSubarrayBeauty(nums: Array[Int], k: Int, x: Int): Array[Int] = {
+
+ }
+}","class Solution {
+ fun getSubarrayBeauty(nums: IntArray, k: Int, x: Int): IntArray {
+
+ }
+}","impl Solution {
+ pub fn get_subarray_beauty(nums: Vec, k: i32, x: i32) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer $k
+ * @param Integer $x
+ * @return Integer[]
+ */
+ function getSubarrayBeauty($nums, $k, $x) {
+
+ }
+}","function getSubarrayBeauty(nums: number[], k: number, x: number): number[] {
+
+};","(define/contract (get-subarray-beauty nums k x)
+ (-> (listof exact-integer?) exact-integer? exact-integer? (listof exact-integer?))
+
+ )","-spec get_subarray_beauty(Nums :: [integer()], K :: integer(), X :: integer()) -> [integer()].
+get_subarray_beauty(Nums, K, X) ->
+ .","defmodule Solution do
+ @spec get_subarray_beauty(nums :: [integer], k :: integer, x :: integer) :: [integer]
+ def get_subarray_beauty(nums, k, x) do
+
+ end
+end","class Solution {
+ List getSubarrayBeauty(List nums, int k, int x) {
+
+ }
+}",
+92,calculate-delayed-arrival-time,Calculate Delayed Arrival Time,2651.0,2748.0,"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-hours format.
+
+
+Example 1:
+
+
+Input: arrivalTime = 15, delayedTime = 5
+Output: 20
+Explanation: Arrival time of the train was 15:00 hours. It is delayed by 5 hours. Now it will reach at 15+5 = 20 (20:00 hours).
+
+
+Example 2:
+
+
+Input: arrivalTime = 13, delayedTime = 11
+Output: 0
+Explanation: Arrival time of the train was 13:00 hours. It is delayed by 11 hours. Now it will reach at 13+11=24 (Which is denoted by 00:00 in 24 hours format so return 0).
+
+
+
+Constraints:
+
+
+ 1 <= arrivaltime < 24
+ 1 <= delayedTime <= 24
+
+",1.0,False,"class Solution {
+public:
+ int findDelayedArrivalTime(int arrivalTime, int delayedTime) {
+
+ }
+};","class Solution {
+ public int findDelayedArrivalTime(int arrivalTime, int delayedTime) {
+
+ }
+}","class Solution(object):
+ def findDelayedArrivalTime(self, arrivalTime, delayedTime):
+ """"""
+ :type arrivalTime: int
+ :type delayedTime: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int:
+ ","int findDelayedArrivalTime(int arrivalTime, int delayedTime){
+
+}","public class Solution {
+ public int FindDelayedArrivalTime(int arrivalTime, int delayedTime) {
+
+ }
+}","/**
+ * @param {number} arrivalTime
+ * @param {number} delayedTime
+ * @return {number}
+ */
+var findDelayedArrivalTime = function(arrivalTime, delayedTime) {
+
+};","# @param {Integer} arrival_time
+# @param {Integer} delayed_time
+# @return {Integer}
+def find_delayed_arrival_time(arrival_time, delayed_time)
+
+end","class Solution {
+ func findDelayedArrivalTime(_ arrivalTime: Int, _ delayedTime: Int) -> Int {
+
+ }
+}","func findDelayedArrivalTime(arrivalTime int, delayedTime int) int {
+
+}","object Solution {
+ def findDelayedArrivalTime(arrivalTime: Int, delayedTime: Int): Int = {
+
+ }
+}","class Solution {
+ fun findDelayedArrivalTime(arrivalTime: Int, delayedTime: Int): Int {
+
+ }
+}","impl Solution {
+ pub fn find_delayed_arrival_time(arrival_time: i32, delayed_time: i32) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $arrivalTime
+ * @param Integer $delayedTime
+ * @return Integer
+ */
+ function findDelayedArrivalTime($arrivalTime, $delayedTime) {
+
+ }
+}","function findDelayedArrivalTime(arrivalTime: number, delayedTime: number): number {
+
+};","(define/contract (find-delayed-arrival-time arrivalTime delayedTime)
+ (-> exact-integer? exact-integer? exact-integer?)
+
+ )","-spec find_delayed_arrival_time(ArrivalTime :: integer(), DelayedTime :: integer()) -> integer().
+find_delayed_arrival_time(ArrivalTime, DelayedTime) ->
+ .","defmodule Solution do
+ @spec find_delayed_arrival_time(arrival_time :: integer, delayed_time :: integer) :: integer
+ def find_delayed_arrival_time(arrival_time, delayed_time) do
+
+ end
+end","class Solution {
+ int findDelayedArrivalTime(int arrivalTime, int delayedTime) {
+
+ }
+}",
+93,minimize-the-total-price-of-the-trips,Minimize the Total Price of the Trips,2646.0,2739.0,"There exists an undirected and unrooted tree with n
nodes indexed from 0
to n - 1
. You are given the integer n
and a 2D integer array edges
of length n - 1
, where edges[i] = [ai, bi]
indicates that there is an edge between nodes ai
and bi
in the tree.
+
+Each node has an associated price. You are given an integer array price
, where price[i]
is the price of the ith
node.
+
+The price sum of a given path is the sum of the prices of all nodes lying on that path.
+
+Additionally, you are given a 2D integer array trips
, where trips[i] = [starti, endi]
indicates that you start the ith
trip from the node starti
and travel to the node endi
by any path you like.
+
+Before performing your first trip, you can choose some non-adjacent nodes and halve the prices.
+
+Return the minimum total price sum to perform all the given trips.
+
+
+Example 1:
+
+
+Input: n = 4, edges = [[0,1],[1,2],[1,3]], price = [2,2,10,6], trips = [[0,3],[2,1],[2,3]]
+Output: 23
+Explanation: The diagram above denotes the tree after rooting it at node 2. The first part shows the initial tree and the second part shows the tree after choosing nodes 0, 2, and 3, and making their price half.
+For the 1st trip, we choose path [0,1,3]. The price sum of that path is 1 + 2 + 3 = 6.
+For the 2nd trip, we choose path [2,1]. The price sum of that path is 2 + 5 = 7.
+For the 3rd trip, we choose path [2,1,3]. The price sum of that path is 5 + 2 + 3 = 10.
+The total price sum of all trips is 6 + 7 + 10 = 23.
+It can be proven, that 23 is the minimum answer that we can achieve.
+
+
+Example 2:
+
+
+Input: n = 2, edges = [[0,1]], price = [2,2], trips = [[0,0]]
+Output: 1
+Explanation: The diagram above denotes the tree after rooting it at node 0. The first part shows the initial tree and the second part shows the tree after choosing node 0, and making its price half.
+For the 1st trip, we choose path [0]. The price sum of that path is 1.
+The total price sum of all trips is 1. It can be proven, that 1 is the minimum answer that we can achieve.
+
+
+
+Constraints:
+
+
+ 1 <= n <= 50
+ edges.length == n - 1
+ 0 <= ai, bi <= n - 1
+ edges
represents a valid tree.
+ price.length == n
+ price[i]
is an even integer.
+ 1 <= price[i] <= 1000
+ 1 <= trips.length <= 100
+ 0 <= starti, endi <= n - 1
+
+",3.0,False,"class Solution {
+public:
+ int minimumTotalPrice(int n, vector>& edges, vector& price, vector>& trips) {
+
+ }
+};","class Solution {
+ public int minimumTotalPrice(int n, int[][] edges, int[] price, int[][] trips) {
+
+ }
+}","class Solution(object):
+ def minimumTotalPrice(self, n, edges, price, trips):
+ """"""
+ :type n: int
+ :type edges: List[List[int]]
+ :type price: List[int]
+ :type trips: List[List[int]]
+ :rtype: int
+ """"""
+ ","class Solution:
+ def minimumTotalPrice(self, n: int, edges: List[List[int]], price: List[int], trips: List[List[int]]) -> int:
+ ","int minimumTotalPrice(int n, int** edges, int edgesSize, int* edgesColSize, int* price, int priceSize, int** trips, int tripsSize, int* tripsColSize){
+
+}","public class Solution {
+ public int MinimumTotalPrice(int n, int[][] edges, int[] price, int[][] trips) {
+
+ }
+}","/**
+ * @param {number} n
+ * @param {number[][]} edges
+ * @param {number[]} price
+ * @param {number[][]} trips
+ * @return {number}
+ */
+var minimumTotalPrice = function(n, edges, price, trips) {
+
+};","# @param {Integer} n
+# @param {Integer[][]} edges
+# @param {Integer[]} price
+# @param {Integer[][]} trips
+# @return {Integer}
+def minimum_total_price(n, edges, price, trips)
+
+end","class Solution {
+ func minimumTotalPrice(_ n: Int, _ edges: [[Int]], _ price: [Int], _ trips: [[Int]]) -> Int {
+
+ }
+}","func minimumTotalPrice(n int, edges [][]int, price []int, trips [][]int) int {
+
+}","object Solution {
+ def minimumTotalPrice(n: Int, edges: Array[Array[Int]], price: Array[Int], trips: Array[Array[Int]]): Int = {
+
+ }
+}","class Solution {
+ fun minimumTotalPrice(n: Int, edges: Array, price: IntArray, trips: Array): Int {
+
+ }
+}","impl Solution {
+ pub fn minimum_total_price(n: i32, edges: Vec>, price: Vec, trips: Vec>) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @param Integer[][] $edges
+ * @param Integer[] $price
+ * @param Integer[][] $trips
+ * @return Integer
+ */
+ function minimumTotalPrice($n, $edges, $price, $trips) {
+
+ }
+}","function minimumTotalPrice(n: number, edges: number[][], price: number[], trips: number[][]): number {
+
+};","(define/contract (minimum-total-price n edges price trips)
+ (-> exact-integer? (listof (listof exact-integer?)) (listof exact-integer?) (listof (listof exact-integer?)) exact-integer?)
+
+ )","-spec minimum_total_price(N :: integer(), Edges :: [[integer()]], Price :: [integer()], Trips :: [[integer()]]) -> integer().
+minimum_total_price(N, Edges, Price, Trips) ->
+ .","defmodule Solution do
+ @spec minimum_total_price(n :: integer, edges :: [[integer]], price :: [integer], trips :: [[integer]]) :: integer
+ def minimum_total_price(n, edges, price, trips) do
+
+ end
+end","class Solution {
+ int minimumTotalPrice(int n, List> edges, List price, List> trips) {
+
+ }
+}",
+95,minimum-additions-to-make-valid-string,Minimum Additions to Make Valid String,2645.0,2736.0,"Given a string word
to which you can insert letters "a", "b" or "c" anywhere and any number of times, return the minimum number of letters that must be inserted so that word
becomes valid.
+
+A string is called valid if it can be formed by concatenating the string "abc" several times.
+
+
+Example 1:
+
+
+Input: word = "b"
+Output: 2
+Explanation: Insert the letter "a" right before "b", and the letter "c" right next to "a" to obtain the valid string "abc".
+
+
+Example 2:
+
+
+Input: word = "aaa"
+Output: 6
+Explanation: Insert letters "b" and "c" next to each "a" to obtain the valid string "abcabcabc".
+
+
+Example 3:
+
+
+Input: word = "abc"
+Output: 0
+Explanation: word is already valid. No modifications are needed.
+
+
+
+Constraints:
+
+
+ 1 <= word.length <= 50
+ word
consists of letters "a", "b" and "c" only.
+
+",2.0,False,"class Solution {
+public:
+ int addMinimum(string word) {
+
+ }
+};","class Solution {
+ public int addMinimum(String word) {
+
+ }
+}","class Solution(object):
+ def addMinimum(self, word):
+ """"""
+ :type word: str
+ :rtype: int
+ """"""
+ ","class Solution:
+ def addMinimum(self, word: str) -> int:
+ ","int addMinimum(char * word){
+
+}","public class Solution {
+ public int AddMinimum(string word) {
+
+ }
+}","/**
+ * @param {string} word
+ * @return {number}
+ */
+var addMinimum = function(word) {
+
+};","# @param {String} word
+# @return {Integer}
+def add_minimum(word)
+
+end","class Solution {
+ func addMinimum(_ word: String) -> Int {
+
+ }
+}","func addMinimum(word string) int {
+
+}","object Solution {
+ def addMinimum(word: String): Int = {
+
+ }
+}","class Solution {
+ fun addMinimum(word: String): Int {
+
+ }
+}","impl Solution {
+ pub fn add_minimum(word: String) -> i32 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param String $word
+ * @return Integer
+ */
+ function addMinimum($word) {
+
+ }
+}","function addMinimum(word: string): number {
+
+};","(define/contract (add-minimum word)
+ (-> string? exact-integer?)
+
+ )","-spec add_minimum(Word :: unicode:unicode_binary()) -> integer().
+add_minimum(Word) ->
+ .","defmodule Solution do
+ @spec add_minimum(word :: String.t) :: integer
+ def add_minimum(word) do
+
+ end
+end","class Solution {
+ int addMinimum(String word) {
+
+ }
+}",
+96,maximum-or,Maximum OR,2680.0,2730.0,"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
times.
+
+Note that a | b
denotes the bitwise or between two integers a
and b
.
+
+
+Example 1:
+
+
+Input: nums = [12,9], k = 1
+Output: 30
+Explanation: If we apply the operation to index 1, our new array nums will be equal to [12,18]. Thus, we return the bitwise or of 12 and 18, which is 30.
+
+
+Example 2:
+
+
+Input: nums = [8,1,2], k = 2
+Output: 35
+Explanation: If we apply the operation twice on index 0, we yield a new array of [32,1,2]. Thus, we return 32|1|2 = 35.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 105
+ 1 <= nums[i] <= 109
+ 1 <= k <= 15
+
+",2.0,False,"class Solution {
+public:
+ long long maximumOr(vector& nums, int k) {
+
+ }
+};","class Solution {
+ public long maximumOr(int[] nums, int k) {
+
+ }
+}","class Solution(object):
+ def maximumOr(self, nums, k):
+ """"""
+ :type nums: List[int]
+ :type k: int
+ :rtype: int
+ """"""
+ ","class Solution:
+ def maximumOr(self, nums: List[int], k: int) -> int:
+ ","long long maximumOr(int* nums, int numsSize, int k){
+
+}","public class Solution {
+ public long MaximumOr(int[] nums, int k) {
+
+ }
+}","/**
+ * @param {number[]} nums
+ * @param {number} k
+ * @return {number}
+ */
+var maximumOr = function(nums, k) {
+
+};","# @param {Integer[]} nums
+# @param {Integer} k
+# @return {Integer}
+def maximum_or(nums, k)
+
+end","class Solution {
+ func maximumOr(_ nums: [Int], _ k: Int) -> Int {
+
+ }
+}","func maximumOr(nums []int, k int) int64 {
+
+}","object Solution {
+ def maximumOr(nums: Array[Int], k: Int): Long = {
+
+ }
+}","class Solution {
+ fun maximumOr(nums: IntArray, k: Int): Long {
+
+ }
+}","impl Solution {
+ pub fn maximum_or(nums: Vec, k: i32) -> i64 {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer[] $nums
+ * @param Integer $k
+ * @return Integer
+ */
+ function maximumOr($nums, $k) {
+
+ }
+}","function maximumOr(nums: number[], k: number): number {
+
+};","(define/contract (maximum-or nums k)
+ (-> (listof exact-integer?) exact-integer? exact-integer?)
+
+ )","-spec maximum_or(Nums :: [integer()], K :: integer()) -> integer().
+maximum_or(Nums, K) ->
+ .","defmodule Solution do
+ @spec maximum_or(nums :: [integer], k :: integer) :: integer
+ def maximum_or(nums, k) do
+
+ end
+end","class Solution {
+ int maximumOr(List nums, int k) {
+
+ }
+}",
+99,minimum-reverse-operations,Minimum Reverse Operations,2612.0,2726.0,"You are given an integer n
and an integer p
in the range [0, n - 1]
. Representing a 0-indexed array arr
of length n
where all positions are set to 0
's, except position p
which is set to 1
.
+
+You are also given an integer array banned
containing some positions from the array. For the ith position in banned
, arr[banned[i]] = 0
, and banned[i] != p
.
+
+You can perform multiple operations on arr
. In an operation, you can choose a subarray with size k
and reverse the subarray. However, the 1
in arr
should never go to any of the positions in banned
. In other words, after each operation arr[banned[i]]
remains 0
.
+
+Return an array ans
where for each i
from [0, n - 1]
, ans[i]
is the minimum number of reverse operations needed to bring the 1
to position i
in arr, or -1
if it is impossible.
+
+
+ - A subarray is a contiguous non-empty sequence of elements within an array.
+ - The values of
ans[i]
are independent for all i
's.
+ - The reverse of an array is an array containing the values in reverse order.
+
+
+
+Example 1:
+
+
+Input: n = 4, p = 0, banned = [1,2], k = 4
+Output: [0,-1,-1,1]
+Explanation: In this case k = 4
so there is only one possible reverse operation we can perform, which is reversing the whole array. Initially, 1 is placed at position 0 so the amount of operations we need for position 0 is 0
. We can never place a 1 on the banned positions, so the answer for positions 1 and 2 is -1
. Finally, with one reverse operation we can bring the 1 to index 3, so the answer for position 3 is 1
.
+
+
+Example 2:
+
+
+Input: n = 5, p = 0, banned = [2,4], k = 3
+Output: [0,-1,-1,-1,-1]
+Explanation: In this case the 1 is initially at position 0, so the answer for that position is 0
. We can perform reverse operations of size 3. The 1 is currently located at position 0, so we need to reverse the subarray [0, 2]
for it to leave that position, but reversing that subarray makes position 2 have a 1, which shouldn't happen. So, we can't move the 1 from position 0, making the result for all the other positions -1
.
+
+
+Example 3:
+
+
+Input: n = 4, p = 2, banned = [0,1,3], k = 1
+Output: [-1,-1,0,-1]
+Explanation: In this case we can only perform reverse operations of size 1. So the 1 never changes its position.
+
+
+
+Constraints:
+
+
+ 1 <= n <= 105
+ 0 <= p <= n - 1
+ 0 <= banned.length <= n - 1
+ 0 <= banned[i] <= n - 1
+ 1 <= k <= n
+ banned[i] != p
+ - all values in
banned
are unique
+
+",3.0,False,"class Solution {
+public:
+ vector minReverseOperations(int n, int p, vector& banned, int k) {
+
+ }
+};","class Solution {
+ public int[] minReverseOperations(int n, int p, int[] banned, int k) {
+
+ }
+}","class Solution(object):
+ def minReverseOperations(self, n, p, banned, k):
+ """"""
+ :type n: int
+ :type p: int
+ :type banned: List[int]
+ :type k: int
+ :rtype: List[int]
+ """"""
+ ","class Solution:
+ def minReverseOperations(self, n: int, p: int, banned: List[int], k: int) -> List[int]:
+ ","/**
+ * Note: The returned array must be malloced, assume caller calls free().
+ */
+int* minReverseOperations(int n, int p, int* banned, int bannedSize, int k, int* returnSize){
+
+}","public class Solution {
+ public int[] MinReverseOperations(int n, int p, int[] banned, int k) {
+
+ }
+}","/**
+ * @param {number} n
+ * @param {number} p
+ * @param {number[]} banned
+ * @param {number} k
+ * @return {number[]}
+ */
+var minReverseOperations = function(n, p, banned, k) {
+
+};","# @param {Integer} n
+# @param {Integer} p
+# @param {Integer[]} banned
+# @param {Integer} k
+# @return {Integer[]}
+def min_reverse_operations(n, p, banned, k)
+
+end","class Solution {
+ func minReverseOperations(_ n: Int, _ p: Int, _ banned: [Int], _ k: Int) -> [Int] {
+
+ }
+}","func minReverseOperations(n int, p int, banned []int, k int) []int {
+
+}","object Solution {
+ def minReverseOperations(n: Int, p: Int, banned: Array[Int], k: Int): Array[Int] = {
+
+ }
+}","class Solution {
+ fun minReverseOperations(n: Int, p: Int, banned: IntArray, k: Int): IntArray {
+
+ }
+}","impl Solution {
+ pub fn min_reverse_operations(n: i32, p: i32, banned: Vec, k: i32) -> Vec {
+
+ }
+}","class Solution {
+
+ /**
+ * @param Integer $n
+ * @param Integer $p
+ * @param Integer[] $banned
+ * @param Integer $k
+ * @return Integer[]
+ */
+ function minReverseOperations($n, $p, $banned, $k) {
+
+ }
+}","function minReverseOperations(n: number, p: number, banned: number[], k: number): number[] {
+
+};","(define/contract (min-reverse-operations n p banned k)
+ (-> exact-integer? exact-integer? (listof exact-integer?) exact-integer? (listof exact-integer?))
+
+ )","-spec min_reverse_operations(N :: integer(), P :: integer(), Banned :: [integer()], K :: integer()) -> [integer()].
+min_reverse_operations(N, P, Banned, K) ->
+ .","defmodule Solution do
+ @spec min_reverse_operations(n :: integer, p :: integer, banned :: [integer], k :: integer) :: [integer]
+ def min_reverse_operations(n, p, banned, k) do
+
+ end
+end","class Solution {
+ List minReverseOperations(int n, int p, List banned, int k) {
+
+ }
+}",
+104,sum-of-distances,Sum of Distances,2615.0,2721.0,"You are given a 0-indexed integer array nums
. There exists an array arr
of length nums.length
, where arr[i]
is the sum of |i - j|
over all j
such that nums[j] == nums[i]
and j != i
. If there is no such j
, set arr[i]
to be 0
.
+
+Return the array arr
.
+
+
+Example 1:
+
+
+Input: nums = [1,3,1,1,2]
+Output: [5,0,3,4,0]
+Explanation:
+When i = 0, nums[0] == nums[2] and nums[0] == nums[3]. Therefore, arr[0] = |0 - 2| + |0 - 3| = 5.
+When i = 1, arr[1] = 0 because there is no other index with value 3.
+When i = 2, nums[2] == nums[0] and nums[2] == nums[3]. Therefore, arr[2] = |2 - 0| + |2 - 3| = 3.
+When i = 3, nums[3] == nums[0] and nums[3] == nums[2]. Therefore, arr[3] = |3 - 0| + |3 - 2| = 4.
+When i = 4, arr[4] = 0 because there is no other index with value 2.
+
+
+
+Example 2:
+
+
+Input: nums = [0,5,3]
+Output: [0,0,0]
+Explanation: Since each element in nums is distinct, arr[i] = 0 for all i.
+
+
+
+Constraints:
+
+
+ 1 <= nums.length <= 10