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 explain the reasoning behind the following solution and provide code in Haskell: You are given an integer array `nums` and an integer `k`. Find the longest subsequence of `nums` that meets the following requirements: * The subsequence is **strictly increasing** and * The difference between adjacent element...
dolphin
[ 0.02429606392979622, 0.03235159441828728, -0.012470478191971779, -0.0365995354950428, 0.0475240983068943, -0.02214336208999157, -0.0325041227042675, 0.05865710601210594, 0.043582819402217865, -0.014421891421079636, 0.024150673300027847, 0.02499229460954666, -0.029687469825148582, 0.0159958...
0.840466
0.786279
0.054187
Please write the following solution using ANSI C: Given an array `nums` that represents a permutation of integers from `1` to `n`. We are going to construct a binary search tree (BST) by inserting the elements of `nums` in order into an initially empty BST. Find the number of different ways to reorder `nums` so that th...
dolphin
[ 0.024516701698303223, 0.027715370059013367, -0.028101520612835884, -0.014978185296058655, 0.025899095460772514, -0.02642901800572872, -0.019717734307050705, 0.07448618113994598, 0.025011179968714714, -0.015214036218822002, 0.02279495820403099, 0.013276872225105762, -0.045942746102809906, -...
0.849244
0.786516
0.062728
Please explain the following problem in detail and provide code in Scheme: You are given two integer arrays, `source` and `target`, both of length `n`. You are also given an array `allowedSwaps` where each `allowedSwaps[i] = [ai, bi]` indicates that you are allowed to swap the elements at index `ai` and index `bi` **(0...
dolphin
[ 0.03536326065659523, 0.027619464322924614, -0.019467290490865707, -0.009769829921424389, 0.0378284715116024, -0.02748764120042324, -0.03538563847541809, 0.05316050350666046, 0.03526505082845688, -0.023427268490195274, 0.014755643904209137, 0.014236719347536564, -0.01738840900361538, -0.010...
0.842743
0.789365
0.053378
Please focus on the efficiency of this problem and provide code in Fortran: 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 elemen...
dolphin
[ 0.012797181494534016, 0.030120834708213806, -0.023601459339261055, -0.022796697914600372, 0.027189789339900017, -0.008439782075583935, -0.028299931436777115, 0.03966326266527176, 0.029594995081424713, 0.005310236010700464, 0.04156945273280144, 0.04394222050905228, -0.03280380368232727, -0....
0.843957
0.783389
0.060567
Please focus on the efficiency of this problem and provide code in Mojo: You are given an integer array `nums` where the largest integer is **unique**. Determine whether the largest element in the array is **at least twice** as much as every other number in the array. If it is, return _the **index** of the largest ele...
dolphin
[ 0.035113122314214706, 0.03892720863223076, -0.022727342322468758, -0.0251307375729084, 0.02399745211005211, -0.0255380030721426, -0.02848481945693493, 0.05834250897169113, 0.03172614052891731, -0.015710117295384407, 0.023726699873805046, 0.01935545727610588, -0.03254144266247749, -0.016939...
0.841409
0.787882
0.053527
Please write the following solution using Objective-C: Given an integer array `nums` and an integer `k`, return _the number of non-empty **subarrays** that have a sum divisible by_ `k`. A **subarray** is a **contiguous** part of an array. **Example 1:** **Input:** nums = \[4,5,0,-2,-3,1\], k = 5 **Output:** 7 **Expl...
dolphin
[ 0.017823992297053337, 0.03234962373971939, -0.038496531546115875, -0.022749530151486397, 0.050503920763731, -0.02036334201693535, -0.025529960170388222, 0.05619185417890549, 0.02533976547420025, -0.0028771881479769945, 0.03392912074923515, 0.023564783856272697, -0.03699187561869621, -0.010...
0.835776
0.76961
0.066166
Please focus on the efficiency of this problem and provide code in Scheme: Given an array of integers `nums`, you start with an initial **positive** value _startValue__._ In each iteration, you calculate the step by step sum of _startValue_ plus elements in `nums` (from left to right). Return the minimum **positive**...
dolphin
[ 0.009851226583123207, 0.014843343757092953, -0.0291336290538311, -0.03464965894818306, 0.043778494000434875, -0.018291838467121124, -0.03272011876106262, 0.05497393384575844, 0.036621589213609695, -0.02261403575539589, 0.02439275197684765, 0.0277875829488039, -0.03290396183729172, -0.00956...
0.846597
0.791542
0.055055
Please write the following solution using ANSI C: You are given an integer array `nums` and an integer `k`. You can partition the array into **at most** `k` non-empty adjacent subarrays. The **score** of a partition is the sum of the averages of each subarray. Note that the partition must use every integer in `nums`, ...
dolphin
[ 0.01661432906985283, 0.025575581938028336, -0.0408305749297142, -0.017436057329177856, 0.033677734434604645, -0.019108543172478676, -0.0370151586830616, 0.048331163823604584, 0.030588846653699875, -0.011171439662575722, 0.04444936290383339, 0.024131733924150467, -0.040209200233221054, 0.00...
0.83477
0.765668
0.069102
Please write the following solution using Go: Given the `root` of a binary tree, return the most frequent **subtree sum**. If there is a tie, return all the values with the highest frequency in any order. The **subtree sum** of a node is defined as the sum of all the node values formed by the subtree rooted at that no...
dolphin
[ 0.01785275526344776, 0.0242148544639349, -0.029900744557380676, -0.02687334641814232, 0.01967472955584526, -0.03117426484823227, -0.003113921033218503, 0.046367209404706955, 0.022968992590904236, 0.010509394109249115, 0.03668823093175888, 0.016245540231466293, -0.04032720625400543, 0.00486...
0.828805
0.775007
0.053797
Please write the following solution using C#: Given an integer `n`, return **any** array containing `n` **unique** integers such that they add up to `0`. **Example 1:** **Input:** n = 5 **Output:** \[-7,-1,1,3,4\] **Explanation:** These arrays also are accepted \[-5,-1,1,2,3\] , \[-3,-1,2,-2,4\]. **Example 2:** **I...
dolphin
[ 0.018875660374760628, 0.031109122559428215, -0.01901690661907196, -0.031377535313367844, 0.03850511461496353, -0.03914327546954155, -0.012490199878811836, 0.06687530130147934, 0.039430391043424606, -0.006189430132508278, 0.01663852669298649, 0.02036583051085472, -0.038229212164878845, -0.0...
0.826625
0.765382
0.061243
Please focus on the functionality of this problem and provide code in PHP: The **distance of a pair** of integers `a` and `b` is defined as the absolute difference between `a` and `b`. Given an integer array `nums` and an integer `k`, return _the_ `kth` _smallest **distance among all the pairs**_ `nums[i]` _and_ `nums...
dolphin
[ 0.010595443658530712, 0.04261946678161621, -0.029443373903632164, -0.020103299990296364, 0.05202748626470566, -0.022301247343420982, -0.028315098956227303, 0.050770871341228485, 0.0476357564330101, -0.01687639206647873, 0.026293816044926643, 0.019516082480549812, -0.01970798522233963, 0.00...
0.840681
0.781969
0.058712
Please write the following solution using F#: Given an integer array `nums`, return `0` _if the sum of the digits of the minimum integer in_ `nums` _is odd, or_ `1` _otherwise_. **Example 1:** **Input:** nums = \[34,23,1,24,75,33,54,8\] **Output:** 0 **Explanation:** The minimal element is 1, and the sum of those dig...
dolphin
[ -0.004381355829536915, 0.018426071852445602, -0.021586647257208824, -0.049335215240716934, 0.051210418343544006, -0.022987402975559235, -0.011969184502959251, 0.05889051780104637, 0.03805750980973244, -0.0024783152621239424, 0.006794240325689316, 0.010414228774607182, -0.0430912971496582, ...
0.837701
0.783692
0.054009
Please focus on the functionality of this problem and provide code in Fortran: 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 **Expla...
dolphin
[ 0.022004224359989166, 0.017148464918136597, -0.022879187017679214, -0.03596984222531319, 0.03572635352611542, -0.01784352771937847, -0.032761797308921814, 0.0631924495100975, 0.03847721219062805, -0.01878410577774048, 0.023670637980103493, 0.032077331095933914, -0.03297048807144165, -0.002...
0.840384
0.780843
0.059541
Please focus on the functionality of this problem and provide code in c++: A bus has `n` stops numbered from `0` to `n - 1` that form a circle. We know the distance between all pairs of neighboring stops where `distance[i]` is the distance between the stops number `i` and `(i + 1) % n`. The bus goes along both directi...
dolphin
[ 0.012148831970989704, 0.023680824786424637, -0.018954865634441376, -0.0256486926227808, 0.034954581409692764, -0.0020317689049988985, -0.04792977496981621, 0.07028315216302872, 0.04798212647438049, 0.0011767036048695445, 0.023287493735551834, 0.03247011452913284, 0.0033194352872669697, -0....
0.837572
0.778318
0.059253
Please focus on the efficiency of this problem and provide code in Groovy: 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 g...
dolphin
[ 0.030523626133799553, 0.02319493144750595, -0.0378669872879982, -0.015879571437835693, 0.02077656053006649, -0.0020415554754436016, -0.03768989071249962, 0.04930492863059044, 0.03312807157635689, -0.014516185969114304, 0.03627761825919151, 0.05226981267333031, -0.024120008572936058, -0.007...
0.851278
0.789535
0.061743
Please explain the reasoning behind the following solution and provide code in java: Given an integer `n`, return _all the structurally unique **BST'**s (binary search trees), which has exactly_ `n` _nodes of unique values from_ `1` _to_ `n`. Return the answer in **any order**. **Example 1:** **Input:** n = 3 **Outpu...
dolphin
[ 0.02418690174818039, 0.031094862148165703, -0.03982074186205864, -0.022776328027248383, 0.031494658440351486, -0.045786626636981964, -0.008792035281658173, 0.032009463757276535, 0.04202582687139511, -0.02529875934123993, 0.029978560283780098, 0.025558199733495712, -0.034808844327926636, -0...
0.846761
0.792141
0.05462
Please write the following solution using Scheme: You are given an integer array `nums` sorted in **non-decreasing** order. Build and return _an integer array_ `result` _with the same length as_ `nums` _such that_ `result[i]` _is equal to the **summation of absolute differences** between_ `nums[i]` _and all the other ...
dolphin
[ 0.022845100611448288, 0.024364925920963287, -0.023476477712392807, -0.0324363112449646, 0.04125283658504486, -0.027694188058376312, -0.04808133468031883, 0.057034045457839966, 0.05085183307528496, -0.010690688155591488, 0.02209959179162979, 0.02111230045557022, -0.05464957281947136, -0.003...
0.843029
0.783455
0.059574
Please write the following solution using Julia: Given an unsorted array of integers `nums`, return _the length of the longest **continuous increasing subsequence** (i.e. subarray)_. The subsequence must be **strictly** increasing. A **continuous increasing subsequence** is defined by two indices `l` and `r` (`l < r`)...
dolphin
[ 0.02060069516301155, 0.0413212813436985, -0.028108831495046616, -0.029108820483088493, 0.03222861886024475, -0.017197126522660255, -0.04562051221728325, 0.06765405833721161, 0.04708385467529297, -0.017347725108265877, 0.02344587817788124, 0.013450653292238712, -0.031958796083927155, 0.0158...
0.832987
0.774294
0.058693
Please explain the following problem in detail and provide code in Visual Basic .NET: Given a 2D `grid` of `0`s and `1`s, return the number of elements in the largest **square** subgrid that has all `1`s on its **border**, or `0` if such a subgrid doesn't exist in the `grid`. **Example 1:** **Input:** grid = \[\[1,1,...
dolphin
[ 0.00551871070638299, 0.03292068839073181, -0.023083044216036797, -0.03442804515361786, 0.03062601014971733, -0.029611770063638687, -0.021621348336338997, 0.06329033523797989, 0.03771057352423668, -0.008367123082280159, 0.022016841918230057, 0.02410818450152874, -0.041552718728780746, -0.02...
0.837823
0.779138
0.058685
Please explain the following problem in detail and provide code in ANSI C: There exists an undirected and initially 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 betwee...
dolphin
[ 0.011395074427127838, 0.02127784863114357, -0.027913492172956467, -0.029370948672294617, 0.01839430443942547, -0.03547290712594986, -0.01998983882367611, 0.07269983738660812, 0.034914497286081314, -0.0051924921572208405, 0.0570458322763443, 0.0243765190243721, -0.03168853744864464, -0.0174...
0.836523
0.780416
0.056108
Please focus on the algorithm of this problem and provide code in Visual Basic .NET: Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_. **Example 1:** **Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\] **Output:** 6 **Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6. ...
dolphin
[ 0.013170701451599598, 0.028021221980452538, -0.02542208507657051, -0.0271944347769022, 0.03036089614033699, -0.022586287930607796, -0.01622566394507885, 0.06456664949655533, 0.03672826662659645, -0.0144710848107934, 0.02936728671193123, 0.03863213211297989, -0.0478820726275444, -0.01298975...
0.834095
0.778629
0.055466
Please explain the following problem in detail and provide code in C#: You are given an integer array `nums` of length `n` where `nums` is a permutation of the numbers in the range `[0, n - 1]`. You should build a set `s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... }` subjected to the following rule: * Th...
dolphin
[ 0.024749858304858208, 0.024306030943989754, -0.027517667040228844, -0.010177157819271088, 0.03041710890829563, -0.0419459268450737, -0.03125094622373581, 0.08921036869287491, 0.03493231534957886, -0.01179022528231144, 0.025201348587870598, 0.016418443992733955, -0.04002734646201134, -0.017...
0.845035
0.778348
0.066687
Please write the following solution using Julia: Given an integer array `nums` of length `n` where all the integers of `nums` are in the range `[1, n]` and each integer appears **once** or **twice**, return _an array of all the integers that appears **twice**_. You must write an algorithm that runs in `O(n)` time and ...
dolphin
[ 0.012526553124189377, 0.027720313519239426, -0.02502232976257801, -0.015720315277576447, 0.02822222001850605, -0.014451340772211552, -0.0311929639428854, 0.06063155457377434, 0.02814684621989727, -0.006550717167556286, 0.0169437974691391, 0.00971977412700653, -0.01795893721282482, -0.01560...
0.845691
0.788852
0.056839
Please write the following solution using java: Given an integer array `queries` and a **positive** integer `intLength`, return _an array_ `answer` _where_ `answer[i]` _is either the_ `queries[i]th` _smallest **positive palindrome** of length_ `intLength` _or_ `-1` _if no such palindrome exists_. A **palindrome** is a...
dolphin
[ 0.01441461592912674, 0.009494910947978497, -0.03561808168888092, -0.028321178629994392, 0.020976286381483078, -0.027912044897675514, -0.017266320064663887, 0.05055048689246178, 0.02860203944146633, -0.02636263146996498, 0.04422876238822937, 0.022773990407586098, -0.043625786900520325, -0.0...
0.84047
0.783575
0.056895
Please explain the following problem in detail and provide code in javascript: Numbers can be regarded as the product of their factors. * For example, `8 = 2 x 2 x 2 = 2 x 4`. Given an integer `n`, return _all possible combinations of its factors_. You may return the answer in **any order**. **Note** that the fact...
dolphin
[ 0.050558507442474365, 0.05309087410569191, -0.007250825874507427, -0.02093259058892727, 0.02840503305196762, -0.012222187593579292, -0.02046206220984459, 0.050618428736925125, 0.044322419911623, -0.0021158389281481504, 0.0213706623762846, 0.03972107172012329, -0.05664440244436264, -0.03166...
0.831064
0.77348
0.057584
Please focus on the efficiency of this problem and provide code in Scheme: You are given a **0-indexed** integer array `nums` of size `n` and a positive integer `k`. We call an index `i` in the range `k <= i < n - k` **good** if the following conditions are satisfied: * The `k` elements that are just **before** the...
dolphin
[ 0.028541499748826027, 0.040174905210733414, -0.025788601487874985, -0.030968353152275085, 0.016748366877436638, -0.021522890776395798, -0.044679686427116394, 0.05020882934331894, 0.029275942593812943, -0.004409015644341707, 0.0217828918248415, 0.013780128210783005, -0.04016559571027756, 0....
0.843053
0.789817
0.053236
Please write the following solution using PHP: Given an integer array nums, return _the number of **AND triples**_. An **AND triple** is a triple of indices `(i, j, k)` such that: * `0 <= i < nums.length` * `0 <= j < nums.length` * `0 <= k < nums.length` * `nums[i] & nums[j] & nums[k] == 0`, where `&` represe...
dolphin
[ 0.00015042198356240988, 0.018989916890859604, -0.026008695363998413, -0.017445862293243408, 0.03981180489063263, -0.021786915138363838, -0.04490257427096367, 0.059767648577690125, 0.015288176946341991, 0.0011639395961537957, 0.03520101681351662, 0.03331536427140236, -0.05095626041293144, -...
0.842143
0.787007
0.055136
Please write the following solution using Perl: 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:** \[\[4,6\],\[4,6,7\],\[4,6,7...
dolphin
[ 0.013867194764316082, 0.014195853844285011, -0.011914731934666634, -0.021406719461083412, 0.04159436747431755, -0.006893576588481665, -0.025699244812130928, 0.060482874512672424, 0.04354862496256828, -0.01277411263436079, 0.040740761905908585, 0.02793663740158081, -0.04574068635702133, -0....
0.829512
0.770221
0.059292
Please write the following solution using Elixir: Given an array `nums` sorted in **non-decreasing** order, return _the maximum between the number of positive integers and the number of negative integers._ * In other words, if the number of positive integers in `nums` is `pos` and the number of negative integers is ...
dolphin
[ 0.02199811488389969, 0.010883967392146587, -0.030867651104927063, -0.023529168218374252, 0.010873017832636833, -0.018781235441565514, -0.048247598111629486, 0.02977687492966652, 0.02745658904314041, -0.00948355533182621, 0.023615030571818352, 0.03787459805607796, -0.0241397637873888, -0.01...
0.84546
0.791168
0.054292
Please explain the reasoning behind the following solution and provide code in ANSI C: You have a pointer at index `0` in an array of size `arrLen`. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at a...
dolphin
[ 0.025825025513768196, 0.032045818865299225, -0.021678708493709564, -0.03606603667140007, 0.028735186904668808, -0.017712604254484177, -0.039070021361112595, 0.0778099074959755, 0.04629632458090782, -0.016435613855719566, 0.0263215284794569, 0.03165334090590477, -0.03148973733186722, -0.035...
0.842736
0.785176
0.057561
Please write the following solution using Kotlin: Given an array of `n` integers `nums`, a **132 pattern** is a subsequence of three integers `nums[i]`, `nums[j]` and `nums[k]` such that `i < j < k` and `nums[i] < nums[k] < nums[j]`. Return `true` _if there is a **132 pattern** in_ `nums`_, otherwise, return_ `false`_...
dolphin
[ 0.011808417737483978, 0.014721555635333061, -0.017930811271071434, -0.025655454024672508, 0.04159959405660629, -0.011346174404025078, -0.012781457044184208, 0.06167014315724373, 0.021608328446745872, 0.008611087687313557, 0.010633589699864388, 0.03049759566783905, -0.014352732338011265, -0...
0.844706
0.789428
0.055277
Please explain the following problem in detail and provide code in java: You have a pointer at index `0` in an array of size `arrLen`. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any time). Giv...
dolphin
[ 0.022519785910844803, 0.026858000084757805, -0.03034389205276966, -0.03208396956324577, 0.031075576320290565, -0.014404543675482273, -0.02834922820329666, 0.04825847968459129, 0.04217172786593437, -0.016977081075310707, 0.02474789507687092, 0.029559658840298653, -0.02256554365158081, -0.03...
0.847314
0.787414
0.0599
Please focus on the efficiency of this problem and provide code in C#: 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\...
dolphin
[ 0.03672921285033226, 0.028724877163767815, -0.019619949162006378, -0.01241432223469019, 0.030538076534867287, -0.04312313720583916, -0.008980571292340755, 0.07630087435245514, 0.05053103342652321, -0.025455351918935776, 0.03401551768183708, 0.017941635102033615, -0.045832838863134384, -0.0...
0.846273
0.788407
0.057866
Please write the following solution using Lua: Given an integer array `nums`, return _the number of longest increasing subsequences._ **Notice** that the sequence has to be **strictly** increasing. **Example 1:** **Input:** nums = \[1,3,5,4,7\] **Output:** 2 **Explanation:** The two longest increasing subsequences a...
dolphin
[ 0.01110000442713499, 0.03594960644841194, -0.022027848288416862, -0.03661547601222992, 0.03547144681215286, -0.006857653148472309, -0.04541158676147461, 0.05236821249127388, 0.035562288016080856, -0.02120000496506691, 0.030991196632385254, 0.016803694888949394, -0.0498664528131485, -0.0019...
0.831039
0.776301
0.054737
Please write the following solution using java: You have `n` jobs and `m` workers. You are given three arrays: `difficulty`, `profit`, and `worker` where: * `difficulty[i]` and `profit[i]` are the difficulty and the profit of the `ith` job, and * `worker[j]` is the ability of `jth` worker (i.e., the `jth` worker c...
dolphin
[ 0.02872031182050705, 0.017908528447151184, -0.03084612265229225, -0.02755090408027172, 0.02873452566564083, -0.0070388843305408955, -0.03792837634682655, 0.04340411722660065, 0.03135674446821213, -0.01224781945347786, 0.020811427384614944, 0.03143623471260071, -0.014509457163512707, -0.027...
0.836722
0.77923
0.057492
Please write the following solution using java: Given an array `nums` of integers, return how many of them contain an **even number** of digits. **Example 1:** **Input:** nums = \[12,345,2,6,7896\] **Output:** 2 **Explanation:** 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digi...
dolphin
[ 0.00851354468613863, 0.008501737378537655, -0.018274804577231407, -0.03510032594203949, 0.029284656047821045, -0.022562528029084206, -0.0327020138502121, 0.037846893072128296, 0.012086918577551842, -0.0007981793605722487, 0.010772068053483963, 0.025823673233389854, -0.03644074872136116, -0...
0.827106
0.766753
0.060353
Please write the following solution using F#: You are given an integer array `nums` of **even** length `n` and an integer `limit`. In one move, you can replace any integer from `nums` with another integer between `1` and `limit`, inclusive. The array `nums` is **complementary** if for all indices `i` (**0-indexed**), ...
dolphin
[ 0.0055156489834189415, 0.03691018000245094, -0.010655190795660019, -0.02460426837205887, 0.03673579543828964, -0.02895377203822136, -0.021087996661663055, 0.0690961554646492, 0.040207769721746445, -0.02850913815200329, 0.013372146524488926, 0.01821846514940262, -0.05386299267411232, -0.029...
0.854279
0.799215
0.055064
Please explain the following problem in detail and provide code in ANSI C: Given the `root` node of a binary search tree and two integers `low` and `high`, return _the sum of values of all nodes with a value in the **inclusive** range_ `[low, high]`. **Example 1:** **Input:** root = \[10,5,15,3,7,null,18\], low = 7, ...
dolphin
[ 0.01408186461776495, 0.034811489284038544, -0.024600358679890633, -0.028890196233987808, 0.029691092669963837, -0.039942417293787, -0.015255218371748924, 0.06979814171791077, 0.017470669001340866, -0.020023919641971588, 0.04185308888554573, 0.027224093675613403, -0.047980599105358124, -0.0...
0.82917
0.769125
0.060045
Please explain the reasoning behind the following solution and provide code in ANSI C: There are `n` people standing in a line labeled from `1` to `n`. The first person in the line is holding a pillow initially. Every second, the person holding the pillow passes it to the next person standing in the line. Once the pill...
dolphin
[ 0.019246431067585945, 0.03239275515079498, -0.02164696715772152, -0.02883586846292019, 0.008758964948356152, -0.02803967520594597, -0.04002837836742401, 0.08214036375284195, 0.029284443706274033, -0.017377318814396858, 0.027411378920078278, 0.040118325501680374, -0.028402183204889297, -0.0...
0.835093
0.781225
0.053869
Please explain the reasoning behind the following solution and provide code in PHP: Given a 2D `grid` of `0`s and `1`s, return the number of elements in the largest **square** subgrid that has all `1`s on its **border**, or `0` if such a subgrid doesn't exist in the `grid`. **Example 1:** **Input:** grid = \[\[1,1,1\...
dolphin
[ 0.0010096621699631214, 0.04176977276802063, -0.017929712310433388, -0.030182864516973495, 0.03355933353304863, -0.03410588204860687, -0.03226910158991814, 0.0609128400683403, 0.03757016360759735, -0.006297215353697538, 0.019436951726675034, 0.024401294067502022, -0.03970877081155777, -0.01...
0.839279
0.785985
0.053294
Please explain the following problem in detail and provide code in java: You are given an array of `n` strings `strs`, all of the same length. We may choose any deletion indices, and we delete all the characters in those indices for each string. For example, if we have `strs = [ "abcdef ", "uvwxyz "]` and deletion in...
dolphin
[ 0.01552362460643053, 0.015354862436652184, -0.036786362528800964, -0.03705712780356407, 0.03750118240714073, -0.0516929067671299, -0.019734807312488556, 0.04069158062338829, 0.027080586180090904, -0.019511353224515915, 0.006453826557844877, 0.005691871512681246, -0.039211831986904144, -0.0...
0.849512
0.790219
0.059293
Please explain the following problem in detail and provide code in Mojo: You are given a binary string `s` consisting only of zeroes and ones. A substring of `s` is considered balanced if **all zeroes are before ones** and the number of zeroes is equal to the number of ones inside the substring. Notice that the empty ...
dolphin
[ 0.03364107012748718, 0.027293773368000984, -0.026043178513646126, -0.04439873620867729, 0.046278130263090134, -0.052814990282058716, -0.018259892240166664, 0.05663905665278435, 0.04103786498308182, -0.01227007620036602, 0.024118032306432724, 0.024026697501540184, -0.02929702401161194, -0.0...
0.837883
0.783446
0.054437
Please explain the reasoning behind the following solution and provide code in Scala: Given an binary array `nums` and an integer `k`, return `true` _if all_ `1`_'s are at least_ `k` _places away from each other, otherwise return_ `false`. **Example 1:** **Input:** nums = \[1,0,0,0,1,0,0,1\], k = 2 **Output:** true *...
dolphin
[ 0.010769427753984928, 0.03582419455051422, -0.014211594127118587, -0.03323233127593994, 0.049660574644804, -0.03833235800266266, -0.011908997781574726, 0.06305721402168274, 0.021184192970395088, -0.01381066907197237, 0.02434343844652176, 0.024129346013069153, -0.015608517453074455, -0.0035...
0.84481
0.790776
0.054034
Please write the following solution using Erlang: Given an array of integers `arr` and an integer `k`. Find the _least number of unique integers_ after removing **exactly** `k` elements**.** **Example 1:** **Input:** arr = \[5,5,4\], k = 1 **Output:** 1 **Explanation**: Remove the single 4, only 5 is left. **Example...
dolphin
[ 0.028863774612545967, 0.04603475332260132, -0.015432538464665413, -0.048970770090818405, 0.04495120048522949, -0.03456278145313263, -0.01511791255325079, 0.05292874202132225, 0.05253417417407036, -0.013588392175734043, 0.02119697816669941, -0.0022866723593324423, -0.004256182815879583, -0....
0.849473
0.793484
0.055988
Please explain the following problem in detail and provide code in Visual Basic .NET: You have a graph of `n` nodes. You are given an integer `n` and an array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between `ai` and `bi` in the graph. Return _the number of connected components in the graph_...
dolphin
[ 0.027064764872193336, 0.02059454843401909, -0.03414687514305115, -0.019938427954912186, 0.019245006144046783, -0.02506934478878975, -0.009462600573897362, 0.061988964676856995, 0.036221884191036224, 0.006170664448291063, 0.027167867869138718, 0.0184414554387331, -0.02727780118584633, -0.03...
0.840781
0.776444
0.064337
Please explain the following problem in detail and provide code in Kotlin: Given two non-negative integers `low` and `high`. Return the _count of odd numbers between_ `low` _and_ `high` _(inclusive)_. **Example 1:** **Input:** low = 3, high = 7 **Output:** 3 **Explanation:** The odd numbers between 3 and 7 are \[3,5,...
dolphin
[ 0.005083488766103983, 0.016792001202702522, -0.01364215463399887, -0.030774805694818497, 0.02931903675198555, -0.008448619395494461, -0.03502087667584419, 0.05551555007696152, 0.027759935706853867, -0.015315109863877296, 0.018259435892105103, 0.022899627685546875, -0.02130267396569252, -0....
0.83064
0.775443
0.055197
Please write the following solution using ANSI C: 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 and to an empty cell. Retu...
dolphin
[ 0.010398296639323235, 0.02792646735906601, -0.008006490767002106, -0.03739645704627037, 0.036623504012823105, -0.029023196548223495, -0.04166141524910927, 0.08334586769342422, 0.04215683788061142, -0.021640807390213013, 0.012454181909561157, 0.007443537469953299, -0.02447216399013996, -0.0...
0.842772
0.78053
0.062242
Please explain the following problem in detail and provide code in c++: You have `n` bulbs in a row numbered from `1` to `n`. Initially, all the bulbs are turned off. We turn on **exactly one** bulb every day until all bulbs are on after `n` days. You are given an array `bulbs` of length `n` where `bulbs[i] = x` means...
dolphin
[ 0.005927184130996466, 0.03986708074808121, -0.024306176230311394, -0.032189831137657166, 0.032835911959409714, -0.03792092949151993, -0.022405551746487617, 0.09863706678152084, 0.021907173097133636, -0.010415429249405861, 0.02451818250119686, 0.040359050035476685, -0.007413790561258793, 0....
0.845978
0.787809
0.058169
Please write the following solution using java: Given two arrays of **unique** digits `nums1` and `nums2`, return _the **smallest** number that contains **at least** one digit from each array_. **Example 1:** **Input:** nums1 = \[4,1,3\], nums2 = \[5,7\] **Output:** 15 **Explanation:** The number 15 contains the digi...
dolphin
[ 0.0016269073821604252, 0.03532774746417999, -0.030220551416277885, -0.03645176813006401, 0.04802650958299637, -0.023144638165831566, -0.02860955335199833, 0.03322666510939598, 0.026934415102005005, -0.027653945609927177, 0.028437979519367218, 0.009685116820037365, -0.013682066462934017, -0...
0.826042
0.763416
0.062626
Please explain the following problem in detail and provide code in java: Given an array `arr` of positive integers sorted in a **strictly increasing order**, and an integer `k`. Return _the_ `kth` _**positive** integer that is **missing** from this array._ **Example 1:** **Input:** arr = \[2,3,4,7,11\], k = 5 **Outp...
dolphin
[ 0.022622546181082726, 0.045955535024404526, -0.025354227051138878, -0.037231143563985825, 0.03477902337908745, -0.03509718179702759, -0.026647981256246567, 0.038754578679800034, 0.029682785272598267, -0.016659734770655632, 0.025733254849910736, -0.005490836221724749, -0.03729123994708061, ...
0.839888
0.783376
0.056512
Please write the following solution using Ruby: Given an integer array `nums` of `2n` integers, group these integers into `n` pairs `(a1, b1), (a2, b2), ..., (an, bn)` such that the sum of `min(ai, bi)` for all `i` is **maximized**. Return _the maximized sum_. **Example 1:** **Input:** nums = \[1,4,3,2\] **Output:** ...
dolphin
[ 0.019408848136663437, 0.03361271694302559, -0.04955058917403221, -0.02938055992126465, 0.04325888678431511, -0.003116555977612734, -0.02156471274793148, 0.028935551643371582, 0.03603560850024223, -0.017506089061498642, 0.024437211453914642, 0.03569464385509491, -0.028926510363817215, -0.01...
0.837282
0.779127
0.058154
Please explain the reasoning behind the following solution and provide code in ANSI C: Given an array of integers `nums` sorted in non-decreasing order, find the starting and ending position of a given `target` value. If `target` is not found in the array, return `[-1, -1]`. You must write an algorithm with `O(log n)...
dolphin
[ 0.020592309534549713, 0.041668832302093506, -0.029516873881220818, -0.029205111786723137, 0.03933542221784592, -0.019821062684059143, -0.045041341334581375, 0.0696772038936615, 0.03559468314051628, -0.027072235941886902, 0.030547399073839188, 0.02045612595975399, -0.051985569298267365, -0....
0.840784
0.787115
0.053668
Please explain the following problem in detail and provide code in ANSI C: You are given an array of **distinct** positive integers locations where `locations[i]` represents the position of city `i`. You are also given integers `start`, `finish` and `fuel` representing the starting city, ending city, and the initial am...
dolphin
[ 0.029578693211078644, 0.029776105657219887, -0.016451139003038406, -0.027079880237579346, 0.018181098625063896, -0.03876114264130592, -0.043879564851522446, 0.078047014772892, 0.03246079012751579, -0.02063511498272419, 0.032632503658533096, 0.02850075624883175, -0.03623490035533905, -0.033...
0.843383
0.79011
0.053273
Please explain the following problem in detail and provide code in R: You have `n` `tiles`, where each tile has one letter `tiles[i]` printed on it. Return _the number of possible non-empty sequences of letters_ you can make using the letters printed on those `tiles`. **Example 1:** **Input:** tiles = "AAB " **Outp...
dolphin
[ 0.03032754547894001, 0.02688628062605858, 0.007391390390694141, -0.014194046147167683, 0.03799967095255852, -0.024457130581140518, -0.02537812478840351, 0.06577283889055252, 0.024898085743188858, -0.003516710828989744, 0.03469274938106537, 0.03428790718317032, -0.04375167191028595, -0.0274...
0.82486
0.769611
0.05525
Please explain the reasoning behind the following solution and provide code in java: Given an integer number `n`, return the difference between the product of its digits and the sum of its digits. **Example 1:** **Input:** n = 234 **Output:** 15 **Explanation:** Product of digits = 2 \* 3 \* 4 = 24 Sum of digits =...
dolphin
[ 0.027250193059444427, 0.030143508687615395, -0.03159196302294731, -0.04258501157164574, 0.05589038133621216, -0.031513333320617676, -0.03941984474658966, 0.051226723939180374, 0.036706920713186264, -0.0015703369863331318, 0.012175610288977623, 0.04158375412225723, -0.057921938598155975, -0...
0.835696
0.780908
0.054788
Please explain the following problem in detail and provide code in Scheme: A sequence of numbers is called an **arithmetic progression** if the difference between any two consecutive elements is the same. Given an array of numbers `arr`, return `true` _if the array can be rearranged to form an **arithmetic progression...
dolphin
[ 0.045942272990942, 0.031051114201545715, -0.014110330492258072, -0.04349362850189209, 0.025645986199378967, -0.01773598976433277, 0.0002911437477450818, 0.08837446570396423, 0.03228079155087471, -0.03205981105566025, 0.010701905936002731, -0.008380911312997341, -0.03194410726428032, -0.016...
0.831519
0.774041
0.057478
Please explain the following problem in detail and provide code in Clojure: You are given an array of positive integers `nums` and want to erase a subarray containing **unique elements**. The **score** you get by erasing the subarray is equal to the **sum** of its elements. Return _the **maximum score** you can get by...
dolphin
[ 0.012111310847103596, 0.03364758938550949, -0.03188095614314079, -0.025305332615971565, 0.037271060049533844, -0.03272920846939087, -0.019261466339230537, 0.035261742770671844, 0.05233871191740036, -0.007011739537119865, 0.023862803354859352, 0.016601627692580223, -0.015625808387994766, -0...
0.841412
0.786923
0.054489
Please focus on the functionality of this problem and provide code in java: You are given an integer `n`. There is an **undirected** graph with `n` nodes, numbered from `0` to `n - 1`. You are given a 2D integer array `edges` where `edges[i] = [ai, bi]` denotes that there exists an **undirected** edge connecting nodes ...
dolphin
[ 0.024601256474852562, 0.04027685150504112, -0.01959104835987091, -0.028108352795243263, 0.036824192851781845, -0.024130813777446747, -0.017112301662564278, 0.03402659296989441, 0.02586427889764309, -0.00505260843783617, 0.03658778592944145, 0.028099672868847847, -0.018074771389365196, -0.0...
0.851496
0.791156
0.06034
Please focus on the algorithm of this problem and provide code in ANSI C: You are given a **0-indexed** `m x n` binary matrix `matrix` and an integer `numSelect`, which denotes the number of **distinct** columns you must select from `matrix`. Let us consider `s = {c1, c2, ...., cnumSelect}` as the set of columns selec...
dolphin
[ 0.011295045726001263, 0.020172733813524246, -0.03729007765650749, -0.021888528019189835, 0.039586134254932404, -0.04272463172674179, -0.035619791597127914, 0.07740949839353561, 0.023299112915992737, -0.005233906675130129, 0.02897520735859871, 0.032109349966049194, -0.03234131634235382, -0....
0.837421
0.781077
0.056343
Please focus on the algorithm of this problem and provide code in ANSI C: Given the `root` of a binary tree, return _the sum of all left leaves._ A **leaf** is a node with no children. A **left leaf** is a leaf that is the left child of another node. **Example 1:** **Input:** root = \[3,9,20,null,null,15,7\] **Outpu...
dolphin
[ 0.012902526184916496, 0.024871503934264183, -0.02766658365726471, -0.03201819583773613, 0.024435587227344513, -0.04760640114545822, 0.0019591974560171366, 0.07402166724205017, 0.025123286992311478, -0.022866424173116684, 0.0398847870528698, 0.020525019615888596, -0.04512524604797363, -0.00...
0.830862
0.776992
0.053871
Please explain the following problem in detail and provide code in F#: Given an integer array `nums` and an integer `k`, return _the number of **subarrays** of_ `nums` _where the least common multiple of the subarray's elements is_ `k`. A **subarray** is a contiguous non-empty sequence of elements within an array. Th...
dolphin
[ 0.006895511411130428, 0.04234231263399124, -0.03231029957532883, -0.029422689229249954, 0.058786842972040176, -0.021955784410238266, -0.02395762875676155, 0.052899137139320374, 0.029696321114897728, -0.011781618930399418, 0.026126887649297714, 0.018918851390480995, -0.021448345854878426, -...
0.838812
0.782728
0.056085
Please explain the following problem in detail and provide code in Scala: 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.007866892032325268, 0.034098103642463684, -0.0045547387562692165, -0.026519862934947014, 0.042247477918863297, -0.026518523693084717, -0.030600465834140778, 0.05909218639135361, 0.019176049157977104, -0.012718006037175655, 0.024941029027104378, 0.02219494991004467, -0.01500114519149065, ...
0.846126
0.791965
0.054161
Please explain the following problem in detail and provide code in Object Pascal: 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**...
dolphin
[ 0.014540259726345539, 0.05279841274023056, -0.010554393753409386, -0.025042859837412834, 0.03500985726714134, -0.02558026649057865, -0.026439255103468895, 0.07004664093255997, 0.032287321984767914, -0.0058913324028253555, 0.020891468971967697, 0.0041198949329555035, -0.032383255660533905, ...
0.849552
0.793535
0.056017
Please focus on the efficiency of this problem and provide code in ANSI C: Given the `root` of a binary tree, the level of its root is `1`, the level of its children is `2`, and so on. Return the **smallest** level `x` such that the sum of all the values of nodes at level `x` is **maximal**. **Example 1:** **Input:*...
dolphin
[ 0.029502544552087784, 0.03758251294493675, -0.029179884120821953, -0.0400509387254715, 0.020227164030075073, -0.03981398046016693, -0.011250801384449005, 0.0710311084985733, 0.027998851612210274, -0.02329421415925026, 0.042411934584379196, 0.02693754993379116, -0.04269720986485481, -0.0065...
0.834898
0.779858
0.05504
Please explain the following problem in detail and provide code in PHP: You are given an array `nums` of size `n` consisting of **distinct** integers from `1` to `n` and a positive integer `k`. Return _the number of non-empty subarrays in_ `nums` _that have a **median** equal to_ `k`. **Note**: * The median of an ...
dolphin
[ 0.024471277371048927, 0.029180243611335754, -0.03998520225286484, -0.02225014753639698, 0.03606775030493736, -0.00317709450609982, -0.027319064363837242, 0.05591380596160889, 0.023239608854055405, -0.006731015630066395, 0.032278385013341904, 0.009403274394571781, -0.0326879620552063, -0.00...
0.832977
0.773847
0.05913
Please focus on the efficiency of this problem and provide code in Mojo: 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 **subarray...
dolphin
[ 0.0210352074354887, 0.027420299127697945, -0.04398811236023903, -0.01992686092853546, 0.03164380416274071, -0.019257694482803345, -0.045543208718299866, 0.03930079936981201, 0.03237544745206833, -0.006450833287090063, 0.0196442399173975, 0.01661296747624874, -0.027693860232830048, -0.00662...
0.843279
0.785942
0.057337
Please write the following solution using C#: 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 and to an empty cell. Return _...
dolphin
[ 0.007845541462302208, 0.021469101309776306, -0.011502294801175594, -0.03645143285393715, 0.03685998171567917, -0.03637496009469032, -0.033049434423446655, 0.08785289525985718, 0.04482829570770264, -0.018502337858080864, 0.007422465365380049, 0.008388652466237545, -0.021994594484567642, -0....
0.840263
0.783209
0.057054
Please explain the following problem in detail and provide code in Rust: 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 t...
dolphin
[ 0.013634872622787952, 0.01805897057056427, -0.023918574675917625, -0.03451021388173103, 0.037623610347509384, -0.002528771059587598, -0.01830158568918705, 0.06876494735479355, 0.03630353882908821, -0.008463549427688122, 0.023344676941633224, 0.03554927185177803, -0.032908666878938675, -0.0...
0.846333
0.792992
0.053342
Please focus on the functionality of this problem and provide code in Kotlin: 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...
dolphin
[ 0.009378557093441486, 0.042860377579927444, -0.03475750610232353, -0.017150241881608963, 0.041310373693704605, -0.028590066358447075, -0.04364117607474327, 0.061194147914648056, 0.056189727038145065, -0.017571058124303818, 0.01405305601656437, 0.021553784608840942, -0.03113729879260063, 0....
0.849501
0.794439
0.055062
Please explain the following problem in detail and provide code in Go: You are given an integer array `nums`. The unique elements of an array are the elements that appear **exactly once** in the array. Return _the **sum** of all the unique elements of_ `nums`. **Example 1:** **Input:** nums = \[1,2,3,2\] **Output:**...
dolphin
[ -0.006705930456519127, 0.031248584389686584, -0.01185274962335825, -0.034874092787504196, 0.05555916205048561, -0.01923798769712448, -0.018509909510612488, 0.050599731504917145, 0.04311658442020416, 0.004222567193210125, 0.014725393615663052, 0.005344942677766085, -0.034421730786561966, -0...
0.822683
0.767091
0.055592
Please focus on the algorithm of this problem and provide code in Haskell: You are given an array `nums` consisting of **positive** integers. You can perform the following operation on the array **any** number of times: * Choose any two **adjacent** elements and **replace** them with their **sum**. * For exam...
dolphin
[ 0.010012391954660416, 0.01831255853176117, -0.003592916764318943, -0.02181253582239151, 0.03975540027022362, -0.025910276919603348, -0.01605735905468464, 0.05818001180887222, 0.03266691043972969, -0.01625910960137844, 0.019823532551527023, 0.019716501235961914, -0.024146458134055138, -0.02...
0.84657
0.792555
0.054015
Please focus on the algorithm of this problem and provide code in ANSI C: Given an integer array `nums` and an integer `k`, return _the number of **good subarrays** of_ `nums`. A **good array** is an array where the number of different integers in that array is exactly `k`. * For example, `[1,2,3,1,2]` has `3` diff...
dolphin
[ 0.013415250927209854, 0.024685416370630264, -0.03206725791096687, -0.017547065392136574, 0.029409589245915413, -0.017222503200173378, -0.05004104971885681, 0.059987012296915054, 0.023546520620584488, -0.00656672241166234, 0.021511374041438103, 0.02391947992146015, -0.02919231541454792, -0....
0.843972
0.779841
0.064131
Please explain the reasoning behind the following solution and provide code in c++: You are given a **0-indexed** integer array `nums`. In one operation, you can: * Choose an index `i` in the range `0 <= i < nums.length` * Set `nums[i]` to `nums[i] + 1` **or** `nums[i] - 1` Return _the **minimum** number of opera...
dolphin
[ 0.011571141891181469, 0.035452935844659805, -0.019838297739624977, -0.02255471795797348, 0.03143555298447609, -0.006064014974981546, -0.04224175959825516, 0.09982123970985413, 0.04556513577699661, -0.012694020755589008, 0.019559063017368317, 0.002432191511616111, -0.02861165441572666, -0.0...
0.848301
0.793908
0.054393
Please write the following solution using ANSI C: You are given a **0-indexed** array `nums` of size `n` consisting of **non-negative** integers. You need to apply `n - 1` operations to this array where, in the `ith` operation (**0-indexed**), you will apply the following on the `ith` element of `nums`: * If `nums[...
dolphin
[ 0.027716176584362984, 0.04771297425031662, -0.005546804517507553, -0.02414810098707676, 0.02927335351705551, -0.01878921128809452, -0.0380442775785923, 0.10205540806055069, 0.0304991714656353, -0.028683295473456383, 0.014040108770132065, 0.0006904975161887705, -0.042420003563165665, -0.045...
0.841301
0.781986
0.059315
Please explain the following problem in detail and provide code in C#: There is an integer array `nums` sorted in ascending order (with **distinct** values). Prior to being passed to your function, `nums` is **possibly rotated** at an unknown pivot index `k` (`1 <= k < nums.length`) such that the resulting array is `[...
dolphin
[ 0.012014041654765606, 0.050671663135290146, -0.022979771718382835, -0.004050727467983961, 0.02649809420108795, -0.020973864942789078, -0.013233416713774204, 0.08527206629514694, 0.03415603190660477, -0.0020115175284445286, 0.025602584704756737, 0.006654778495430946, -0.033050939440727234, ...
0.841235
0.787385
0.05385
Please explain the reasoning behind the following solution and provide code in Objective-C: Given a positive integer `n`, return the number of the integers in the range `[0, n]` whose binary representations **do not** contain consecutive ones. **Example 1:** **Input:** n = 5 **Output:** 5 **Explanation:** Here are th...
dolphin
[ 0.007794398348778486, 0.020230181515216827, -0.030987685546278954, -0.033265676349401474, 0.04427444562315941, -0.02438616007566452, -0.045309990644454956, 0.06442197412252426, 0.034126006066799164, -0.021851064637303352, 0.028096819296479225, 0.018805047497153282, -0.03316805511713028, -0...
0.840306
0.78387
0.056437
Please focus on the algorithm of this problem and provide code in Object Pascal: Given an integer array `arr` and an integer `k`, modify the array by repeating it `k` times. For example, if `arr = [1, 2]` and `k = 3` then the modified array will be `[1, 2, 1, 2, 1, 2]`. Return the maximum sub-array sum in the modifie...
dolphin
[ 0.019784901291131973, 0.03268488124012947, -0.009496285580098629, -0.03516655042767525, 0.04682629555463791, -0.03386685252189636, -0.01565319113433361, 0.05098630115389824, 0.028036881238222122, -0.015772100538015366, 0.03365883603692055, 0.02433345839381218, -0.03340962156653404, 0.00936...
0.840987
0.782229
0.058758
Please explain the following problem in detail and provide code in Mojo: Given an array of integers `nums` and an integer `k`. A continuous subarray is called **nice** if there are `k` odd numbers on it. Return _the number of **nice** sub-arrays_. **Example 1:** **Input:** nums = \[1,1,2,1,1\], k = 3 **Output:** 2 *...
dolphin
[ 0.013900788500905037, 0.03598421439528465, -0.03508523851633072, -0.019912881776690483, 0.0411839634180069, -0.018637824803590775, -0.03235771879553795, 0.04066542163491249, 0.0380360446870327, -0.0010831598192453384, 0.033594995737075806, 0.0042453063651919365, -0.0412679985165596, -0.012...
0.839602
0.778939
0.060663
Please write the following solution using PHP: 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 i = 0 and j = 2, arr\[i\] =...
dolphin
[ 0.01413805317133665, 0.030238203704357147, -0.030407072976231575, -0.03135408088564873, 0.04372088983654976, -0.02525421977043152, -0.019950909540057182, 0.09503122419118881, 0.03413146361708641, -0.013899574987590313, 0.017195606604218483, -0.0034306137822568417, -0.030009672045707703, -0...
0.837625
0.776812
0.060813
Please explain the following problem in detail and provide code in R: Given an integer `k`, _return the minimum number of Fibonacci numbers whose sum is equal to_ `k`. The same Fibonacci number can be used multiple times. The Fibonacci numbers are defined as: * `F1 = 1` * `F2 = 1` * `Fn = Fn-1 + Fn-2` for `n > ...
dolphin
[ 0.009874153882265091, 0.03145458921790123, -0.03878523036837578, -0.0435035340487957, 0.06531352549791336, -0.019845303148031235, -0.021524300798773766, 0.06008349731564522, 0.021991267800331116, 0.006851368583738804, 0.01439997274428606, 0.03001224249601364, -0.034727439284324646, -0.0063...
0.832134
0.776859
0.055275
Please focus on the efficiency of this problem and provide code in c++: Given two integers `n` and `k`, construct a list `answer` that contains `n` different positive integers ranging from `1` to `n` and obeys the following requirement: * Suppose this list is `answer = [a1, a2, a3, ... , an]`, then the list `[|a1 - ...
dolphin
[ 0.03941478952765465, 0.02455367147922516, -0.02479739673435688, -0.042486611753702164, 0.041368111968040466, -0.014798449352383614, -0.02515033259987831, 0.09080281108617783, 0.045415520668029785, -0.012533859349787235, 0.03321108594536781, 0.04217057302594185, -0.016540657728910446, -0.00...
0.843394
0.780838
0.062556
Please focus on the algorithm of this problem and provide code in c++: You are given an integer array `nums`. The **absolute sum** of a subarray `[numsl, numsl+1, ..., numsr-1, numsr]` is `abs(numsl + numsl+1 + ... + numsr-1 + numsr)`. Return _the **maximum** absolute sum of any **(possibly empty)** subarray of_ `nums...
dolphin
[ 0.017944490537047386, 0.024318242445588112, -0.020427104085683823, -0.016347190365195274, 0.03134412318468094, -0.011566775850951672, -0.03277425840497017, 0.07992421090602875, 0.048034556210041046, -0.010954347439110279, 0.028714619576931, 0.030694518238306046, -0.02948055788874626, -0.00...
0.830618
0.768742
0.061876
Please write the following solution using java: 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`, `9`, and `16` are perfect...
dolphin
[ 0.019620249047875404, 0.04595052823424339, -0.03121105581521988, -0.05158039927482605, 0.04786356911063194, -0.028585178777575493, -0.025358907878398895, 0.025197884067893028, 0.03555916249752045, -0.0055762603878974915, 0.026441145688295364, 0.032015424221754074, -0.04447493329644203, -0....
0.824294
0.762101
0.062192
Please write the following solution using Dart: Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. **Note:** You can only move either down or right at any point in time. **Example 1:** **Input:** grid = \[\[1,3,1\...
dolphin
[ -0.0007226067828014493, 0.014518625102937222, -0.024009574204683304, -0.045956604182720184, 0.038328684866428375, -0.029137685894966125, -0.037916187196969986, 0.04166227579116821, 0.041421953588724136, -0.01434436347335577, 0.01090182363986969, 0.03887009993195534, -0.026898115873336792, ...
0.837757
0.775971
0.061786
Please write the following solution using javascript: You are given an integer `num`. You know that Danny Mittal will sneakily **remap** one of the `10` possible digits (`0` to `9`) to another digit. Return _the difference between the maximum and minimum_ _values Danny can make by remapping **exactly** **one** digit_ ...
dolphin
[ 0.02302398905158043, 0.019629912450909615, -0.01608855463564396, -0.02616608329117298, 0.027845239266753197, -0.025191882625222206, -0.024863269180059433, 0.05571727827191353, 0.03498142212629318, -0.021707404404878616, 0.029292238876223564, 0.043793562799692154, -0.048014700412750244, -0....
0.847812
0.792814
0.054998
Please explain the following problem in detail and provide code in Julia: Given an integer `n`, return all the numbers in the range `[1, n]` sorted in lexicographical order. You must write an algorithm that runs in `O(n)` time and uses `O(1)` extra space. **Example 1:** **Input:** n = 13 **Output:** \[1,10,11,12,13,...
dolphin
[ 0.02401678077876568, 0.03606243059039116, -0.0256090946495533, -0.033075254410505295, 0.030544960871338844, -0.025885799899697304, -0.038068704307079315, 0.040390804409980774, 0.023402931168675423, -0.0075761862099170685, 0.021599676460027695, 0.03554235398769379, -0.0416036956012249, -0.0...
0.841274
0.782281
0.058992
Please write the following solution using ANSI C: Given a `root` of an [N-ary tree](https://leetcode.com/articles/introduction-to-n-ary-trees/), you need to compute the length of the diameter of the tree. The diameter of an N-ary tree is the length of the **longest** path between any two nodes in the tree. This path m...
dolphin
[ 0.021213507279753685, 0.037970513105392456, -0.015434023924171925, -0.04362139850854874, 0.023302026093006134, -0.041314736008644104, -0.03560149297118187, 0.05249454453587532, 0.019625764340162277, -0.023587767034769058, 0.04682421684265137, 0.018917908892035484, -0.03314013406634331, -0....
0.823108
0.7649
0.058208
Please focus on the algorithm of this problem and provide code in Kotlin: You are given an integer array of unique positive integers `nums`. Consider the following graph: * There are `nums.length` nodes, labeled `nums[0]` to `nums[nums.length - 1]`, * There is an undirected edge between `nums[i]` and `nums[j]` if ...
dolphin
[ 0.019353579729795456, 0.036686476320028305, -0.020129092037677765, -0.023894891142845154, 0.02604961208999157, -0.012049863114953041, -0.024563627317547798, 0.054925587028265, 0.020941095426678658, -0.012597845867276192, 0.029112426564097404, 0.032917384058237076, -0.01807299070060253, -0....
0.846266
0.782115
0.064152
Please explain the reasoning behind the following solution and provide code in python: There is an undirected graph consisting of `n` nodes numbered from `0` to `n - 1`. You are given a **0-indexed** integer array `vals` of length `n` where `vals[i]` denotes the value of the `ith` node. You are also given a 2D integer...
dolphin
[ 0.011252160184085369, 0.04221804812550545, -0.031246453523635864, -0.028977464884519577, 0.04129793494939804, -0.022896485403180122, -0.021174106746912003, 0.05071154609322548, 0.02857077307999134, -0.0024409235920757055, 0.04028141871094704, 0.027849124744534492, -0.009893747977912426, 0....
0.840088
0.784384
0.055704
Please focus on the functionality of this problem and provide code in c++: Given a `m x n` matrix `mat` and an integer `k`, return _a matrix_ `answer` _where each_ `answer[i][j]` _is the sum of all elements_ `mat[r][c]` _for_: * `i - k <= r <= i + k,` * `j - k <= c <= j + k`, and * `(r, c)` is a valid position i...
dolphin
[ 0.023565856739878654, 0.015095707960426807, -0.029114708304405212, -0.051628097891807556, 0.059786248952150345, -0.021588444709777832, -0.022261470556259155, 0.09585963189601898, 0.042528990656137466, -0.014994963072240353, 0.01925128698348999, 0.03919219970703125, -0.03918212279677391, -0...
0.830303
0.775057
0.055246
Please write the following solution using Swift: Given a 2D integer array `nums` where `nums[i]` is a non-empty array of **distinct** positive integers, return _the list of integers that are present in **each array** of_ `nums` _sorted in **ascending order**_. **Example 1:** **Input:** nums = \[\[**3**,1,2,**4**,5\],...
dolphin
[ 0.01272515021264553, 0.03768130764365196, -0.01460762694478035, -0.017802154645323753, 0.05004757270216942, -0.022083275020122528, -0.025793977081775665, 0.04833530634641647, 0.03993666172027588, -0.016321726143360138, 0.02981150522828102, 0.005895713344216347, -0.03420087695121765, -0.008...
0.834346
0.779147
0.055199
Please write the following solution using Go: You are given a **0-indexed** integer array `nums`. You can rearrange the elements of `nums` to **any order** (including the given order). Let `prefix` be the array containing the prefix sums of `nums` after rearranging it. In other words, `prefix[i]` is the sum of the ele...
dolphin
[ 0.009110584855079651, 0.01912815496325493, -0.004092995543032885, -0.02883146144449711, 0.024975130334496498, -0.01135935727506876, -0.03297353535890579, 0.0416780486702919, 0.03609028086066246, 0.0011117591056972742, 0.008748394437134266, 0.02250250242650509, -0.04256599023938179, -0.0134...
0.842886
0.78667
0.056216
Please write the following solution using Dart: You are given an integer array `arr`. We split `arr` into some number of **chunks** (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array. Return _the largest number of chunks we can make to sort the arr...
dolphin
[ 0.05157579481601715, 0.024859648197889328, -0.005594805348664522, -0.020250461995601654, 0.02284780517220497, -0.009266532026231289, -0.038710229098796844, 0.028405172750353813, 0.03277314454317093, -0.015430165454745293, 0.015923157334327698, 0.021996457129716873, -0.02823837287724018, -0...
0.841156
0.778435
0.06272
Please explain the following problem in detail and provide code in Groovy: You are given an integer array `nums`. The **absolute sum** of a subarray `[numsl, numsl+1, ..., numsr-1, numsr]` is `abs(numsl + numsl+1 + ... + numsr-1 + numsr)`. Return _the **maximum** absolute sum of any **(possibly empty)** subarray of_ `...
dolphin
[ 0.018730081617832184, 0.02963021583855152, -0.025473780930042267, -0.029509413987398148, 0.03322574123740196, -0.024557774886488914, -0.0255436971783638, 0.027552857995033264, 0.050036970525979996, -0.01424526609480381, 0.03265688940882683, 0.026872508227825165, -0.030216285958886147, -0.0...
0.831674
0.776886
0.054788
Please write the following solution using C#: You have a set of integers `s`, which originally contains all the numbers from `1` to `n`. Unfortunately, due to some error, one of the numbers in `s` got duplicated to another number in the set, which results in **repetition of one** number and **loss of another** number. ...
dolphin
[ 0.020619770511984825, 0.021564023569226265, -0.022666919976472855, -0.025226114317774773, 0.04144861549139023, -0.02768305502831936, -0.028198231011629105, 0.09041313827037811, 0.03216678649187088, -0.014989680610597134, 0.02926611341536045, 0.006187996361404657, -0.03063340298831463, -0.0...
0.848714
0.791004
0.057711
Please write the following solution using Clojure: Given a **0-indexed** integer array `nums` of length `n` and an integer `k`, return _the **number of pairs**_ `(i, j)` _such that:_ * `0 <= i < j <= n - 1` _and_ * `nums[i] * nums[j]` _is divisible by_ `k`. **Example 1:** **Input:** nums = \[1,2,3,4,5\], k = 2 *...
dolphin
[ 0.01890791580080986, 0.050231773406267166, -0.04044073820114136, -0.025509756058454514, 0.05458531901240349, -0.026171721518039703, -0.01970340497791767, 0.055963046848773956, 0.026858365163207054, -0.012208368629217148, 0.021737078204751015, 0.023484187200665474, -0.014818146824836731, -0...
0.843193
0.785392
0.0578
Please write the following solution using Scheme: Given an integer array `arr` of **distinct** integers and an integer `k`. A game will be played between the first two elements of the array (i.e. `arr[0]` and `arr[1]`). In each round of the game, we compare `arr[0]` with `arr[1]`, the larger integer wins and remains a...
dolphin
[ 0.030133100226521492, 0.05390389636158943, -0.021202901378273964, -0.037963222712278366, 0.041004475206136703, -0.03489510715007782, -0.05821211636066437, 0.05623884126543999, 0.040369536727666855, -0.023626534268260002, 0.02992342785000801, 0.02473190240561962, -0.031669795513153076, 0.00...
0.845202
0.778451
0.066751
Please write the following solution using javascript: You are given a string `s` of length `n` where `s[i]` is either: * `'D'` means decreasing, or * `'I'` means increasing. A permutation `perm` of `n + 1` integers of all the integers in the range `[0, n]` is called a **valid permutation** if for all valid `i`: ...
dolphin
[ 0.007333927322179079, 0.021387556567788124, -0.024659939110279083, -0.03451594337821007, 0.03784608468413353, -0.02935563400387764, -0.02099141664803028, 0.06356032937765121, 0.029965940862894058, -0.015940124168992043, 0.02595020830631256, 0.025359036400914192, -0.03814522549510002, -0.02...
0.856494
0.799113
0.057381
Please write the following solution using Visual Basic .NET: An integer has **monotone increasing digits** if and only if each pair of adjacent digits `x` and `y` satisfy `x <= y`. Given an integer `n`, return _the largest number that is less than or equal to_ `n` _with **monotone increasing digits**_. **Example 1:**...
dolphin
[ 0.03637821599841118, 0.02707618661224842, -0.02952490746974945, -0.03537282347679138, 0.01384846679866314, -0.03338265419006348, -0.025503847748041153, 0.07145638763904572, 0.03279703110456467, -0.0028559828642755747, 0.03389648720622063, 0.040402933955192566, -0.06552285701036453, -0.0103...
0.83301
0.770607
0.062403
Please focus on the algorithm of this problem and provide code in R: Given an binary array `nums` and an integer `k`, return `true` _if all_ `1`_'s are at least_ `k` _places away from each other, otherwise return_ `false`. **Example 1:** **Input:** nums = \[1,0,0,0,1,0,0,1\], k = 2 **Output:** true **Explanation:** E...
dolphin
[ 0.002455188427120447, 0.03319375216960907, -0.02058257721364498, -0.028551826253533363, 0.0382683239877224, -0.03047308139503002, -0.023526567965745926, 0.07707618921995163, 0.023212267085909843, -0.008704125881195068, 0.013767004013061523, 0.023396577686071396, -0.016373461112380028, -0.0...
0.845439
0.787192
0.058247