instruction_seed
stringlengths
308
3.48k
source
stringclasses
1 value
embeddings
listlengths
1.02k
1.02k
mean_positive_score
float64
0.8
0.86
mean_negative_score
float64
0.74
0.8
difference_score
float64
0.05
0.07
Please write the following solution using Groovy: Given an integer array `arr`, return _the length of a maximum size turbulent subarray of_ `arr`. A subarray is **turbulent** if the comparison sign flips between each adjacent pair of elements in the subarray. More formally, a subarray `[arr[i], arr[i + 1], ..., arr[j...
dolphin
[ 0.01744816266000271, 0.029503412544727325, -0.030083948746323586, -0.028337985277175903, 0.0327809639275074, -0.030285244807600975, -0.04895428568124771, 0.03555143624544144, 0.030698202550411224, -0.01572415977716446, 0.0263790562748909, 0.015177025459706783, -0.02482156828045845, -0.0086...
0.84706
0.791912
0.055148
Please explain the following problem in detail and provide code in Scheme: Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`. A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element...
dolphin
[ 0.015695683658123016, 0.03186534345149994, -0.028862038627266884, -0.01997401751577854, 0.03070545569062233, -0.009698351845145226, -0.03052511066198349, 0.028301790356636047, 0.029600735753774643, 0.005020462907850742, 0.04129725694656372, 0.03432133421301842, -0.03286857530474663, 0.0079...
0.843996
0.772428
0.071568
Please focus on the efficiency of this problem and provide code in Julia: Given a **0-indexed** integer array `nums`, find a **0-indexed** integer array `answer` where: * `answer.length == nums.length`. * `answer[i] = |leftSum[i] - rightSum[i]|`. Where: * `leftSum[i]` is the sum of elements to the left of the ...
dolphin
[ 0.012275285087525845, 0.04041182994842529, -0.03598283976316452, -0.036427464336156845, 0.03318070247769356, -0.018322870135307312, -0.02127365954220295, 0.06207520142197609, 0.051347363740205765, -0.011280525475740433, 0.02979358471930027, 0.020800955593585968, -0.03527047857642174, -0.01...
0.847709
0.792869
0.05484
Please focus on the algorithm of this problem and provide code in c++: Alice has `n` candies, where the `ith` candy is of type `candyType[i]`. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat `n / 2` of the candies she has (`n` is always even). Alice likes he...
dolphin
[ 0.00765305757522583, 0.016747109591960907, -0.006321577355265617, -0.032137755304574966, 0.0182388536632061, -0.017061872407794, -0.04095705226063728, 0.11027880758047104, 0.01785183884203434, -0.02932473085820675, 0.027559367939829826, 0.04162954166531563, -0.018867885693907738, -0.005442...
0.837702
0.780164
0.057538
Please write the following solution using PHP: Given an integer array `nums` and two integers `k` and `p`, return _the number of **distinct subarrays** which have **at most**_ `k` _elements divisible by_ `p`. Two arrays `nums1` and `nums2` are said to be **distinct** if: * They are of **different** lengths, or * ...
dolphin
[ 0.021015087142586708, 0.03313877433538437, -0.030700301751494408, -0.016516337171196938, 0.03407717123627663, -0.029754694551229477, -0.02738075517117977, 0.06235503777861595, 0.0397949293255806, 0.008007288910448551, 0.037346892058849335, 0.02245158888399601, -0.03621961921453476, 0.00902...
0.83922
0.780518
0.058702
Please write the following solution using Objective-C: Given an integer array `nums`, return the sum of `floor(nums[i] / nums[j])` for all pairs of indices `0 <= i, j < nums.length` in the array. Since the answer may be too large, return it **modulo** `109 + 7`. The `floor()` function returns the integer part of the d...
dolphin
[ 0.004068012349307537, 0.029718676581978798, -0.04395908862352371, -0.02951708622276783, 0.04703644663095474, -0.02893560193479061, -0.036679934710264206, 0.04575403779745102, 0.035314589738845825, -0.013988349586725235, 0.037461213767528534, 0.011248216032981873, -0.05330047756433487, -0.0...
0.825823
0.771724
0.054099
Please focus on the algorithm of this problem and provide code in Elixir: You are given an integer array `nums` of length `n`, and an integer array `queries` of length `m`. Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the **maximum** size of a **subsequence** that you can take from_ `nums` _such ...
dolphin
[ 0.01319749467074871, 0.017088161781430244, -0.02385745942592621, -0.036286208778619766, 0.029997948557138443, -0.011446256190538406, -0.017852889373898506, 0.0561523512005806, 0.022148024290800095, -0.01610591821372509, 0.025542395189404488, 0.02750387042760849, -0.026346366852521896, -0.0...
0.854162
0.796928
0.057234
Please write the following solution using java: Given an integer array `nums` and a positive integer `k`, return _the most **competitive** subsequence of_ `nums` _of size_ `k`. An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array. We define that a subsequence...
dolphin
[ 0.01707858219742775, 0.049223147332668304, -0.02061595395207405, -0.020120985805988312, 0.0415579192340374, -0.016776710748672485, -0.027861520648002625, 0.04017341136932373, 0.04003732651472092, -0.021686937659978867, 0.02530824765563011, 0.022734614089131355, -0.042213328182697296, -0.00...
0.843861
0.778489
0.065373
Please explain the reasoning behind the following solution and provide code in C#: You have a list `arr` of all integers in the range `[1, n]` sorted in a strictly increasing order. Apply the following algorithm on `arr`: * Starting from left to right, remove the first number and every other number afterward until y...
dolphin
[ 0.033950574696063995, 0.03569180518388748, -0.02062358520925045, -0.047406308352947235, 0.02502506412565708, -0.04661191627383232, -0.039233654737472534, 0.08028005808591843, 0.04229697957634926, -0.019864534959197044, 0.017975470051169395, 0.015504096634685993, -0.04149679094552994, -0.01...
0.840584
0.782588
0.057995
Please write the following solution using Groovy: Given a single-digit integer `d` and two integers `low` and `high`, return _the number of times that_ `d` _occurs as a digit in all integers in the inclusive range_ `[low, high]`. **Example 1:** **Input:** d = 1, low = 1, high = 13 **Output:** 6 **Explanation:** The d...
dolphin
[ -0.000025452189220231958, 0.007838561199605465, -0.027905236929655075, -0.031103845685720444, 0.035959355533123016, -0.020079607143998146, -0.02291145920753479, 0.045885808765888214, 0.019452108070254326, -0.004522768314927816, 0.015800969675183296, 0.03202183544635773, -0.02266458235681057,...
0.832933
0.777996
0.054938
Please explain the following problem in detail and provide code in Clojure: Given an unsorted array of integers `nums`, return _the length of the longest consecutive elements sequence._ You must write an algorithm that runs in `O(n)` time. **Example 1:** **Input:** nums = \[100,4,200,1,3,2\] **Output:** 4 **Explanat...
dolphin
[ 0.019972993060946465, 0.024376308545470238, -0.02679571509361267, -0.03817550837993622, 0.03214314207434654, -0.02886483445763588, -0.0329546257853508, 0.04626540467143059, 0.04093431681394577, -0.018271828070282936, 0.02788691222667694, 0.027540873736143112, -0.029637441039085388, -0.0068...
0.836349
0.779159
0.05719
Please explain the following problem in detail and provide code in Object Pascal: A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`. Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is ...
dolphin
[ 0.01920074038207531, 0.032516468316316605, -0.023576252162456512, -0.012083271518349648, 0.04811122640967369, -0.015462243929505348, -0.036166343837976456, 0.06415849924087524, 0.036490581929683685, -0.01676090434193611, 0.02605261094868183, 0.033216070383787155, -0.026909582316875458, -0....
0.842456
0.778914
0.063542
Please focus on the algorithm of this problem and provide code in c++: You are given an integer array `nums` (**0-indexed**). In one operation, you can choose an element of the array and increment it by `1`. * For example, if `nums = [1,2,3]`, you can choose to increment `nums[1]` to make `nums = [1,**3**,3]`. Retu...
dolphin
[ 0.011344931088387966, 0.043193891644477844, -0.010474433191120625, -0.02234750986099243, 0.029005318880081177, -0.011530394665896893, -0.03916076570749283, 0.11662838608026505, 0.026359496638178825, -0.02082652784883976, 0.022773021832108498, 0.005712992046028376, -0.03090890310704708, -0....
0.845294
0.784601
0.060692
Please write the following solution using Elixir: You are given two positive integer arrays `nums` and `target`, of the same length. In one operation, you can choose any two **distinct** indices `i` and `j` where `0 <= i, j < nums.length` and: * set `nums[i] = nums[i] + 2` and * set `nums[j] = nums[j] - 2`. Two ...
dolphin
[ 0.023645849898457527, 0.03004755638539791, -0.02516345866024494, -0.02519499883055687, 0.04463895037770271, -0.01202794536948204, -0.03146609291434288, 0.06488100439310074, 0.03348303213715553, -0.015235347673296928, 0.013253971934318542, 0.0045696753077209, -0.02905913069844246, -0.020538...
0.859073
0.79743
0.061643
Please write the following solution using R: You are given a **0-indexed** array `nums` of length `n`, consisting of non-negative integers. For each index `i` from `0` to `n - 1`, you must determine the size of the **minimum sized** non-empty subarray of `nums` starting at `i` (**inclusive**) that has the **maximum** p...
dolphin
[ 0.007159998640418053, 0.027607101947069168, -0.03320954367518425, -0.011369552463293076, 0.02924816496670246, -0.018400922417640686, -0.042409490793943405, 0.05574190989136696, 0.047243114560842514, -0.0009175226441584527, 0.022043908014893532, 0.02909757010638714, -0.03612028807401657, -0...
0.845034
0.78199
0.063045
Please explain the following problem in detail and provide code in PHP: Given an array of **distinct** integers `arr`, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect to pairs), each pair `[a, b]` follows * `a, b` are from `...
dolphin
[ 0.02812565118074417, 0.041399016976356506, -0.020825572311878204, -0.029710259288549423, 0.04983897507190704, -0.021859537810087204, -0.03525569662451744, 0.05455601587891579, 0.04365166649222374, -0.022510673850774765, 0.025202009826898575, -0.0011619289871305227, -0.04321608319878578, 0....
0.831027
0.777165
0.053862
Please write the following solution using Objective-C: Given an integer array `nums`, return `true` if any value appears **at least twice** in the array, and return `false` if every element is distinct. **Example 1:** **Input:** nums = \[1,2,3,1\] **Output:** true **Example 2:** **Input:** nums = \[1,2,3,4\] **Outp...
dolphin
[ 0.01542274747043848, 0.018295789137482643, -0.022227520123124123, -0.02202075906097889, 0.03974093869328499, -0.03679661452770233, -0.005785709712654352, 0.07858550548553467, 0.043141260743141174, -0.017578525468707085, 0.020678596571087837, 0.001120331697165966, -0.023502277210354805, -0....
0.829926
0.775096
0.054831
Please write the following solution using Kotlin: Given an array of integers `nums` and an integer `k`, return _the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than_ `k`. **Example 1:** **Input:** nums = \[10,5,2,6\], k = 100 **Output:** 8 **Explanation:** The...
dolphin
[ 0.023406879976391792, 0.033879611641168594, -0.026995724067091942, -0.01446621771901846, 0.05193086713552475, -0.014944140799343586, -0.03324702009558678, 0.05439982935786247, 0.038830555975437164, -0.0025718228425830603, 0.005379461217671633, 0.03536755591630936, -0.022423526272177696, -0...
0.84403
0.782273
0.061757
Please explain the following problem in detail and provide code in ANSI C: You are given two positive integers `n` and `k`. A factor of an integer `n` is defined as an integer `i` where `n % i == 0`. Consider a list of all factors of `n` sorted in **ascending order**, return _the_ `kth` _factor_ in this list or return...
dolphin
[ 0.038727205246686935, 0.06273524463176727, -0.018398910760879517, -0.0367618054151535, 0.02843511290848255, -0.021378709003329277, -0.012975671328604221, 0.07900683581829071, 0.03652459383010864, -0.009218355640769005, 0.022709626704454422, 0.03153672441840172, -0.051957372575998306, -0.00...
0.833669
0.771896
0.061774
Please focus on the efficiency of this problem and provide code in ANSI C: Given an array `arr` of integers, check if there exist two indices `i` and `j` such that : * `i != j` * `0 <= i, j < arr.length` * `arr[i] == 2 * arr[j]` **Example 1:** **Input:** arr = \[10,2,5,3\] **Output:** true **Explanation:** For...
dolphin
[ 0.01637713983654976, 0.03661482036113739, -0.02817629650235176, -0.03632982447743416, 0.03260672092437744, -0.02794448845088482, -0.02893969416618347, 0.09893510490655899, 0.02688426524400711, -0.019807232543826103, 0.019104555249214172, -0.0004947003326378763, -0.031033465638756752, -0.04...
0.845324
0.781391
0.063933
Please explain the following problem in detail and provide code in Kotlin: An array `nums` of length `n` is **beautiful** if: * `nums` is a permutation of the integers in the range `[1, n]`. * For every `0 <= i < j < n`, there is no index `k` with `i < k < j` where `2 * nums[k] == nums[i] + nums[j]`. Given the in...
dolphin
[ 0.024100661277770996, 0.03315979987382889, -0.016849655658006668, -0.03094300627708435, 0.0423966683447361, -0.033327337354421616, -0.033039841800928116, 0.05335225909948349, 0.03578192740678787, -0.008171414025127888, 0.029964976012706757, 0.04091730713844299, -0.029702842235565186, -0.01...
0.841364
0.77899
0.062373
Please explain the following problem in detail and provide code in SmallTalk: Given an integer array `nums` that may contain duplicates, return _all possible_ _subsets_ _(the power set)_. The solution set **must not** contain duplicate subsets. Return the solution in **any order**. **Example 1:** **Input:** nums = \...
dolphin
[ 0.03612593933939934, 0.02850930765271187, -0.020024890080094337, -0.01736808381974697, 0.04643351957201958, -0.040617745369672775, -0.005221438594162464, 0.05350964143872261, 0.05470100790262222, -0.02724502608180046, 0.041503943502902985, 0.019596748054027557, -0.04318387433886528, -0.031...
0.846055
0.791949
0.054106
Please explain the following problem in detail and provide code in java: Given an array of **distinct** integers `candidates` and a target integer `target`, return _a list of all **unique combinations** of_ `candidates` _where the chosen numbers sum to_ `target`_._ You may return the combinations in **any order**. The...
dolphin
[ 0.022644521668553352, 0.04145181179046631, -0.021619638428092003, -0.020313527435064316, 0.047251708805561066, -0.017489418387413025, -0.022596335038542747, 0.024450674653053284, 0.028990987688302994, -0.011513820849359035, 0.02676624245941639, 0.02296634018421173, -0.025729471817612648, -...
0.83643
0.782672
0.053758
Please write the following solution using Scala: Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums = \[3,2,3\] **Output:** 3 ...
dolphin
[ 0.016325363889336586, 0.026430457830429077, -0.031502582132816315, -0.01893668808043003, 0.04063158854842186, -0.033286385238170624, -0.02267579734325409, 0.048609599471092224, 0.020693426951766014, -0.005756499245762825, 0.02175176329910755, 0.025721121579408646, -0.010517925024032593, 0....
0.841458
0.782637
0.058821
Please write the following solution using ANSI C: You are given an array of transactions `transactions` where `transactions[i] = [fromi, toi, amounti]` indicates that the person with `ID = fromi` gave `amounti $` to the person with `ID = toi`. Return _the minimum number of transactions required to settle the debt_. *...
dolphin
[ 0.028468018397688866, 0.02987241931259632, -0.021003831177949905, -0.037158094346523285, 0.04473041370511055, -0.022272448986768723, -0.02237093262374401, 0.07087060064077377, 0.03555425629019737, -0.019620073959231377, 0.021694689989089966, 0.007729194592684507, -0.028082897886633873, -0....
0.848386
0.791262
0.057125
Please focus on the algorithm of this problem and provide code in Object Pascal: Given an integer array `nums` and two integers `lower` and `upper`, return _the number of range sums that lie in_ `[lower, upper]` _inclusive_. Range sum `S(i, j)` is defined as the sum of the elements in `nums` between indices `i` and `j...
dolphin
[ -0.010966191068291664, 0.01978834718465805, -0.033798690885305405, -0.012497356161475182, 0.04579160362482071, -0.013676142320036888, -0.023349393159151077, 0.05947349965572357, 0.03654065355658531, -0.004441593773663044, 0.03412913531064987, 0.05497918277978897, -0.026678696274757385, -0....
0.837198
0.780636
0.056561
Please explain the following problem in detail and provide code in Scala: You are given two integers `n` and `maxValue`, which are used to describe an **ideal** array. A **0-indexed** integer array `arr` of length `n` is considered **ideal** if the following conditions hold: * Every `arr[i]` is a value from `1` to ...
dolphin
[ 0.036965664476156235, 0.023674728348851204, -0.02451433427631855, -0.0227534007281065, 0.04087730124592781, -0.04375680536031723, -0.046388015151023865, 0.04104018211364746, 0.018237974494695663, -0.01969532109797001, 0.037597957998514175, 0.030788417905569077, -0.03386521711945534, -0.017...
0.839766
0.777865
0.061901
Please write the following solution using ANSI C: Given an integer array `arr`, return _the length of a maximum size turbulent subarray of_ `arr`. A subarray is **turbulent** if the comparison sign flips between each adjacent pair of elements in the subarray. More formally, a subarray `[arr[i], arr[i + 1], ..., arr[j...
dolphin
[ 0.020293021574616432, 0.03721826151013374, -0.02368939109146595, -0.027454545721411705, 0.027537107467651367, -0.026726631447672844, -0.057235389947891235, 0.06643205136060715, 0.028393372893333435, -0.013435699976980686, 0.027140004560351372, 0.008226890116930008, -0.039778780192136765, -...
0.84783
0.778727
0.069103
Please explain the following problem in detail and provide code in javascript: Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element t...
dolphin
[ 0.01805192604660988, 0.03388643637299538, -0.03231309354305267, -0.020948784425854683, 0.05076003447175026, -0.001291379565373063, -0.031180312857031822, 0.04337907209992409, 0.02738230861723423, -0.0057743145152926445, 0.023651987314224243, 0.029777107760310173, -0.03134031966328621, -0.0...
0.843101
0.788406
0.054695
Please focus on the functionality of this problem and provide code in Clojure: Given an integer array `nums` and two integers `left` and `right`, return _the number of contiguous non-empty **subarrays** such that the value of the maximum array element in that subarray is in the range_ `[left, right]`. The test cases a...
dolphin
[ 0.030616382136940956, 0.03102237544953823, -0.038073502480983734, -0.01944352686405182, 0.024076763540506363, -0.0028547458350658417, -0.027331078425049782, 0.04452848061919212, 0.03478876128792763, -0.01000763289630413, 0.036177705973386765, 0.049625977873802185, -0.02444697730243206, -0....
0.847133
0.790963
0.05617
Please explain the reasoning behind the following solution and provide code in Kotlin: You are given an `m x n` matrix `M` initialized with all `0`'s and an array of operations `ops`, where `ops[i] = [ai, bi]` means `M[x][y]` should be incremented by one for all `0 <= x < ai` and `0 <= y < bi`. Count and return _the n...
dolphin
[ 0.02943398989737034, 0.017527049407362938, -0.02023576758801937, -0.04126434400677681, 0.04375828057527542, -0.02712235227227211, -0.04154055193066597, 0.061245519667863846, 0.03127144277095795, -0.01688643917441368, 0.008526495657861233, 0.02621295489370823, -0.032525818794965744, -0.0141...
0.847902
0.791997
0.055905
Please focus on the efficiency of this problem and provide code in Object Pascal: You are given a **0-indexed** `m x n` integer matrix `grid` and an integer `k`. You are currently at position `(0, 0)` and you want to reach position `(m - 1, n - 1)` moving only **down** or **right**. Return _the number of paths where t...
dolphin
[ 0.012407603673636913, 0.02885410189628601, -0.018810268491506577, -0.0379989929497242, 0.04237153381109238, -0.04384125769138336, -0.012505763210356236, 0.059034671634435654, 0.0359945185482502, -0.005251087713986635, 0.028331950306892395, 0.015608607791364193, -0.0215328149497509, -0.0152...
0.850846
0.791994
0.058852
Please explain the following problem in detail and provide code in Scala: Given an integer array `nums` and an integer `k`, return _the number of **subarrays** of_ `nums` _where the greatest common divisor of the subarray's elements is_ `k`. A **subarray** is a contiguous non-empty sequence of elements within an array...
dolphin
[ 0.02525738626718521, 0.03960997238755226, -0.0335540808737278, -0.023055505007505417, 0.04202301427721977, -0.019848575815558434, -0.025475863367319107, 0.0364273376762867, 0.0178745836019516, -0.019349459558725357, 0.03651077672839165, 0.029899975284934044, -0.012416009791195393, 0.006108...
0.830576
0.775966
0.05461
Please explain the following problem in detail and provide code in Scala: Given a binary array `nums` and an integer `goal`, return _the number of non-empty **subarrays** with a sum_ `goal`. A **subarray** is a contiguous part of the array. **Example 1:** **Input:** nums = \[1,0,1,0,1\], goal = 2 **Output:** 4 **Exp...
dolphin
[ -0.0008908064919523895, 0.035931456834077835, -0.020678939297795296, -0.020327968522906303, 0.04920664429664612, -0.01927003264427185, -0.0358075313270092, 0.036793842911720276, 0.020112255588173866, -0.0021526161581277847, 0.028159726411104202, 0.03161550685763359, -0.027469679713249207, ...
0.83822
0.782359
0.055861
Please write the following solution using python: For an integer array `nums`, an **inverse pair** is a pair of integers `[i, j]` where `0 <= i < j < nums.length` and `nums[i] > nums[j]`. Given two integers n and k, return the number of different arrays consist of numbers from `1` to `n` such that there are exactly `k...
dolphin
[ 0.03707689046859741, 0.0424184612929821, -0.032965607941150665, -0.02770238183438778, 0.0499202199280262, -0.024225357919931412, -0.01270328275859356, 0.043556537479162216, 0.02657095156610012, -0.010135442949831486, 0.022775085642933846, 0.020432140678167343, -0.030510976910591125, -0.007...
0.838201
0.767698
0.070503
Please write the following solution using Fortran: Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_. A quadruplet `(i, j, k, l)` is increasing if: * `0 <= i < j < k < l < n`, and * `nums[i] < nums[k] < nums[j] < nums[l]`. ...
dolphin
[ 0.02075420320034027, 0.03302890062332153, -0.005476769059896469, -0.021673202514648438, 0.036218512803316116, -0.010532365180552006, -0.02430935576558113, 0.07561350613832474, 0.02334403246641159, -0.007261672522872686, 0.016581127420067787, 0.005131493788212538, -0.038019441068172455, -0....
0.844205
0.788076
0.056129
Please explain the reasoning behind the following solution and provide code in Swift: You are given an integer array `arr`. In one move, you can select a **palindromic** subarray `arr[i], arr[i + 1], ..., arr[j]` where `i <= j`, and remove that subarray from the given array. Note that after removing a subarray, the el...
dolphin
[ 0.018451254814863205, 0.029313087463378906, -0.03270237520337105, -0.034802474081516266, 0.04878102242946625, -0.022348685190081596, -0.031864266842603683, 0.05606197565793991, 0.05085068196058273, -0.008825329132378101, 0.02570556290447712, 0.003894219407811761, -0.02507101185619831, -0.0...
0.841384
0.784174
0.05721
Please explain the following problem in detail and provide code in Elixir: You are given four integers `minLength`, `maxLength`, `oneGroup` and `zeroGroup`. A binary string is **good** if it satisfies the following conditions: * The length of the string is in the range `[minLength, maxLength]`. * The size of each...
dolphin
[ 0.011312087997794151, 0.02593938633799553, -0.019939500838518143, -0.0585724376142025, 0.04920988529920578, -0.04748278856277466, -0.04671582579612732, 0.046811770647764206, 0.026612069457769394, -0.019033703953027725, 0.014781163074076176, 0.023872356861829758, -0.02522284723818302, -0.02...
0.857665
0.804026
0.053639
Please explain the following problem in detail and provide code in Object Pascal: Given an array of integers `arr`, return _the number of subarrays with an **odd** sum_. Since the answer can be very large, return it modulo `109 + 7`. **Example 1:** **Input:** arr = \[1,3,5\] **Output:** 4 **Explanation:** All subarr...
dolphin
[ 0.008525555953383446, 0.02913088910281658, -0.022725867107510567, -0.036564819514751434, 0.04170363023877144, -0.017656391486525536, -0.02911185659468174, 0.04201173037290573, 0.05433710291981697, -0.003984600771218538, 0.020572539418935776, 0.01296991016715765, -0.04451681300997734, -0.01...
0.837049
0.781123
0.055926
Please explain the following problem in detail and provide code in Object Pascal: Given an integer array `nums` and an integer `k`, return _the number of **good** subarrays of_ `nums`. A subarray `arr` is **good** if it there are **at least** `k` pairs of indices `(i, j)` such that `i < j` and `arr[i] == arr[j]`. A *...
dolphin
[ 0.017019491642713547, 0.02690272033214569, -0.037769123911857605, -0.022109193727374077, 0.04415472596883774, -0.01610931009054184, -0.027922138571739197, 0.0349276177585125, 0.034761685878038406, 0.005242146551609039, 0.018713705241680145, 0.024542663246393204, -0.017718913033604622, -0.0...
0.83927
0.781171
0.058099
Please explain the following problem in detail and provide code in Scala: In combinatorial mathematics, a **derangement** is a permutation of the elements of a set, such that no element appears in its original position. You are given an integer `n`. There is originally an array consisting of `n` integers from `1` to `...
dolphin
[ 0.038604844361543655, 0.018013769760727882, -0.011932696215808392, -0.03207088261842728, 0.031120583415031433, -0.02836471050977707, -0.03061491623520851, 0.04143109172582626, 0.014822101220488548, -0.008765739388763905, 0.03544233739376068, 0.01914331316947937, -0.037822939455509186, -0.0...
0.847459
0.788909
0.05855
Please write the following solution using Fortran: You are given an integer array `values` where values\[i\] represents the value of the `ith` sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them. The score of a pair (`i < j`) of sightseeing spots is `values[i] + values[j] + i -...
dolphin
[ 0.02218962460756302, 0.019680051133036613, -0.028531614691019058, -0.026360007002949715, 0.056161023676395416, -0.018987398594617844, -0.047733694314956665, 0.04098573327064514, 0.051395680755376816, -0.012953760102391243, 0.03648949787020683, 0.05001885071396828, -0.03297305479645729, 0.0...
0.836343
0.778666
0.057678
Please write the following solution using Perl: You are given an integer array `nums`. In one move, you can pick an index `i` where `0 <= i < nums.length` and increment `nums[i]` by `1`. Return _the minimum number of moves to make every value in_ `nums` _**unique**_. The test cases are generated so that the answer fi...
dolphin
[ 0.007299800869077444, 0.03179208189249039, -0.015658941119909286, -0.020645596086978912, 0.04032241180539131, -0.013637261465191841, -0.022970139980316162, 0.0672014057636261, 0.03300594165921211, -0.025736302137374878, 0.03697533532977104, 0.017380351200699806, -0.026513295248150826, -0.0...
0.847367
0.789569
0.057798
Please write the following solution using Swift: You are given an integer array `values` where values\[i\] represents the value of the `ith` sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them. The score of a pair (`i < j`) of sightseeing spots is `values[i] + values[j] + i - j...
dolphin
[ 0.01973911002278328, 0.016745325177907944, -0.03192475438117981, -0.022083811461925507, 0.05807862803339958, -0.016474904492497444, -0.05543416738510132, 0.0351649634540081, 0.05598108470439911, -0.01607511192560196, 0.0386812724173069, 0.04141002893447876, -0.03267607465386391, 0.00520272...
0.832769
0.773213
0.059556
Please explain the reasoning behind the following solution and provide code in F#: Given a set of **distinct** positive integers `nums`, return the largest subset `answer` such that every pair `(answer[i], answer[j])` of elements in this subset satisfies: * `answer[i] % answer[j] == 0`, or * `answer[j] % answer[i]...
dolphin
[ 0.031096341088414192, 0.02283453196287155, -0.022455543279647827, -0.034386128187179565, 0.043842971324920654, -0.0319199375808239, -0.0020814829040318727, 0.0687420666217804, 0.044588603079319, -0.010943777859210968, 0.030130986124277115, 0.022808514535427094, -0.03793090209364891, -0.016...
0.850591
0.794313
0.056278
Please explain the following problem in detail and provide code in PHP: Let `f(x)` be the number of zeroes at the end of `x!`. Recall that `x! = 1 * 2 * 3 * ... * x` and by convention, `0! = 1`. * For example, `f(3) = 0` because `3! = 6` has no zeroes at the end, while `f(11) = 2` because `11! = 39916800` has two ze...
dolphin
[ 0.01527856383472681, 0.035227976739406586, -0.0316973514854908, -0.03569013252854347, 0.0356731154024601, -0.022087138146162033, -0.010373448021709919, 0.06525126099586487, 0.02796354703605175, -0.004186190664768219, 0.01218856405466795, 0.01537555456161499, -0.03286226466298103, -0.026840...
0.831104
0.775417
0.055688
Please explain the following problem in detail and provide code in java: You are given an integer array `nums` and an integer `k`. You may partition `nums` into one or more **subsequences** such that each element in `nums` appears in **exactly** one of the subsequences. Return _the **minimum** number of subsequences n...
dolphin
[ 0.02365916222333908, 0.0186851117759943, -0.03363681957125664, -0.004683027509599924, 0.03475524112582207, -0.015233932062983513, -0.031677596271038055, 0.04583948105573654, 0.023073824122548103, -0.007612995337694883, 0.03527776524424553, 0.02647658810019493, -0.030110567808151245, 0.0147...
0.846508
0.779037
0.067471
Please write the following solution using Mojo: You have two types of tiles: a `2 x 1` domino shape and a tromino shape. You may rotate these shapes. Given an integer n, return _the number of ways to tile an_ `2 x n` _board_. Since the answer may be very large, return it **modulo** `109 + 7`. In a tiling, every squar...
dolphin
[ 0.03544898331165314, 0.02224784716963768, -0.02701917476952076, -0.02438926324248314, 0.01990957371890545, -0.02203754521906376, -0.022599566727876663, 0.05632887780666351, 0.007629708852618933, -0.003661139402538538, 0.04211808741092682, 0.04954126477241516, -0.04228915646672249, -0.02295...
0.829018
0.771121
0.057897
Please explain the reasoning behind the following solution and provide code in Kotlin: Given the array of integers `nums`, you will choose two different indices `i` and `j` of that array. _Return the maximum value of_ `(nums[i]-1)*(nums[j]-1)`. **Example 1:** **Input:** nums = \[3,4,5,2\] **Output:** 12 **Explanatio...
dolphin
[ 0.036586008965969086, 0.04185491055250168, -0.02273440919816494, -0.026575623080134392, 0.046766337007284164, -0.03621727228164673, -0.01858651265501976, 0.0659475103020668, 0.03091154247522354, -0.015559833496809006, 0.025266123935580254, 0.03331553190946579, -0.03651674836874008, -0.0016...
0.840049
0.783412
0.056637
Please write the following solution using PHP: You are given a positive integer `n` representing the number of nodes in an **undirected** graph. The nodes are labeled from `1` to `n`. You are also given a 2D integer array `edges`, where `edges[i] = [ai, bi]` indicates that there is a **bidirectional** edge between nod...
dolphin
[ 0.02183791622519493, 0.03347175568342209, -0.03940355405211449, -0.02546214871108532, 0.04806004837155342, -0.04451912268996239, -0.024810587987303734, 0.06993118673563004, 0.04438498988747597, -0.004602047149091959, 0.023916011676192284, 0.014880857430398464, -0.021912723779678345, -0.011...
0.857477
0.803231
0.054246
Please focus on the algorithm of this problem and provide code in java: Given an array `nums` of integers, return _the length of the longest arithmetic subsequence in_ `nums`. **Note** that: * A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the o...
dolphin
[ 0.02975240908563137, 0.02611214481294155, -0.03238357976078987, -0.023696156218647957, 0.040182337164878845, -0.02216319926083088, -0.040517669171094894, 0.04889890179038048, 0.03040112741291523, -0.016667606309056282, 0.01711331307888031, 0.02319302409887314, -0.03162616491317749, -0.0021...
0.828335
0.762668
0.065666
Please write the following solution using Rust: You want to build some obstacle courses. You are given a **0-indexed** integer array `obstacles` of length `n`, where `obstacles[i]` describes the height of the `ith` obstacle. For every index `i` between `0` and `n - 1` (**inclusive**), find the length of the **longest ...
dolphin
[ 0.024980299174785614, 0.022359689697623253, -0.00975606869906187, -0.036577899008989334, 0.017867228016257286, -0.017519643530249596, -0.04387498274445534, 0.04913361743092537, 0.053756117820739746, -0.02124197967350483, 0.015491798520088196, 0.0233896654099226, -0.020041054114699364, -0.0...
0.843387
0.789743
0.053644
Please focus on the efficiency of this problem and provide code in Perl: A **wiggle sequence** is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a seque...
dolphin
[ 0.010368450544774532, 0.007831823080778122, -0.028649771586060524, -0.02878536842763424, 0.031048953533172607, -0.022233696654438972, -0.03853871300816536, 0.06464638561010361, 0.030755147337913513, -0.022619152441620827, 0.0233982652425766, 0.033501144498586655, -0.02507062815129757, -0.0...
0.841396
0.788127
0.053269
Please focus on the functionality of this problem and provide code in Scala: Given an integer array `nums`, return _all the different possible non-decreasing subsequences of the given array with at least two elements_. You may return the answer in **any order**. **Example 1:** **Input:** nums = \[4,6,7,7\] **Output:*...
dolphin
[ 0.009069610387086868, 0.023828979581594467, -0.005825999192893505, -0.018891051411628723, 0.04261482506990433, -0.01646089181303978, -0.02626688778400421, 0.0516020692884922, 0.030565384775400162, -0.01473099086433649, 0.03810611739754677, 0.027528753504157066, -0.03660828620195389, -0.006...
0.83998
0.781785
0.058196
Please explain the following problem in detail and provide code in ANSI C: You are given a list of songs where the `ith` song has a duration of `time[i]` seconds. Return _the number of pairs of songs for which their total duration in seconds is divisible by_ `60`. Formally, we want the number of indices `i`, `j` such ...
dolphin
[ 0.030979076400399208, 0.028546232730150223, -0.034002069383859634, -0.005965528078377247, 0.03925452008843422, -0.03238779306411743, -0.04484470188617706, 0.08050704002380371, 0.024328693747520447, -0.02418978326022625, 0.028817199170589447, 0.012982317246496677, -0.05644902214407921, -0.0...
0.830029
0.773129
0.0569
Please explain the reasoning behind the following solution and provide code in c++: You are given an integer `n`. A **0-indexed** integer array `nums` of length `n + 1` is generated in the following way: * `nums[0] = 0` * `nums[1] = 1` * `nums[2 * i] = nums[i]` when `2 <= 2 * i <= n` * `nums[2 * i + 1] = nums[...
dolphin
[ 0.03689488023519516, 0.024867475032806396, -0.019901355728507042, -0.02910536900162697, 0.04242200776934624, -0.02226230502128601, -0.04062732309103012, 0.09885139763355255, 0.02366832084953785, -0.017097488045692444, 0.02712131477892399, 0.050581492483615875, -0.040411483496427536, -0.010...
0.845043
0.778742
0.066301
Please explain the following problem in detail and provide code in Swift: Given an integer `n`, return the count of all numbers with unique digits, `x`, where `0 <= x < 10n`. **Example 1:** **Input:** n = 2 **Output:** 91 **Explanation:** The answer should be the total numbers in the range of 0 <= x < 100, excluding ...
dolphin
[ -0.0002221935719717294, 0.013732911087572575, -0.03274371847510338, -0.025119144469499588, 0.038835518062114716, -0.022737422958016396, -0.023320062085986137, 0.041379284113645554, 0.026262829080224037, 0.0008302589994855225, 0.01893645152449608, 0.023978905752301216, -0.042694613337516785, ...
0.827769
0.771978
0.055791
Please write the following solution using Lisp: You are given an integer array `coins` of length `n` which represents the `n` coins that you own. The value of the `ith` coin is `coins[i]`. You can **make** some value `x` if you can choose some of your `n` coins such that their values sum up to `x`. Return the _maximum...
dolphin
[ 0.021826021373271942, 0.041666679084300995, -0.017359213903546333, -0.030415128916502, 0.038014672696590424, -0.02874394878745079, -0.04101673141121864, 0.046021874994039536, 0.03681059554219246, -0.029017770662903786, 0.04223101958632469, 0.03697012737393379, -0.03386995568871498, -0.0327...
0.844244
0.787407
0.056838
Please explain the following problem in detail and provide code in Scheme: You are given a **0-indexed** integer array `candies`, where `candies[i]` represents the flavor of the `ith` candy. Your mom wants you to share these candies with your little sister by giving her `k` **consecutive** candies, but you want to keep...
dolphin
[ 0.003946408629417419, 0.048224788159132004, -0.0019462562631815672, -0.038080766797065735, 0.03224708512425423, -0.03258199989795685, -0.032521724700927734, 0.051508981734514236, 0.0328405424952507, -0.030283499509096146, 0.033437371253967285, 0.011289196088910103, -0.021669378504157066, 0...
0.848388
0.792887
0.055502
Please focus on the efficiency of this problem and provide code in Perl: You are given an array `nums` consisting of positive integers. Starting with `score = 0`, apply the following algorithm: * Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index. ...
dolphin
[ 0.02015426941215992, 0.03972791135311127, -0.031130142509937286, -0.030693577602505684, 0.03485272452235222, -0.005327461287379265, -0.019566645845770836, 0.06689107418060303, 0.03676178678870201, -0.003403671784326434, 0.02768287993967533, 0.030016928911209106, -0.014129288494586945, -0.0...
0.853835
0.799503
0.054332
Please explain the following problem in detail and provide code in Haskell: For an integer array `nums`, an **inverse pair** is a pair of integers `[i, j]` where `0 <= i < j < nums.length` and `nums[i] > nums[j]`. Given two integers n and k, return the number of different arrays consist of numbers from `1` to `n` such...
dolphin
[ 0.027899770066142082, 0.033429212868213654, -0.020049165934324265, -0.028051337227225304, 0.052674733102321625, -0.023912949487566948, -0.00540665490552783, 0.04617580398917198, 0.03694858029484749, -0.008394572883844376, 0.018938833847641945, 0.027497630566358566, -0.023842543363571167, -...
0.840007
0.776898
0.063109
Please explain the following problem in detail and provide code in Groovy: You are given a **0-indexed** array `nums` of length `n`, consisting of non-negative integers. For each index `i` from `0` to `n - 1`, you must determine the size of the **minimum sized** non-empty subarray of `nums` starting at `i` (**inclusive...
dolphin
[ 0.002991346875205636, 0.01780995912849903, -0.03337295725941658, -0.016262317076325417, 0.028708064928650856, -0.03249035403132439, -0.0282321497797966, 0.03766854107379913, 0.04368841275572777, -0.01218119915574789, 0.03191579133272171, 0.03474128991365433, -0.03043397143483162, 0.0097007...
0.844505
0.789329
0.055176
Please explain the reasoning behind the following solution and provide code in java: You are given two **0-indexed** integer arrays `nums` and `removeQueries`, both of length `n`. For the `ith` query, the element in `nums` at the index `removeQueries[i]` is removed, splitting `nums` into different segments. A **segmen...
dolphin
[ 0.02370157279074192, 0.024442531168460846, -0.04217887297272682, -0.016660435125231743, 0.040368735790252686, -0.038336388766765594, -0.018412260338664055, 0.052430931478738785, 0.0408741794526577, -0.02214881032705307, 0.02999124862253666, 0.019957153126597404, -0.03465304896235466, -0.00...
0.84491
0.789665
0.055245
Please write the following solution using ANSI C: Given an array of **distinct** integers `candidates` and a target integer `target`, return _a list of all **unique combinations** of_ `candidates` _where the chosen numbers sum to_ `target`_._ You may return the combinations in **any order**. The **same** number may be...
dolphin
[ 0.028309883549809456, 0.046125806868076324, -0.01569340005517006, -0.028857138007879257, 0.045921359211206436, -0.01756300963461399, -0.03022857755422592, 0.05350031703710556, 0.032896365970373154, -0.01437715720385313, 0.02650897204875946, 0.022113490849733353, -0.034519538283348083, -0.0...
0.839848
0.783197
0.05665
Please explain the reasoning behind the following solution and provide code in PHP: You are given an integer array `nums`. You must perform **exactly one** operation where you can **replace** one element `nums[i]` with `nums[i] * nums[i]`. Return _the **maximum** possible subarray sum after **exactly one** operation_....
dolphin
[ 0.02477923221886158, 0.04581185802817345, -0.014077729545533657, -0.022497670724987984, 0.04552922770380974, -0.01900361478328705, -0.025051990523934364, 0.07326579838991165, 0.04316595569252968, -0.008828467689454556, 0.025585580617189407, 0.025263462215662003, -0.03170451149344444, -0.01...
0.84587
0.789128
0.056742
Please write the following solution using java: The **minimum absolute difference** of an array `a` is defined as the **minimum value** of `|a[i] - a[j]|`, where `0 <= i < j < a.length` and `a[i] != a[j]`. If all elements of `a` are the **same**, the minimum absolute difference is `-1`. * For example, the minimum ab...
dolphin
[ 0.014390706084668636, 0.02738930843770504, -0.02677014283835888, -0.020321985706686974, 0.0244346484541893, -0.03661857917904854, -0.0460946150124073, 0.04400504007935524, 0.04591688886284828, -0.024700384587049484, 0.029037460684776306, 0.004343788605183363, -0.034497156739234924, -0.0001...
0.838519
0.781353
0.057166
Please explain the reasoning behind the following solution and provide code in c++: Given a non-empty array of non-negative integers `nums`, the **degree** of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of `nums...
dolphin
[ -0.0008361682994291186, 0.015687519684433937, -0.030581410974264145, -0.022863760590553284, 0.03462810814380646, -0.008248571306467056, -0.04494732618331909, 0.0821598544716835, 0.040387801826000214, -0.01322225946933031, 0.0354977548122406, 0.028501754626631737, -0.020055148750543594, 0.0...
0.840775
0.782826
0.057949
Please write the following solution using Scala: Given an integer array `nums` that may contain duplicates, return _all possible_ _subsets_ _(the power set)_. The solution set **must not** contain duplicate subsets. Return the solution in **any order**. **Example 1:** **Input:** nums = \[1,2,2\] **Output:** \[\[\],\...
dolphin
[ 0.04018211364746094, 0.024828525260090828, -0.010004423558712006, -0.016223574057221413, 0.04899991676211357, -0.04276581108570099, -0.0014826986007392406, 0.04562613368034363, 0.045724593102931976, -0.0295633003115654, 0.03361959010362625, 0.02325369045138359, -0.03986889496445656, -0.035...
0.840236
0.780699
0.059537
Please explain the following problem in detail and provide code in Scheme: You are given a **0-indexed** 2D integer array `grid` of size `m x n`. Each cell has one of two values: * `0` represents an **empty** cell, * `1` represents an **obstacle** that may be removed. You can move up, down, left, or right from an...
dolphin
[ 0.013530008494853973, 0.02641444094479084, -0.007574838120490313, -0.037259168922901154, 0.04332102835178375, -0.03484967723488808, -0.039366092532873154, 0.05996754765510559, 0.04204046353697777, -0.014899701811373234, 0.011705910786986351, 0.006571298930794001, -0.017636997625231743, -0....
0.8453
0.788501
0.056799
Please focus on the efficiency of this problem and provide code in Object Pascal: Given an integer array `nums` that may contain duplicates, return _all possible_ _subsets_ _(the power set)_. The solution set **must not** contain duplicate subsets. Return the solution in **any order**. **Example 1:** **Input:** nums...
dolphin
[ 0.038351237773895264, 0.027570439502596855, -0.017166266217827797, -0.01155140157788992, 0.03627178072929382, -0.03654981404542923, -0.004453763365745544, 0.05016452446579933, 0.05201590433716774, -0.02159431204199791, 0.039181627333164215, 0.02100433222949505, -0.03944415599107742, -0.031...
0.847531
0.790934
0.056596
Please write the following solution using Dart: You are given two integer arrays `nums1` and `nums2` both of the same length. The **advantage** of `nums1` with respect to `nums2` is the number of indices `i` for which `nums1[i] > nums2[i]`. Return _any permutation of_ `nums1` _that maximizes its **advantage** with res...
dolphin
[ 0.019526898860931396, 0.024220000952482224, -0.01138855330646038, -0.03159897401928902, 0.02702467329800129, -0.01562781073153019, -0.03872808814048767, 0.06436120718717575, 0.04136194661259651, -0.019592594355344772, 0.010764067061245441, 0.022195251658558846, -0.03746836259961128, -0.010...
0.834617
0.768375
0.066242
Please focus on the functionality of this problem and provide code in Kotlin: There is an undirected tree with `n` nodes labeled from `0` to `n - 1`. You are given a **0-indexed** integer array `nums` of length `n` where `nums[i]` represents the value of the `ith` node. You are also given a 2D integer array `edges` of...
dolphin
[ 0.011430676095187664, 0.022186357527971268, -0.019620321691036224, -0.03244656324386597, 0.03659515082836151, -0.025566793978214264, -0.0016235574148595333, 0.061860810965299606, 0.034984372556209564, -0.013701029121875763, 0.03630592301487923, 0.014802101068198681, -0.01835658587515354, -...
0.854358
0.800263
0.054095
Please write the following solution using Fortran: You are given two positive **0-indexed** integer arrays `nums1` and `nums2`, both of length `n`. The **sum of squared difference** of arrays `nums1` and `nums2` is defined as the **sum** of `(nums1[i] - nums2[i])2` for each `0 <= i < n`. You are also given two positi...
dolphin
[ 0.003860325086861849, 0.03909224271774292, -0.02657630294561386, -0.05688168480992317, 0.055883049964904785, -0.019234126433730125, -0.01231545489281416, 0.07623768597841263, 0.054963089525699615, -0.018012728542089462, 0.029426727443933487, 0.021360797807574272, -0.03715536370873451, -0.0...
0.841344
0.787261
0.054083
Please explain the following problem in detail and provide code in Julia: Given an integer `n`, return _the least number of perfect square numbers that sum to_ `n`. A **perfect square** is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, `1`, `4`,...
dolphin
[ 0.00712592713534832, 0.045065414160490036, -0.032288502901792526, -0.05386023968458176, 0.04662683978676796, -0.022114064544439316, -0.022183917462825775, 0.04500377178192139, 0.044517382979393005, 0.006802965421229601, 0.02895006723701954, 0.03548789396882057, -0.04207485169172287, -0.032...
0.832146
0.775544
0.056601
Please write the following solution using C#: You are given `n` balloons, indexed from `0` to `n - 1`. Each balloon is painted with a number on it represented by an array `nums`. You are asked to burst all the balloons. If you burst the `ith` balloon, you will get `nums[i - 1] * nums[i] * nums[i + 1]` coins. If `i - 1...
dolphin
[ 0.023224933072924614, 0.04455968365073204, -0.014108913950622082, -0.021366380155086517, 0.02850891277194023, -0.031248057261109352, -0.022802166640758514, 0.08326951414346695, 0.03584980219602585, -0.012375005520880222, 0.029367845505475998, 0.04048452153801918, -0.04379861056804657, -0.0...
0.840872
0.783092
0.05778
Please write the following solution using Dart: There exists an undirected and unrooted tree with `n` nodes indexed from `0` to `n - 1`. You are given an 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. You a...
dolphin
[ 0.00452602980658412, 0.026302097365260124, -0.01298128068447113, -0.0346527136862278, 0.011393156833946705, -0.014667480252683163, -0.0207815058529377, 0.05718311667442322, 0.02275485172867775, -0.004407485481351614, 0.031099803745746613, 0.02181321009993553, -0.010978549718856812, -0.0023...
0.857872
0.797772
0.0601
Please write the following solution using Julia: Given an integer array nums and an integer k, return `true` _if_ `nums` _has a **good subarray** or_ `false` _otherwise_. A **good subarray** is a subarray where: * its length is **at least two**, and * the sum of the elements of the subarray is a multiple of `k`. ...
dolphin
[ 0.01398715190589428, 0.03460776433348656, -0.03299346938729286, -0.03713114932179451, 0.05845648795366287, -0.027103133499622345, -0.01481541432440281, 0.05903005972504616, 0.03134744614362717, -0.010530781000852585, 0.02384266071021557, 0.028345340862870216, -0.016948794946074486, 0.00393...
0.840662
0.787279
0.053383
Please focus on the efficiency of this problem and provide code in Object Pascal: A **self-dividing number** is a number that is divisible by every digit it contains. * For example, `128` is **a self-dividing number** because `128 % 1 == 0`, `128 % 2 == 0`, and `128 % 8 == 0`. A **self-dividing number** is not allo...
dolphin
[ 0.02985808253288269, 0.03402453288435936, -0.018472909927368164, -0.04005023092031479, 0.021247951313853264, -0.021510610356926918, -0.01015111431479454, 0.054928969591856, 0.043987587094306946, -0.006611261051148176, 0.035376980900764465, 0.024581050500273705, -0.029122112318873405, -0.02...
0.835296
0.776398
0.058898
Please explain the following problem in detail and provide code in c++: You are given an array `nums` consisting of non-negative integers. You are also given a `queries` array, where `queries[i] = [xi, mi]`. The answer to the `ith` query is the maximum bitwise `XOR` value of `xi` and any element of `nums` that does no...
dolphin
[ 0.02547653578221798, 0.016570404171943665, -0.034536559134721756, -0.016658328473567963, 0.031237654387950897, -0.006034173537045717, -0.022772157564759254, 0.09707969427108765, 0.03623716160655022, -0.012272370047867298, 0.030335567891597748, 0.026887565851211548, -0.04153437539935112, -0...
0.844971
0.784647
0.060324
Please focus on the algorithm of this problem and provide code in javascript: You are given a **0-indexed** array of integers `nums` of length `n`. You are initially positioned at `nums[0]`. Each element `nums[i]` represents the maximum length of a forward jump from index `i`. In other words, if you are at `nums[i]`, ...
dolphin
[ 0.008300556801259518, 0.020570090040564537, -0.014757251366972923, -0.013778463937342167, 0.045518022030591965, -0.02308378368616104, -0.02113659307360649, 0.060746364295482635, 0.02817120961844921, -0.009033839218318462, 0.01855355314910412, 0.028827356174588203, -0.028940176591277122, -0...
0.844013
0.788198
0.055815
Please focus on the efficiency of this problem and provide code in ANSI C: Given an `m x n` matrix `matrix` and an integer `k`, return _the max sum of a rectangle in the matrix such that its sum is no larger than_ `k`. It is **guaranteed** that there will be a rectangle with a sum no larger than `k`. **Example 1:** ...
dolphin
[ 0.017332717776298523, 0.029146624729037285, -0.026223834604024887, -0.04180067032575607, 0.03235182166099548, -0.016252510249614716, -0.030340006574988365, 0.06790323555469513, 0.03353748098015785, -0.015878427773714066, 0.027946127578616142, 0.04433061182498932, -0.028208183124661446, -0....
0.83971
0.777882
0.061828
Please focus on the efficiency of this problem and provide code in Elixir: Given an integer array `nums` that may contain duplicates, return _all possible_ _subsets_ _(the power set)_. The solution set **must not** contain duplicate subsets. Return the solution in **any order**. **Example 1:** **Input:** nums = \[1,...
dolphin
[ 0.0392802357673645, 0.028013937175273895, -0.013272831216454506, -0.020403148606419563, 0.025821426883339882, -0.039248090237379074, -0.010612333193421364, 0.04507448151707649, 0.04749508574604988, -0.027018023654818535, 0.03939239680767059, 0.018191715702414513, -0.03672260046005249, -0.0...
0.849739
0.796345
0.053394
Please write the following solution using ANSI C: You are given a **0-indexed** array `nums` consisting of positive integers, representing targets on a number line. You are also given an integer `space`. You have a machine which can destroy targets. **Seeding** the machine with some `nums[i]` allows it to destroy all ...
dolphin
[ 0.027396606281399727, 0.04042976722121239, -0.030693719163537025, -0.02347688190639019, 0.05327121913433075, -0.016441334038972855, -0.039451006799936295, 0.07708843052387238, 0.03750478848814964, -0.01203175075352192, 0.01609731651842594, 0.026630712673068047, -0.043447382748126984, -0.04...
0.850151
0.79101
0.059141
Please focus on the functionality of this problem and provide code in Objective-C: Given an array of integers `arr`, and three integers `a`, `b` and `c`. You need to find the number of good triplets. A triplet `(arr[i], arr[j], arr[k])` is **good** if the following conditions are true: * `0 <= i < j < k < arr.lengt...
dolphin
[ 0.02910534292459488, 0.026691604405641556, -0.04277076944708824, -0.024625226855278015, 0.03997940942645073, -0.030437732115387917, -0.04266330227255821, 0.05206133797764778, 0.014508571475744247, -0.021733880043029785, 0.014496766962110996, 0.01569576933979988, -0.03156771883368492, -0.03...
0.834888
0.781314
0.053574
Please write the following solution using javascript: Given two integers `n` and `k`, return _all possible combinations of_ `k` _numbers chosen from the range_ `[1, n]`. You may return the answer in **any order**. **Example 1:** **Input:** n = 4, k = 2 **Output:** \[\[1,2\],\[1,3\],\[1,4\],\[2,3\],\[2,4\],\[3,4\]\] ...
dolphin
[ 0.041753824800252914, 0.04619712010025978, -0.025167586281895638, -0.027071380987763405, 0.05298294126987457, -0.028385624289512634, -0.0005394116742536426, 0.033259209245443344, 0.03557209670543671, 0.006468568928539753, 0.04612269997596741, 0.024576030671596527, -0.03431624174118042, 0.0...
0.822077
0.767361
0.054716
Please write the following solution using Rust: A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`. Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ramp** in `nums`, return `0`....
dolphin
[ 0.021346168592572212, 0.02862507663667202, -0.018940294161438942, -0.02305760234594345, 0.040453340858221054, -0.01232310850173235, -0.045400798320770264, 0.07406201958656311, 0.04189889132976532, -0.02745571918785572, 0.023535912856459618, 0.0333927646279335, -0.024092089384794235, -0.018...
0.84211
0.782782
0.059327
Please explain the following problem in detail and provide code in java: Given an array of integers `nums`, find the maximum length of a subarray where the product of all its elements is positive. A subarray of an array is a consecutive sequence of zero or more values taken out of that array. Return _the maximum leng...
dolphin
[ 0.020405441522598267, 0.021757369861006737, -0.03699303790926933, -0.01447104662656784, 0.039001286029815674, -0.028336677700281143, -0.04436647519469261, 0.04335843399167061, 0.030251454561948776, -0.012870154343545437, 0.01006824430078268, 0.03529765456914902, -0.03119228221476078, -0.02...
0.838775
0.777125
0.061649
Please focus on the functionality of this problem and provide code in PHP: The **array-form** of an integer `num` is an array representing its digits in left to right order. * For example, for `num = 1321`, the array form is `[1,3,2,1]`. Given `num`, the **array-form** of an integer, and an integer `k`, return _the...
dolphin
[ 0.02676144801080227, 0.0529855452477932, -0.02585388906300068, -0.054205890744924545, 0.038624927401542664, -0.022411799058318138, -0.013431302271783352, 0.06636951863765717, 0.04337335750460625, 0.0026098531670868397, 0.03373827040195465, 0.032898545265197754, -0.04639911651611328, -0.018...
0.830496
0.774741
0.055754
Please focus on the efficiency of this problem and provide code in java: You are given a 2D integer array `grid` of size `m x n`, where each cell contains a positive integer. A **cornered path** is defined as a set of adjacent cells with **at most** one turn. More specifically, the path should exclusively move either ...
dolphin
[ 0.009703613817691803, 0.035323675721883774, -0.021184759214520454, -0.022560300305485725, 0.02932862564921379, -0.023101575672626495, -0.04522014036774635, 0.05952915921807289, 0.02702457271516323, -0.021269701421260834, 0.029190456494688988, 0.015422775410115719, -0.02051951177418232, -0....
0.847494
0.788794
0.0587
Please focus on the functionality of this problem and provide code in Scala: Given a binary array `nums`, return _the maximum length of a contiguous subarray with an equal number of_ `0` _and_ `1`. **Example 1:** **Input:** nums = \[0,1\] **Output:** 2 **Explanation:** \[0, 1\] is the longest contiguous subarray with...
dolphin
[ 0.020839432254433632, 0.02687174081802368, -0.017874276265501976, -0.026378631591796875, 0.030970416963100433, -0.02519470453262329, -0.04054788500070572, 0.054046887904405594, 0.03226657211780548, -0.01691286638379097, 0.027215350419282913, 0.03115803375840187, -0.02176499180495739, 0.003...
0.844617
0.787223
0.057394
Please write the following solution using C#: Given an integer array `nums`, return _the number of all the **arithmetic subsequences** of_ `nums`. A sequence of numbers is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same. * For ex...
dolphin
[ 0.029183736070990562, 0.023736005648970604, -0.024748435243964195, -0.02863902971148491, 0.04082077741622925, -0.017222577705979347, -0.01989705301821232, 0.08345286548137665, 0.04300522431731224, -0.004056976176798344, 0.01952001452445984, 0.017081761732697487, -0.04849376901984215, -0.02...
0.840229
0.773172
0.067057
Please focus on the algorithm of this problem and provide code in java: You are given a **0-indexed** integer array `nums`. In one operation, you can: * Choose two different indices `i` and `j` such that `0 <= i, j < nums.length`. * Choose a non-negative integer `k` such that the `kth` bit (**0-indexed**) in the b...
dolphin
[ 0.007770727854222059, 0.04171335697174072, -0.043953556567430496, -0.009494161233305931, 0.040331047028303146, -0.035087212920188904, -0.043362878262996674, 0.05563860386610031, 0.05196307972073555, -0.020136872306466103, 0.01938909851014614, 0.01815340295433998, -0.03471507132053375, -0.0...
0.848172
0.786417
0.061755
Please focus on the algorithm of this problem and provide code in C#: You are given an array `nums` that consists of positive integers. The **GCD** of a sequence of numbers is defined as the greatest integer that divides **all** the numbers in the sequence evenly. * For example, the GCD of the sequence `[4,6,16]` i...
dolphin
[ 0.011886147782206535, 0.017578627914190292, -0.013692504726350307, -0.025297563523054123, 0.02185957320034504, -0.0313488245010376, -0.02457123063504696, 0.09025926887989044, 0.027096014469861984, -0.017676005139946938, 0.02005275897681713, 0.019584335386753082, -0.04055614396929741, -0.01...
0.839358
0.780636
0.058722
Please explain the reasoning behind the following solution and provide code in python: Given an array of unique integers, `arr`, where each integer `arr[i]` is strictly greater than `1`. We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should b...
dolphin
[ 0.03263770416378975, 0.040329307317733765, -0.028348930180072784, -0.013647601008415222, 0.04245170205831528, -0.04865450784564018, -0.02105667255818844, 0.06163141131401062, 0.02686203271150589, -0.02474907785654068, 0.02943602204322815, 0.0067582265473902225, -0.036625899374485016, -0.00...
0.840954
0.785463
0.055491
Please focus on the functionality of this problem and provide code in Haskell: You are given an array `nums` consisting of **positive** integers. We call a subarray of `nums` **nice** if the bitwise **AND** of every pair of elements that are in **different** positions in the subarray is equal to `0`. Return _the leng...
dolphin
[ 0.007057428825646639, 0.008912024088203907, -0.03652174398303032, -0.011310652829706669, 0.041734274476766586, -0.030151071026921272, -0.03287817910313606, 0.03927386924624443, 0.03773655369877815, -0.010005793534219265, 0.0327889546751976, 0.025946566835045815, -0.02863946557044983, -0.02...
0.846677
0.790093
0.056584
Please explain the following problem in detail and provide code in Mojo: You are given an integer array `nums` with the following properties: * `nums.length == 2 * n`. * `nums` contains `n + 1` **unique** elements. * Exactly one element of `nums` is repeated `n` times. Return _the element that is repeated_ `n` ...
dolphin
[ 0.029306940734386444, 0.02815205790102482, -0.026143888011574745, -0.028064362704753876, 0.032568879425525665, -0.02543322928249836, -0.030000105500221252, 0.07300817966461182, 0.020500749349594116, 0.000959485478233546, 0.020905224606394768, 0.009310075081884861, -0.033849019557237625, -0...
0.846259
0.78097
0.065288
Please focus on the functionality of this problem and provide code in F#: Given an integer array `nums` and two integers `left` and `right`, return _the number of contiguous non-empty **subarrays** such that the value of the maximum array element in that subarray is in the range_ `[left, right]`. The test cases are ge...
dolphin
[ 0.026473158970475197, 0.023497993126511574, -0.0312713198363781, -0.02132525108754635, 0.03223442658782005, -0.002650173846632242, -0.026209382340312004, 0.06470328569412231, 0.04045427590608597, -0.004576269071549177, 0.030244946479797363, 0.04781239107251167, -0.040947530418634415, -0.02...
0.848668
0.791457
0.057211
Please explain the reasoning behind the following solution and provide code in ANSI C: You are given two integer arrays `nums1` and `nums2`. We write the integers of `nums1` and `nums2` (in the order they are given) on two separate horizontal lines. We may draw connecting lines: a straight line connecting two numbers ...
dolphin
[ 0.022388534620404243, 0.027680927887558937, -0.02665642462670803, -0.03090723790228367, 0.036881979554891586, -0.018352532759308815, -0.047036197036504745, 0.07267529517412186, 0.047173332422971725, -0.02888679876923561, 0.025796644389629364, 0.023324904963374138, -0.0033593308180570602, -...
0.85194
0.785758
0.066182
Please explain the reasoning behind the following solution and provide code in java: Given two integer arrays `nums1` and `nums2`, return _an array of their intersection_. Each element in the result must be **unique** and you may return the result in **any order**. **Example 1:** **Input:** nums1 = \[1,2,2,1\], nums2...
dolphin
[ 0.033405471593141556, 0.023296628147363663, -0.029149064794182777, -0.021541805937886238, 0.029616061598062515, -0.02610548585653305, -0.03148886561393738, 0.037753768265247345, 0.053564976900815964, -0.02342471480369568, 0.03628898784518242, -0.005937503185123205, -0.00467754527926445, -0...
0.827061
0.773194
0.053867
Please explain the following problem in detail and provide code in ANSI C: You want to build some obstacle courses. You are given a **0-indexed** integer array `obstacles` of length `n`, where `obstacles[i]` describes the height of the `ith` obstacle. For every index `i` between `0` and `n - 1` (**inclusive**), find t...
dolphin
[ 0.025138096883893013, 0.028726976364850998, -0.015182944014668465, -0.03003588318824768, 0.013747962191700935, -0.02330901473760605, -0.05250853672623634, 0.060373738408088684, 0.038960397243499756, -0.01823396235704422, 0.022965120151638985, 0.018907150253653526, -0.03652041032910347, -0....
0.842149
0.776385
0.065764