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 following problem in detail and provide code in python: On an `2 x 3` board, there are five tiles labeled from `1` to `5`, and an empty square represented by `0`. A **move** consists of choosing `0` and a 4-directionally adjacent number and swapping it. The state of the board is solved if and only i...
dolphin
[ 0.01648164540529251, 0.02951439656317234, -0.035446736961603165, -0.031395670026540756, 0.04723392426967621, -0.023653991520404816, -0.03464628383517265, 0.04824003204703331, 0.023894699290394783, -0.0016755881952121854, 0.01913321018218994, 0.009213761426508427, -0.021769452840089798, -0....
0.846068
0.792164
0.053904
Please write the following solution using Mojo: You are given an `m x n` integer matrix `matrix` with the following two properties: * Each row is sorted in non-decreasing order. * The first integer of each row is greater than the last integer of the previous row. Given an integer `target`, return `true` _if_ `tar...
dolphin
[ 0.03309653326869011, 0.017557596787810326, -0.03338950127363205, -0.0415593683719635, 0.04941479116678238, -0.02956284210085869, -0.023622220382094383, 0.07148555666208267, 0.03134724497795105, -0.026993878185749054, 0.012544693425297737, 0.010463486425578594, -0.03142821416258812, -0.0250...
0.8453
0.789321
0.055979
Please focus on the algorithm of this problem and provide code in Objective-C: There is an undirected tree with `n` nodes labeled from `0` to `n - 1` and `n - 1` edges. You are given 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 ...
dolphin
[ 0.019883999601006508, 0.03206690400838852, -0.010532408952713013, -0.02602885290980339, 0.022890198975801468, -0.043398670852184296, -0.018811862915754318, 0.06747785210609436, 0.019032148644328117, -0.005719074979424477, 0.03830434009432793, 0.01755964197218418, -0.031591545790433884, -0....
0.844289
0.79102
0.053269
Please write the following solution using C#: Given an integer array `nums` of length `n`, you want to create an array `ans` of length `2n` where `ans[i] == nums[i]` and `ans[i + n] == nums[i]` for `0 <= i < n` (**0-indexed**). Specifically, `ans` is the **concatenation** of two `nums` arrays. Return _the array_ `ans...
dolphin
[ 0.027436669915914536, 0.028499474748969078, -0.025626178830862045, -0.026024814695119858, 0.04081035777926445, -0.042726293206214905, -0.019347889348864555, 0.08164779841899872, 0.038835711777210236, -0.010373057797551155, 0.017895853146910667, 0.014597013592720032, -0.041088398545980453, ...
0.835741
0.779019
0.056722
Please write the following solution using Scheme: There are `n` people and `40` types of hats labeled from `1` to `40`. Given a 2D integer array `hats`, where `hats[i]` is a list of all hats preferred by the `ith` person. Return _the number of ways that the `n` people wear different hats to each other_. Since the an...
dolphin
[ 0.036907486617565155, 0.03157364949584007, -0.02276550978422165, -0.0035636709071695805, 0.02860761061310768, -0.04687574505805969, -0.03887007758021355, 0.030588652938604355, 0.024250250309705734, -0.025440016761422157, 0.021550800651311874, 0.027107063680887222, -0.03439704701304436, -0....
0.828909
0.773996
0.054913
Please write the following solution using PHP: You are given a **0-indexed** integer array `nums` of length `n`. The number of ways to **partition** `nums` is the number of `pivot` indices that satisfy both conditions: * `1 <= pivot < n` * `nums[0] + nums[1] + ... + nums[pivot - 1] == nums[pivot] + nums[pivot + 1]...
dolphin
[ 0.02794128656387329, 0.034548453986644745, -0.02711041457951069, 0.00006784636207157746, 0.024929190054535866, -0.02469955012202263, -0.01644246093928814, 0.07010917365550995, 0.03982558473944664, 0.00010685814049793407, 0.027155930176377296, 0.017672214657068253, -0.03446401283144951, 0.0...
0.840286
0.784503
0.055783
Please write the following solution using Objective-C: Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**. Return _the minimized largest sum of the split_. A **subarray** is a contiguous part of the array. **Example 1...
dolphin
[ 0.02164648473262787, 0.035264428704977036, -0.03911950811743736, -0.02755068615078926, 0.04670014977455139, -0.00540458969771862, -0.025823216885328293, 0.0583932027220726, 0.03425418958067894, -0.01186134573072195, 0.04159064590930939, 0.024002108722925186, -0.03904798626899719, 0.0093872...
0.83257
0.769602
0.062968
Please explain the following problem in detail and provide code in Mojo: 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[j...
dolphin
[ 0.020154418423771858, 0.0375218465924263, -0.027286650612950325, -0.03114575706422329, 0.05557829886674881, -0.02636580355465412, -0.03197604417800903, 0.04151131585240364, 0.04330267012119293, -0.017926743254065514, 0.027594532817602158, 0.015800105407834053, -0.020479777827858925, 0.0047...
0.845057
0.786462
0.058595
Please write the following solution using R: Given an integer array `nums`, reorder it such that `nums[0] < nums[1] > nums[2] < nums[3]...`. You may assume the input array always has a valid answer. **Example 1:** **Input:** nums = \[1,5,1,1,6,4\] **Output:** \[1,6,1,5,1,4\] **Explanation:** \[1,4,1,5,1,6\] is also ...
dolphin
[ 0.02067640982568264, 0.0412958562374115, -0.007325951941311359, -0.016605284065008163, 0.028133990243077278, -0.01118298526853323, -0.033435337245464325, 0.05526766926050186, 0.04040826857089996, 0.002212641993537545, 0.0016075868625193834, 0.007048453204333782, -0.041691672056913376, -0.0...
0.827491
0.773124
0.054367
Please explain the reasoning behind the following solution and provide code in c++: A digit string is **good** if the digits **(0-indexed)** at **even** indices are **even** and the digits at **odd** indices are **prime** (`2`, `3`, `5`, or `7`). * For example, `"2582 "` is good because the digits (`2` and `8`) at e...
dolphin
[ 0.007538261823356152, -0.002352016279473901, -0.027033232152462006, -0.0466044656932354, 0.025708502158522606, -0.04045398160815239, -0.026925846934318542, 0.07493376731872559, 0.02196437679231167, -0.004963123705238104, 0.014301847666501999, 0.03409618139266968, -0.037359122186899185, -0....
0.836837
0.781898
0.054938
Please focus on the efficiency of this problem and provide code in javascript: 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 wi...
dolphin
[ 0.02321036159992218, 0.02775781787931919, -0.02687644027173519, -0.023677963763475418, 0.023962117731571198, -0.01778561621904373, -0.047476980835199356, 0.05864660069346428, 0.04267241060733795, -0.017480023205280304, 0.026323623955249786, 0.024966470897197723, -0.03073468990623951, -0.00...
0.847125
0.784021
0.063105
Please focus on the algorithm of this problem and provide code in PHP: You are given a **0-indexed** integer array `piles`, where `piles[i]` represents the number of stones in the `ith` pile, and an integer `k`. You should apply the following operation **exactly** `k` times: * Choose any `piles[i]` and **remove** `f...
dolphin
[ 0.01998640038073063, 0.03609038516879082, -0.020609848201274872, -0.013100968673825264, 0.02657703123986721, -0.044190868735313416, -0.03449150174856186, 0.07562925666570663, 0.03754039108753204, -0.009186499752104282, 0.030536530539393425, 0.022230185568332672, -0.025150081142783165, 0.00...
0.84512
0.791397
0.053723
Please focus on the efficiency of this problem and provide code in Scala: You are given a **0-indexed** array of non-negative integers `nums`. For each integer in `nums`, you must find its respective **second greater** integer. The **second greater** integer of `nums[i]` is `nums[j]` such that: * `j > i` * `nums[...
dolphin
[ 0.027155837044119835, 0.03809187188744545, -0.022957848384976387, -0.03304056450724602, 0.022858260199427605, -0.015746599063277245, -0.023735286667943, 0.06359022110700607, 0.03703070431947708, -0.026717212051153183, 0.03496395796537399, 0.0271507129073143, -0.03844156116247177, -0.005484...
0.84756
0.79192
0.05564
Please write the following solution using Groovy: Given an array `nums` of positive integers, return the longest possible length of an array prefix of `nums`, such that it is possible to remove **exactly one** element from this prefix so that every number that has appeared in it will have the same number of occurrences...
dolphin
[ 0.02178920805454254, 0.01933225430548191, -0.030560076236724854, -0.03269381448626518, 0.028462817892432213, -0.03531932830810547, -0.03202260658144951, 0.04580143839120865, 0.04076915234327316, -0.018016410991549492, 0.015213049948215485, 0.008663860149681568, -0.009030163288116455, -0.01...
0.849131
0.786684
0.062447
Please write the following solution using C#: Given an integer array `nums` of size `n`, return _the number with the value **closest** to_ `0` _in_ `nums`. If there are multiple answers, return _the number with the **largest** value_. **Example 1:** **Input:** nums = \[-4,-2,1,4,8\] **Output:** 1 **Explanation:** The...
dolphin
[ 0.02854461595416069, 0.040471743792295456, -0.02178199589252472, -0.026770081371068954, 0.03969715163111687, -0.0375962108373642, -0.03334720432758331, 0.0654267817735672, 0.03290985897183418, -0.01661120168864727, 0.025036582723259926, 0.03253460302948952, -0.0373774878680706, -0.02847977...
0.833389
0.767395
0.065994
Please focus on the efficiency of this problem and provide code in python: You are given a square `board` of characters. You can move on the board starting at the bottom right square marked with the character `'S'`. You need to reach the top left square marked with the character `'E'`. The rest of the squares are labe...
dolphin
[ 0.029138047248125076, 0.013577019795775414, -0.028877459466457367, -0.04061521217226982, 0.018168697133660316, -0.01932835951447487, -0.021706465631723404, 0.046721357852220535, 0.031696561723947525, -0.017701882869005203, 0.036734599620103836, 0.043797675520181656, -0.01590816117823124, -...
0.848084
0.793861
0.054223
Please focus on the efficiency of this problem and provide code in Dart: 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 modified array....
dolphin
[ 0.019671013578772545, 0.03687760978937149, -0.00940709002315998, -0.04111886024475098, 0.03689431771636009, -0.029382210224866867, -0.03449512645602226, 0.05043787136673927, 0.031138963997364044, -0.0249287411570549, 0.028387052938342094, 0.022401245310902596, -0.03396822512149811, 0.01154...
0.844495
0.788123
0.056372
Please explain the following problem in detail and provide code in Object Pascal: The **alternating sum** of a **0-indexed** array is defined as the **sum** of the elements at **even** indices **minus** the **sum** of the elements at **odd** indices. * For example, the alternating sum of `[4,2,5,3]` is `(4 + 5) - (2...
dolphin
[ 0.006371666211634874, 0.026009157299995422, -0.008132068440318108, -0.019603842869400978, 0.030185744166374207, -0.021697470918297768, -0.02555661089718342, 0.04911584034562111, 0.04333184286952019, -0.002406799467280507, 0.017056750133633614, 0.019399136304855347, -0.0508582666516304, 0.0...
0.834722
0.772778
0.061945
Please focus on the efficiency of this problem and provide code in Perl: 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` an...
dolphin
[ 0.005305605474859476, 0.02704109251499176, -0.028830671682953835, -0.03581822291016579, 0.008524863049387932, -0.012028712779283524, -0.013763559982180595, 0.06379345059394836, 0.021110957488417625, -0.0029174797236919403, 0.040691591799259186, 0.02672836184501648, -0.010622811503708363, -...
0.851907
0.796667
0.055239
Please explain the following problem in detail and provide code in Kotlin: Given a binary array `nums`, return _the maximum number of consecutive_ `1`_'s in the array_. **Example 1:** **Input:** nums = \[1,1,0,1,1,1\] **Output:** 3 **Explanation:** The first two digits or the last three digits are consecutive 1s. The...
dolphin
[ 0.013945546001195908, 0.03639335185289383, -0.003464731387794018, -0.04237362742424011, 0.04149831831455231, -0.028541212901473045, -0.03996600583195686, 0.052732665091753006, 0.02900298498570919, -0.02272358350455761, 0.027690701186656952, 0.017075473442673683, -0.027183447033166885, 0.00...
0.839376
0.775319
0.064056
Please explain the following problem in detail and provide code in Kotlin: You are given an integer array `coins` (**1-indexed**) of length `n` and an integer `maxJump`. You can jump to any index `i` of the array `coins` if `coins[i] != -1` and you have to pay `coins[i]` when you visit index `i`. In addition to that, i...
dolphin
[ 0.004731134045869112, 0.02808227390050888, -0.007205350324511528, -0.02194085344672203, 0.03420528396964073, -0.02701854333281517, -0.018816445022821426, 0.056228432804346085, 0.02277010679244995, -0.020211508497595787, 0.03622771427035332, 0.03149205446243286, -0.021883442997932434, -0.00...
0.847544
0.791887
0.055657
Please explain the following problem in detail and provide code in ANSI C: You are given a **sorted unique** integer array `nums`. A **range** `[a,b]` is the set of all integers from `a` to `b` (inclusive). Return _the **smallest sorted** list of ranges that **cover all the numbers in the array exactly**_. That is, e...
dolphin
[ 0.015610933303833008, 0.03671756759285927, -0.02907002530992031, -0.025457045063376427, 0.030698832124471664, -0.04163217172026634, -0.023498304188251495, 0.06648506224155426, 0.0375053845345974, -0.0221419595181942, 0.02191757969558239, 0.024650530889630318, -0.034549862146377563, -0.0196...
0.84115
0.782883
0.058267
Please focus on the efficiency of this problem and provide code in R: Given an integer array `nums`, return _an integer array_ `counts` _where_ `counts[i]` _is the number of smaller elements to the right of_ `nums[i]`. **Example 1:** **Input:** nums = \[5,2,6,1\] **Output:** \[2,1,1,0\] **Explanation:** To the right ...
dolphin
[ 0.018048729747533798, 0.04531930759549141, -0.03185872733592987, -0.019244598224759102, 0.01782081089913845, 0.003013073233887553, -0.029372241348028183, 0.06267500668764114, 0.037836164236068726, 0.0038837227039039135, 0.009356160648167133, 0.029912319034337997, -0.028889669105410576, -0....
0.838338
0.776427
0.061911
Please focus on the algorithm of this problem and provide code in ANSI C: 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 subarr...
dolphin
[ 0.0114591084420681, 0.03129839152097702, -0.029074031859636307, -0.030182473361492157, 0.0463130958378315, -0.03464522212743759, -0.017871171236038208, 0.07603631913661957, 0.023633351549506187, -0.017865903675556183, 0.02500021830201149, 0.02644294872879982, -0.02372654154896736, -0.00211...
0.846269
0.789663
0.056606
Please write the following solution using ANSI C: You are given an `m x n` integer matrix `grid`, where you can move from a cell to any adjacent cell in all `4` directions. Return _the number of **strictly** **increasing** paths in the grid such that you can start from **any** cell and end at **any** cell._ Since the ...
dolphin
[ 0.02382451668381691, 0.03480684384703636, -0.00336147821508348, -0.04110753908753395, 0.03006461076438427, -0.04218887537717819, -0.03993327543139458, 0.061169225722551346, 0.03125738352537155, -0.02528153732419014, 0.027333954349160194, 0.011084232479333878, -0.04225044697523117, -0.02931...
0.845611
0.784933
0.060678
Please write the following solution using Scheme: 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 example, if `nums = [1,2,3,1]...
dolphin
[ 0.024032434448599815, 0.0224462877959013, -0.020462509244680405, -0.021904028952121735, 0.03481636941432953, -0.0237713810056448, -0.0334443598985672, 0.05963810160756111, 0.034061722457408905, -0.006321460474282503, 0.017647016793489456, 0.015598566271364689, -0.02827037125825882, -0.0178...
0.854226
0.786734
0.067492
Please explain the reasoning behind the following solution and provide code in Scheme: You are given two integer arrays `nums1` and `nums2` of lengths `m` and `n` respectively. `nums1` and `nums2` represent the digits of two numbers. You are also given an integer `k`. Create the maximum number of length `k <= m + n` f...
dolphin
[ 0.02793034352362156, 0.027860598638653755, -0.030157102271914482, -0.048515815287828445, 0.04132644832134247, -0.025447586551308632, -0.03574483096599579, 0.041884470731019974, 0.03146345168352127, -0.021342584863305092, 0.016215356066823006, 0.03481682762503624, -0.038042426109313965, 0.0...
0.841614
0.782471
0.059143
Please write the following solution using R: The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element. * For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`, and the **XOR sum** of `[3]`...
dolphin
[ 0.011195323430001736, 0.030052535235881805, -0.03255978599190712, -0.03795793652534485, 0.0369182750582695, -0.010928601026535034, -0.0333646722137928, 0.06198577210307121, 0.04564525559544563, -0.0071814474649727345, 0.0018888456979766488, 0.019805649295449257, -0.03228349983692169, -0.02...
0.826726
0.772502
0.054224
Please focus on the algorithm of this problem and provide code in PHP: Given an integer array `arr` and a target value `target`, return the integer `value` such that when we change all the integers larger than `value` in the given array to be equal to `value`, the sum of the array gets as close as possible (in absolute...
dolphin
[ 0.016548477113246918, 0.03124108910560608, -0.026646681129932404, -0.02938828431069851, 0.03724481910467148, -0.032545339316129684, -0.04200991988182068, 0.04539664462208748, 0.041845694184303284, -0.01614896021783352, 0.031969815492630005, 0.02482648566365242, -0.03688665106892586, -0.000...
0.840741
0.782694
0.058047
Please focus on the functionality of this problem and provide code in c++: You are given an integer `n`. Each number from `1` to `n` is grouped according to the sum of its digits. Return _the number of groups that have the largest size_. **Example 1:** **Input:** n = 13 **Output:** 4 **Explanation:** There are 9 gr...
dolphin
[ 0.028283588588237762, 0.03176414966583252, -0.03940944746136665, -0.057665370404720306, 0.045593101531267166, -0.015111429616808891, -0.030013931915163994, 0.0637357234954834, 0.0165754072368145, 0.00055918307043612, 0.027108920738101006, 0.04876510426402092, -0.05510874092578888, -0.01172...
0.833147
0.766586
0.066561
Please write the following solution using javascript: Given two integers n and k, return _an array of all the integers of length_ `n` _where the difference between every two consecutive digits is_ `k`. You may return the answer in **any order**. Note that the integers should not have leading zeros. Integers as `02` an...
dolphin
[ 0.022432010620832443, 0.032199520617723465, -0.030453531071543694, -0.04494859650731087, 0.03927967697381973, -0.027219265699386597, -0.018224136903882027, 0.03905250132083893, 0.03890030086040497, -0.016735246405005455, 0.0416172593832016, 0.028034036979079247, -0.041666414588689804, 0.00...
0.83088
0.775247
0.055633
Please write the following solution using PHP: There is a street with `n * 2` **plots**, where there are `n` plots on each side of the street. The plots on each side are numbered from `1` to `n`. On each plot, a house can be placed. Return _the number of ways houses can be placed such that no two houses are adjacent t...
dolphin
[ 0.021123431622982025, 0.02346980571746826, -0.02116849087178707, -0.010119417682290077, 0.025420574471354485, -0.022990532219409943, -0.0292513445019722, 0.06319332122802734, 0.04626311734318733, -0.009226540103554726, 0.01569213718175888, 0.05760974436998367, -0.038435496389865875, -0.031...
0.838785
0.784149
0.054636
Please write the following solution using java: Given a binary string `s`, return `true` _if the **longest** contiguous segment of_ `1`'_s is **strictly longer** than the **longest** contiguous segment of_ `0`'_s in_ `s`, or return `false` _otherwise_. * For example, in `s = "110100010 "` the longest continuous segm...
dolphin
[ 0.021974559873342514, 0.013963263481855392, -0.035349633544683456, -0.028398625552654266, 0.031244417652487755, -0.05561428144574165, -0.013710925355553627, 0.06359387934207916, 0.02504640258848667, -0.01364569365978241, 0.02401808276772499, 0.018713701516389847, -0.020823456346988678, -0....
0.831526
0.776472
0.055054
Please focus on the functionality of this problem and provide code in Scheme: You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules: * The **most significant digit** is assigned a **positive** sign. * Each other digit has an opposite sign to its adjacent digits. Retur...
dolphin
[ 0.03911760821938515, 0.015326552093029022, -0.049077168107032776, -0.03538934141397476, 0.03138177469372749, -0.046797119081020355, -0.021069712936878204, 0.04961768165230751, 0.03179731220006943, 0.0029718263540416956, 0.024015121161937714, 0.05757530406117439, -0.048525165766477585, -0.0...
0.847443
0.793174
0.054269
Please explain the following problem in detail and provide code in Scheme: You are given two **0-indexed** integer arrays `nums1` and `nums2`, both of length `n`. You can choose two integers `left` and `right` where `0 <= left <= right < n` and **swap** the subarray `nums1[left...right]` with the subarray `nums2[left....
dolphin
[ 0.009666962549090385, 0.024134747684001923, -0.031322333961725235, -0.020918503403663635, 0.02653742954134941, -0.006164562422782183, -0.03776111826300621, 0.04596256464719772, 0.0347571037709713, -0.016082003712654114, 0.020350702106952667, 0.02691921405494213, -0.038537781685590744, -0.0...
0.844336
0.783402
0.060934
Please write the following solution using Clojure: 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. * F...
dolphin
[ 0.02874811552464962, 0.034586742520332336, -0.026179425418376923, -0.03540917485952377, 0.04104740172624588, -0.01733635924756527, -0.018061649054288864, 0.04042430594563484, 0.04179474711418152, -0.0069969287142157555, 0.026802081614732742, 0.020829960703849792, -0.03586357831954956, -0.0...
0.837887
0.779999
0.057889
Please focus on the functionality of this problem and provide code in c++: Given an array of positive integers `nums`, return _an array_ `answer` _that consists of the digits of each integer in_ `nums` _after separating them in **the same order** they appear in_ `nums`. To separate the digits of an integer is to get a...
dolphin
[ 0.046503178775310516, 0.012095367535948753, -0.029479295015335083, -0.038220468908548355, 0.03465377539396286, -0.012583243660628796, -0.029026377946138382, 0.07209693640470505, 0.030351873487234116, -0.009964625351130962, 0.01620430499315262, 0.02849067561328411, -0.04185100644826889, -0....
0.835607
0.775045
0.060562
Please explain the reasoning behind the following solution and provide code in Scheme: 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...
dolphin
[ 0.01944022998213768, 0.032787322998046875, -0.03723999112844467, -0.02240563929080963, 0.05019426718354225, -0.02185843326151371, -0.02962222881615162, 0.049964629113674164, 0.027394266799092293, 0.0030248912516981363, 0.03005829080939293, 0.025234688073396683, -0.035636644810438156, 0.000...
0.838607
0.778537
0.06007
Please write the following solution using ANSI C: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and **it will automatically contact ...
dolphin
[ 0.029280543327331543, 0.04868891090154648, -0.0200376994907856, -0.03231681138277054, 0.028867516666650772, -0.024872850626707077, -0.02758621983230114, 0.05256393924355507, 0.03331654146313667, -0.02738623134791851, 0.03115564025938511, 0.04481521621346474, -0.046280089765787125, -0.04531...
0.839494
0.783784
0.05571
Please write the following solution using Perl: Given an integer array `nums` of **unique** elements, 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,3\] **Output:** \[\[\],\[1\],\...
dolphin
[ 0.043842315673828125, 0.026161788031458855, -0.013280807062983513, -0.0198250450193882, 0.048769500106573105, -0.03265129774808884, -0.005577470641583204, 0.05475099757313728, 0.059521421790122986, -0.018774667754769325, 0.03811713308095932, 0.029726862907409668, -0.04395949840545654, -0.0...
0.829605
0.774354
0.055251
Please explain the reasoning behind the following solution and provide code in javascript: 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` a...
dolphin
[ 0.0161061342805624, 0.027758780866861343, -0.02944793738424778, -0.01786002516746521, 0.05313652381300926, -0.014293303713202477, -0.02213473618030548, 0.06837653368711472, 0.032765571027994156, -0.017077013850212097, 0.013278716243803501, 0.003457151586189866, -0.03240122273564339, -0.007...
0.854501
0.800003
0.054498
Please focus on the algorithm of this problem and provide code in ANSI C: You are given a **directed** graph of `n` nodes numbered from `0` to `n - 1`, where each node has **at most one** outgoing edge. The graph is represented with a given **0-indexed** array `edges` of size `n`, indicating that there is a directed e...
dolphin
[ 0.01041669026017189, 0.03803587704896927, -0.015326259657740593, -0.02765539474785328, 0.018318185582756996, -0.029135774821043015, -0.02762082777917385, 0.07718202471733093, 0.029413094744086266, -0.02699624001979828, 0.03558987379074097, 0.021929001435637474, -0.019488994032144547, -0.01...
0.845253
0.787283
0.05797
Please explain the following problem in detail and provide code in python: 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, o...
dolphin
[ 0.02707083709537983, 0.05011005327105522, -0.027713773772120476, -0.03837629407644272, 0.04799389839172363, -0.04159092903137207, -0.019482174888253212, 0.047933436930179596, 0.04614776372909546, -0.011309388093650341, 0.024093829095363617, -0.009608618915081024, -0.005242514424026012, 0.0...
0.846935
0.785878
0.061057
Please explain the following problem in detail and provide code in Perl: You are given an array of integers `nums` and an integer `target`. Return _the number of **non-empty** subsequences of_ `nums` _such that the sum of the minimum and maximum element on it is less or equal to_ `target`. Since the answer may be too ...
dolphin
[ 0.006898989900946617, 0.0073558189906179905, -0.03345772624015808, -0.03450607880949974, 0.05764583870768547, -0.00010318405111320317, -0.026411356404423714, 0.04777850955724716, 0.02324586920440197, -0.0015536727150902152, 0.027712507173419, 0.04812834411859512, -0.041878797113895416, -0....
0.844284
0.789679
0.054605
Please write the following solution using Scheme: Suppose you have `n` integers labeled `1` through `n`. A permutation of those `n` integers `perm` (**1-indexed**) is considered a **beautiful arrangement** if for every `i` (`1 <= i <= n`), **either** of the following is true: * `perm[i]` is divisible by `i`. * `i`...
dolphin
[ 0.048007212579250336, 0.03962248936295509, -0.028182802721858025, -0.038497257977724075, 0.0356147363781929, -0.03019065596163273, -0.03822408244013786, 0.05737566202878952, 0.03323271870613098, -0.005741060245782137, 0.03372539207339287, 0.014177949167788029, -0.027015015482902527, -0.011...
0.83642
0.768435
0.067985
Please write the following solution using python: You are given a **0-indexed** binary array `nums` of length `n`. `nums` can be divided at index `i` (where `0 <= i <= n)` into two arrays (possibly empty) `numsleft` and `numsright`: * `numsleft` has all the elements of `nums` between index `0` and `i - 1` **(inclusi...
dolphin
[ 0.03452450782060623, 0.026971548795700073, -0.031161431223154068, -0.01790793426334858, 0.03210862725973129, -0.03114287368953228, -0.03301141411066055, 0.053758345544338226, 0.04131101444363594, -0.004763034638017416, 0.01904292218387127, 0.015123272314667702, -0.02378545142710209, -0.005...
0.852039
0.786397
0.065641
Please explain the following problem in detail and provide code in PHP: 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 modified array. ...
dolphin
[ 0.027445849031209946, 0.042112600058317184, -0.014968765899538994, -0.0387183278799057, 0.04895349591970444, -0.03004828467965126, -0.028427984565496445, 0.05624183639883995, 0.03129509463906288, -0.021346155554056168, 0.03138500824570656, 0.021495992317795753, -0.041183847934007645, 0.011...
0.840215
0.77702
0.063196
Please write the following solution using Scheme: You are given an array `arr` of positive integers. You are also given the array `queries` where `queries[i] = [lefti, righti]`. For each query `i` compute the **XOR** of elements from `lefti` to `righti` (that is, `arr[lefti] XOR arr[lefti + 1] XOR ... XOR arr[righti]`...
dolphin
[ 0.046177856624126434, 0.03448346257209778, -0.02799523063004017, -0.022137371823191643, 0.024929028004407883, -0.02834305167198181, -0.03236902505159378, 0.05891243368387222, 0.05386348441243172, -0.011583248153328896, 0.02262788452208042, 0.0014091485645622015, -0.0402597151696682, -0.015...
0.844705
0.787894
0.056811
Please write the following solution using Mojo: You are given an **even** number of people `numPeople` that stand around a circle and each person shakes hands with someone else so that there are `numPeople / 2` handshakes total. Return _the number of ways these handshakes could occur such that none of the handshakes c...
dolphin
[ 0.03923603892326355, 0.01969020813703537, -0.034033630043268204, -0.025170637294650078, 0.03358636796474457, -0.019887281581759453, -0.029704008251428604, 0.027256712317466736, 0.02438393048942089, -0.03356454148888588, 0.031533390283584595, 0.03774716705083847, -0.024869132786989212, -0.0...
0.8292
0.769707
0.059493
Please write the following solution using java: Given an `m x n` binary matrix `mat`, _return the number of **submatrices** that have all ones_. **Example 1:** **Input:** mat = \[\[1,0,1\],\[1,1,0\],\[1,1,0\]\] **Output:** 13 **Explanation:** There are 6 rectangles of side 1x1. There are 2 rectangles of side 1x2. Th...
dolphin
[ 0.01798653043806553, 0.01938566006720066, -0.036100734025239944, -0.033775534480810165, 0.04132566973567009, -0.02771034836769104, -0.025652805343270302, 0.04626883193850517, 0.026668529957532883, -0.00791822001338005, 0.016318464651703835, 0.023995397612452507, -0.0321270152926445, -0.027...
0.832144
0.770455
0.061689
Please write the following solution using ANSI C: Given a binary tree where node values are digits from 1 to 9. A path in the binary tree is said to be **pseudo-palindromic** if at least one permutation of the node values in the path is a palindrome. _Return the number of **pseudo-palindromic** paths going from the ro...
dolphin
[ 0.00472616171464324, 0.024290289729833603, -0.03421827033162117, -0.0353943407535553, 0.02004307322204113, -0.03817444294691086, -0.012748576700687408, 0.08198923617601395, 0.021202178671956062, -0.015482340939342976, 0.035787809640169144, 0.009986963123083115, -0.04788004234433174, -0.021...
0.84012
0.781308
0.058812
Please explain the following problem in detail and provide code in Scheme: The **product sum** of two equal-length arrays `a` and `b` is equal to the sum of `a[i] * b[i]` for all `0 <= i < a.length` (**0-indexed**). * For example, if `a = [1,2,3,4]` and `b = [5,2,3,1]`, the **product sum** would be `1*5 + 2*2 + 3*3 ...
dolphin
[ 0.017527569085359573, 0.030132675543427467, -0.027906937524676323, -0.022272057831287384, 0.054363492876291275, -0.01081387884914875, -0.03200351074337959, 0.06185664236545563, 0.033677369356155396, -0.011275624856352806, 0.004603957291692495, 0.016394538804888725, -0.03641434386372566, -0...
0.833986
0.776288
0.057699
Please explain the following problem in detail and provide code in Scheme: You are given an array `pairs`, where `pairs[i] = [xi, yi]`, and: * There are no duplicates. * `xi < yi` Let `ways` be the number of rooted trees that satisfy the following conditions: * The tree consists of nodes whose values appeared ...
dolphin
[ 0.01572216860949993, 0.029147285968065262, -0.02520003542304039, -0.01469447836279869, 0.019689161330461502, -0.023056650534272194, -0.0028745662420988083, 0.0717553049325943, 0.025366920977830887, -0.017821218818426132, 0.027285395190119743, 0.012218715623021126, -0.021633852273225784, -0...
0.848805
0.794641
0.054165
Please write the following solution using Lua: You are given a **0-indexed** integer array `arr` and an integer `k`. The array `arr` is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array is the previous element of the first element. You c...
dolphin
[ 0.004367531277239323, 0.046240177005529404, -0.03580109030008316, -0.05130552873015404, 0.04933170974254608, -0.01441931538283825, -0.03746519982814789, 0.05370123311877251, 0.0301964171230793, -0.012366009876132011, 0.030775463208556175, 0.004049173556268215, -0.02414017915725708, -0.0038...
0.856358
0.799844
0.056514
Please explain the reasoning behind the following solution and provide code in c++: Given an integer array `nums`, your goal is to make all elements in `nums` equal. To complete one operation, follow these steps: 1. Find the **largest** value in `nums`. Let its index be `i` (**0-indexed**) and its value be `largest`....
dolphin
[ 0.028996363282203674, 0.019003817811608315, -0.031909260898828506, -0.038905069231987, 0.036416199058294296, -0.014413321390748024, -0.023664895445108414, 0.09955790638923645, 0.03011089563369751, -0.027185121551156044, 0.03375577926635742, 0.033141426742076874, -0.031089486554265022, 0.00...
0.839919
0.782636
0.057283
Please write the following solution using Scala: 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`, a...
dolphin
[ 0.012700360268354416, 0.019649647176265717, -0.04232747107744217, -0.014058140106499195, 0.043571677058935165, -0.0208110548555851, -0.025917623192071915, 0.027359504252672195, 0.026844246312975883, -0.008207864128053188, 0.040596578270196915, 0.028958894312381744, -0.02434302493929863, 0....
0.833902
0.771652
0.062251
Please write the following solution using ANSI C: You are given a **0-indexed** integer array `order` of length `n`, a **permutation** of integers from `1` to `n` representing the **order** of insertion into a **binary search tree**. A binary search tree is defined as follows: * The left subtree of a node contains ...
dolphin
[ 0.023061025887727737, 0.02991214022040367, -0.023254593834280968, -0.030036093667149544, 0.017910225316882133, -0.03306811675429344, -0.022846274077892303, 0.06387994438409805, 0.024839267134666443, -0.007901930250227451, 0.02635510452091694, 0.004164495971053839, -0.032502759248018265, -0...
0.832264
0.773029
0.059235
Please explain the reasoning behind the following solution and provide code in Kotlin: You are given two **non-increasing 0-indexed** integer arrays `nums1`​​​​​​ and `nums2`​​​​​​. A pair of indices `(i, j)`, where `0 <= i < nums1.length` and `0 <= j < nums2.length`, is **valid** if both `i <= j` and `nums1[i] <= num...
dolphin
[ 0.014349059201776981, 0.025182059034705162, -0.016496308147907257, -0.030056919902563095, 0.037896234542131424, -0.016937194392085075, -0.032176434993743896, 0.06207902729511261, 0.03530929982662201, -0.025880858302116394, 0.021665874868631363, 0.024533534422516823, -0.027905698865652084, ...
0.85041
0.791619
0.058791
Please explain the following problem in detail and provide code in python: Given an integer array `nums`, find a subarray that has the largest product, and return _the product_. The test cases are generated so that the answer will fit in a **32-bit** integer. **Example 1:** **Input:** nums = \[2,3,-2,4\] **Output:**...
dolphin
[ 0.03972690925002098, 0.044761575758457184, -0.032630905508995056, -0.011839421465992928, 0.0425291508436203, -0.016855912283062935, -0.03633042424917221, 0.05577513948082924, 0.031066719442605972, -0.01610906980931759, 0.029973596334457397, 0.04182199016213417, -0.03047001361846924, -0.024...
0.841863
0.787849
0.054015
Please explain the reasoning behind the following solution and provide code in python: 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 ...
dolphin
[ 0.05277547985315323, 0.05615010857582092, -0.008893195539712906, -0.02364768274128437, 0.0323830284178257, -0.01880192570388317, -0.02817338891327381, 0.046330392360687256, 0.03827700763940811, -0.0014044996351003647, 0.015131736174225807, 0.04296419769525528, -0.054339610040187836, -0.023...
0.82984
0.775715
0.054125
Please focus on the functionality of this problem and provide code in Swift: 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 **suba...
dolphin
[ 0.01521072257310152, 0.02361134998500347, -0.044092852622270584, -0.017848802730441093, 0.04310810938477516, -0.013958893716335297, -0.04165098816156387, 0.043290309607982635, 0.030583668500185013, -0.005541528109461069, 0.021500058472156525, 0.013988612219691277, -0.020393764600157738, 0....
0.83857
0.781954
0.056617
Please write the following solution using c++: Given an array of points on the **X-Y** plane `points` where `points[i] = [xi, yi]`, return _the area of the largest triangle that can be formed by any three different points_. Answers within `10-5` of the actual answer will be accepted. **Example 1:** **Input:** points ...
dolphin
[ 0.026755748316645622, 0.029716266319155693, -0.032329339534044266, -0.03801491856575012, 0.028480930253863335, -0.01227283664047718, -0.02760797180235386, 0.0794726088643074, 0.05442110821604729, -0.006443334743380547, 0.03553119674324989, 0.04968293756246567, -0.02103123627603054, -0.0330...
0.82041
0.765733
0.054678
Please write the following solution using Objective-C: 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-ind...
dolphin
[ 0.00877210684120655, 0.04268521070480347, -0.018912388011813164, -0.019765378907322884, 0.029735898599028587, -0.02576880156993866, -0.03415367007255554, 0.07484161108732224, 0.03040274605154991, -0.036620814353227615, 0.017995145171880722, 0.01284552551805973, -0.04852975532412529, -0.015...
0.85171
0.795746
0.055964
Please focus on the functionality of this problem and provide code in Scala: 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` d...
dolphin
[ 0.01583440974354744, 0.0270395465195179, -0.035642173141241074, -0.01741529442369938, 0.039864346385002136, -0.017880670726299286, -0.041894394904375076, 0.032156988978385925, 0.021952999755740166, -0.0069981166161596775, 0.02256143093109131, 0.02502516843378544, -0.01361940149217844, -0.0...
0.843064
0.786588
0.056475
Please write the following solution using Visual Basic .NET: You are given a positive integer array `nums`. * The **element sum** is the sum of all the elements in `nums`. * The **digit sum** is the sum of all the digits (not necessarily distinct) that appear in `nums`. Return _the **absolute** difference between...
dolphin
[ 0.011685648001730442, 0.018352419137954712, -0.03473825007677078, -0.03273753076791763, 0.04171920567750931, -0.039336834102869034, -0.02629285678267479, 0.06746204197406769, 0.05283242091536522, -0.013676255941390991, 0.02466343715786934, 0.026139970868825912, -0.052076756954193115, -0.01...
0.829714
0.771295
0.058419
Please write the following solution using R: Given an array `nums`. We define a running sum of an array as `runningSum[i] = sum(nums[0]...nums[i])`. Return the running sum of `nums`. **Example 1:** **Input:** nums = \[1,2,3,4\] **Output:** \[1,3,6,10\] **Explanation:** Running sum is obtained as follows: \[1, 1+2, 1...
dolphin
[ 0.013853546231985092, 0.046810973435640335, -0.02452637068927288, -0.022952795028686523, 0.04571690782904625, -0.01092244777828455, -0.044368546456098557, 0.04038339480757713, 0.039176203310489655, -0.008697004988789558, 0.0161887239664793, 0.025730924680829048, -0.04628387466073036, -0.01...
0.816532
0.753759
0.062773
Please write the following solution using Scala: Given an integer array `nums` of length `n`, return `true` if there is a triplet `(i, j, k)` which satisfies the following conditions: * `0 < i, i + 1 < j, j + 1 < k < n - 1` * The sum of subarrays `(0, i - 1)`, `(i + 1, j - 1)`, `(j + 1, k - 1)` and `(k + 1, n - 1)...
dolphin
[ 0.012160795740783215, 0.023128291592001915, -0.026065630838274956, -0.030588138848543167, 0.057625267654657364, -0.022747211158275604, -0.005200130864977837, 0.061541598290205, 0.007866865955293179, -0.012812070548534393, 0.0163310207426548, 0.027355125173926353, -0.024784883484244347, -0....
0.848824
0.791956
0.056868
Please write the following solution using java: Given an array `nums` containing `n` distinct numbers in the range `[0, n]`, return _the only number in the range that is missing from the array._ **Example 1:** **Input:** nums = \[3,0,1\] **Output:** 2 **Explanation:** n = 3 since there are 3 numbers, so all numbers a...
dolphin
[ 0.015869496390223503, 0.03465183451771736, -0.02879762090742588, -0.021102244034409523, 0.045106466859579086, -0.025893397629261017, -0.03279190883040428, 0.04067564383149147, 0.0254462081938982, -0.01723789982497692, 0.01821388304233551, 0.011053928174078465, -0.02246394008398056, -0.0103...
0.839955
0.780376
0.059579
Please explain the reasoning behind the following solution and provide code in java: You are given an `m x n` binary matrix `grid`. A **move** consists of choosing any row or column and toggling each value in that row or column (i.e., changing all `0`'s to `1`'s, and all `1`'s to `0`'s). Every row of the matrix is in...
dolphin
[ 0.0025696828961372375, 0.02148883417248726, -0.025099068880081177, -0.04479166120290756, 0.050769880414009094, -0.05514821782708168, -0.03575866296887398, 0.04236933961510658, 0.02953651174902916, -0.006703842431306839, 0.02374829724431038, 0.0173669271171093, -0.045811112970113754, -0.011...
0.835667
0.782316
0.053351
Please write the following solution using java: You are given a positive integer `n`, indicating that we initially have an `n x n` **0-indexed** integer matrix `mat` filled with zeroes. You are also given a 2D integer array `query`. For each `query[i] = [row1i, col1i, row2i, col2i]`, you should do the following operat...
dolphin
[ 0.021354326978325844, 0.03288041800260544, -0.0313703827559948, -0.029671374708414078, 0.030350858345627785, -0.016618434339761734, -0.016972234472632408, 0.05249037593603134, 0.02150111272931099, -0.011301087215542793, 0.02678823471069336, 0.017130929976701736, -0.04202433302998543, -0.01...
0.84328
0.786813
0.056466
Please write the following solution using javascript: You are given `nums`, an array of positive integers of size `2 * n`. You must perform `n` operations on this array. In the `ith` operation **(1-indexed)**, you will: * Choose two elements, `x` and `y`. * Receive a score of `i * gcd(x, y)`. * Remove `x` and `...
dolphin
[ 0.02076544240117073, 0.03652049973607063, -0.03258570283651352, -0.02955322153866291, 0.03327067941427231, -0.025606146082282066, -0.029293835163116455, 0.05214414745569229, 0.040968481451272964, -0.005486301612108946, 0.013539174571633339, 0.012901601381599903, -0.024461744353175163, -0.0...
0.851181
0.789661
0.06152
Please explain the following problem in detail and provide code in ANSI C: Given two integers `left` and `right` that represent the range `[left, right]`, return _the bitwise AND of all numbers in this range, inclusive_. **Example 1:** **Input:** left = 5, right = 7 **Output:** 4 **Example 2:** **Input:** left = 0,...
dolphin
[ 0.03028295189142227, 0.033772606402635574, -0.02137172222137451, -0.035382550209760666, 0.019258707761764526, -0.014959448017179966, -0.025521760806441307, 0.07349740713834763, 0.03991854190826416, -0.02668899856507778, 0.034015901386737823, 0.05170691758394241, -0.032528992742300034, -0.0...
0.831989
0.771075
0.060913
Please write the following solution using Clojure: Given an integer array `nums` of **unique** elements, 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,3\] **Output:** \[\[\],\[1\...
dolphin
[ 0.03949754685163498, 0.034304987639188766, -0.010836607776582241, -0.02350287139415741, 0.045751478523015976, -0.04199030250310898, -0.007162641733884811, 0.04217587038874626, 0.057927925139665604, -0.020849188789725304, 0.03639211133122444, 0.02488737553358078, -0.0400518923997879, -0.040...
0.832669
0.77851
0.054158
Please write the following solution using Scheme: 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.01807144097983837, 0.01584443636238575, -0.05027344077825546, -0.015631113201379776, 0.0391215980052948, -0.02134445309638977, -0.03629649803042412, 0.02904573082923889, 0.03408421203494072, -0.005719075910747051, 0.03878979757428169, 0.02877930924296379, -0.033528510481119156, 0.0113416...
0.831773
0.764405
0.067369
Please explain the reasoning behind the following solution and provide code in Kotlin: Suppose you have `n` integers labeled `1` through `n`. A permutation of those `n` integers `perm` (**1-indexed**) is considered a **beautiful arrangement** if for every `i` (`1 <= i <= n`), **either** of the following is true: * `...
dolphin
[ 0.03049079142510891, 0.03526716306805611, -0.015570363029837608, -0.041337065398693085, 0.039810266345739365, -0.02953917719423771, -0.03623337298631668, 0.06110458821058273, 0.029155317693948746, -0.01042100228369236, 0.03289064019918442, 0.01803562045097351, -0.02283436246216297, -0.0008...
0.844898
0.788047
0.056851
Please write the following solution using Elixir: 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_. **Example 1:** **Input:** n = 5,...
dolphin
[ 0.035217877477407455, 0.027477890253067017, -0.03229456767439842, -0.02973584458231926, 0.01739826239645481, -0.023920323699712753, -0.01864743046462536, 0.03599005565047264, 0.031387895345687866, 0.008644630201160908, 0.023128710687160492, 0.021314525976777077, -0.0241712536662817, -0.038...
0.834397
0.767575
0.066822
Please explain the following problem in detail and provide code in Scheme: 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_. **Exampl...
dolphin
[ 0.03519463166594505, 0.025469737127423286, -0.033575255423784256, -0.021213943138718605, 0.021262697875499725, -0.022999467328190804, -0.017069248482584953, 0.039079226553440094, 0.032098088413476944, 0.0071593536995351315, 0.02400103211402893, 0.015838006511330605, -0.024586210027337074, ...
0.835592
0.765708
0.069884
Please focus on the algorithm of this problem and provide code in python: Given an integer array `nums`, return _the largest perimeter of a triangle with a non-zero area, formed from three of these lengths_. If it is impossible to form any triangle of a non-zero area, return `0`. **Example 1:** **Input:** nums = \[2,...
dolphin
[ 0.01909560337662697, 0.03957940638065338, -0.02691110596060753, -0.019002992659807205, 0.027284160256385803, -0.011486424133181572, -0.02584158629179001, 0.06135096400976181, 0.016207126900553703, -0.0040037669241428375, 0.03566889837384224, 0.05481314659118652, -0.022809024900197983, -0.0...
0.837235
0.781991
0.055244
Please explain the following problem in detail and provide code in Julia: Given an integer array `nums` of length `n`, return `true` if there is a triplet `(i, j, k)` which satisfies the following conditions: * `0 < i, i + 1 < j, j + 1 < k < n - 1` * The sum of subarrays `(0, i - 1)`, `(i + 1, j - 1)`, `(j + 1, k ...
dolphin
[ 0.0009427223121747375, 0.026263128966093063, -0.03869974985718727, -0.03129493072628975, 0.049659740179777145, -0.01723763719201088, -0.0093429209664464, 0.07059415429830551, 0.016317930072546005, -0.005679565016180277, 0.015815095975995064, 0.030872609466314316, -0.025185225531458855, -0....
0.854348
0.800607
0.053741
Please write the following solution using Objective-C: You are given two integer arrays `nums1` and `nums2` of lengths `m` and `n` respectively. `nums1` and `nums2` represent the digits of two numbers. You are also given an integer `k`. Create the maximum number of length `k <= m + n` from digits of the two numbers. T...
dolphin
[ 0.028931880369782448, 0.030150393024086952, -0.03060532920062542, -0.051501452922821045, 0.04109270125627518, -0.026025686413049698, -0.03438994288444519, 0.05294802784919739, 0.028586404398083687, -0.023717259988188744, 0.026745222508907318, 0.02665102481842041, -0.04032258316874504, 0.00...
0.835022
0.772283
0.062739
Please focus on the efficiency of this problem and provide code in java: Given an array `nums` of integers and integer `k`, return the maximum `sum` such that there exists `i < j` with `nums[i] + nums[j] = sum` and `sum < k`. If no `i`, `j` exist satisfying this equation, return `-1`. **Example 1:** **Input:** nums =...
dolphin
[ 0.0069680227898061275, 0.02990935929119587, -0.04117543622851372, -0.027585485950112343, 0.04508015885949135, -0.005830811802297831, -0.027524320408701897, 0.048909734934568405, 0.023869715631008148, -0.0162516962736845, 0.03814433515071869, 0.03462976589798927, -0.030698182061314583, 0.00...
0.842115
0.777106
0.065009
Please explain the following problem in detail and provide code in Fortran: You are given a **0-indexed** integer array `nums`. You can apply the following operation any number of times: * Pick any element from `nums` and put it at the end of `nums`. The prefix sum array of `nums` is an array `prefix` of the same l...
dolphin
[ 0.008789261803030968, 0.021405871957540512, -0.013237305916845798, -0.0267465952783823, 0.029588153585791588, -0.02130361646413803, -0.010691816918551922, 0.061348967254161835, 0.03790941834449768, -0.0020349808037281036, 0.006573162507265806, 0.03489464893937111, -0.02256157249212265, -0....
0.846711
0.786098
0.060613
Please explain the reasoning behind the following solution and provide code in C#: 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 subarra...
dolphin
[ 0.023581670597195625, 0.02300865761935711, -0.02102687582373619, -0.02837882563471794, 0.03157538175582886, -0.032382749021053314, -0.04395701363682747, 0.08416122943162918, 0.048372216522693634, -0.01604810729622841, 0.021805085241794586, 0.029105784371495247, -0.03876397758722305, -0.002...
0.840394
0.782635
0.057759
Please explain the following problem in detail and provide code in c++: 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 elem...
dolphin
[ 0.02989315055310726, 0.035128090530633926, -0.016470765694975853, -0.021398060023784637, 0.031631022691726685, -0.009451951831579208, -0.021135231480002403, 0.0894833505153656, 0.03264612704515457, -0.01341159176081419, 0.026224644854664803, 0.0323605015873909, -0.030210092663764954, -0.00...
0.837966
0.77589
0.062076
translate this code from C# to Perl: ```csharp public int NumOfWays(int[] nums) { int n = nums.Length; int mod = 1000000007; long[,] dp = new long[n + 1, n + 1]; for (int i = 1; i <= n; i++) { dp[i, i] = 1; } for (int len = 2; len <= n; len++) { for (int i = 1; i <= n - len + 1; ...
dolphin
[ 0.018173502758145332, 0.012594420462846756, -0.011592309921979904, -0.041351381689310074, 0.028328200802206993, 0.004685527645051479, -0.016852959990501404, 0.06498342752456665, 0.03604396805167198, -0.0070311822928488255, 0.02000894583761692, 0.03922678902745247, -0.032478854060173035, -0...
0.844464
0.790923
0.053541
Please explain the reasoning behind the following solution and provide code in Dart: 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 **O...
dolphin
[ 0.0026084566488862038, 0.032308634370565414, -0.0277201347053051, -0.0234601441770792, 0.043015576899051666, -0.012299418449401855, -0.037120938301086426, 0.04818778112530708, 0.0379435271024704, -0.0023662294261157513, 0.030230097472667694, 0.008820866234600544, -0.032985344529151917, -0....
0.841285
0.787366
0.053919
Please write the following solution using Groovy: Given an integer array `nums` and an integer `k`, you are asked to construct the array `ans` of size `n-k+1` where `ans[i]` is the number of **distinct** numbers in the subarray `nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]]`. Return _the array_ `ans`. **Exam...
dolphin
[ 0.022971568629145622, 0.034841861575841904, -0.027939490973949432, -0.021796803921461105, 0.048819977790117264, -0.03302546590566635, -0.02285320684313774, 0.04180525988340378, 0.04192114248871803, -0.005987587850540876, 0.03232105076313019, 0.0221547894179821, -0.03025306947529316, 0.0112...
0.841917
0.786081
0.055836
Please explain the following problem in detail and provide code in Swift: 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**_. *...
dolphin
[ 0.033017463982105255, 0.025336038321256638, -0.024767503142356873, -0.03559720516204834, 0.019835270941257477, -0.031808920204639435, -0.03518759831786156, 0.0601191408932209, 0.03282473608851433, 0.002016160637140274, 0.03477857634425163, 0.03391217812895775, -0.05579407140612602, 0.00631...
0.837552
0.780882
0.056671
Please explain the following problem in detail and provide code in Object Pascal: Given an integer array `nums` and an integer `k`, return _the_ `k` _most frequent elements_. You may return the answer in **any order**. **Example 1:** **Input:** nums = \[1,1,1,2,2,3\], k = 2 **Output:** \[1,2\] **Example 2:** **Inpu...
dolphin
[ 0.02060656063258648, 0.045309875160455704, -0.020330552011728287, -0.01797247678041458, 0.04488223418593407, -0.02592703141272068, -0.012694336473941803, 0.05290393903851509, 0.03091258555650711, 0.0037718394305557013, 0.03443179652094841, 0.013534879311919212, -0.009977998211979866, 0.002...
0.836528
0.777896
0.058632
Please explain the following problem in detail and provide code in Scheme: Given an integer `n`, count _the total number of digit_ `1` _appearing in all non-negative integers less than or equal to_ `n`. **Example 1:** **Input:** n = 13 **Output:** 6 **Example 2:** **Input:** n = 0 **Output:** 0 **Constraints:** *...
dolphin
[ 0.0165939312428236, 0.022656921297311783, -0.02623881958425045, -0.03860125690698624, 0.038590967655181885, -0.027260323986411095, -0.03151696175336838, 0.04163080453872681, 0.022326646372675896, 0.011678742244839668, 0.029929915443062782, 0.03199345991015434, -0.035506051033735275, -0.014...
0.829891
0.771701
0.058191
Please explain the reasoning behind the following solution and provide code in Mojo: An array is **squareful** if the sum of every pair of adjacent elements is a **perfect square**. Given an integer array nums, return _the number of permutations of_ `nums` _that are **squareful**_. Two permutations `perm1` and `perm2...
dolphin
[ 0.011416280642151833, 0.04380450397729874, -0.02368040196597576, -0.032015569508075714, 0.04687810689210892, -0.028708551079034805, -0.029291443526744843, 0.06719893217086792, 0.02963011898100376, -0.014205129817128181, 0.019969867542386055, 0.005862480960786343, -0.04137720540165901, -0.0...
0.841528
0.785881
0.055647
Please focus on the functionality of this problem and provide code in C#: 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 in...
dolphin
[ 0.023880891501903534, 0.047766830772161484, -0.023801131173968315, -0.032970279455184937, 0.03026551939547062, -0.04253083094954491, -0.04525205120444298, 0.08247782289981842, 0.04358431324362755, -0.024644197896122932, 0.027661465108394623, 0.023575935512781143, -0.034132134169340134, -0....
0.844657
0.786301
0.058356
Please write the following solution using C#: Given a positive integer `n`, you can apply one of the following operations: 1. If `n` is even, replace `n` with `n / 2`. 2. If `n` is odd, replace `n` with either `n + 1` or `n - 1`. Return _the minimum number of operations needed for_ `n` _to become_ `1`. **Example 1...
dolphin
[ 0.023594867438077927, 0.02954760380089283, -0.017327435314655304, -0.04270559549331665, 0.021379586309194565, -0.024207422509789467, -0.03870445117354393, 0.0747428834438324, 0.027107294648885727, -0.011589476838707924, 0.015268100425601006, 0.012818894349038601, -0.0247940793633461, -0.03...
0.838679
0.783116
0.055563
Please explain the following problem in detail and provide code in Swift: The [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) between two integers is the number of positions at which the corresponding bits are different. Given an integer array `nums`, return _the sum of **Hamming distances** between...
dolphin
[ 0.010402025654911995, 0.01890694536268711, -0.019562887027859688, -0.016606973484158516, 0.05846027284860611, -0.027490131556987762, -0.04287544637918472, 0.03407542407512665, 0.04166461527347565, -0.014772781170904636, 0.028369273990392685, 0.019338810816407204, -0.02569466643035412, -0.0...
0.827593
0.773954
0.053639
Please explain the following problem in detail and provide code in Scheme: 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...
dolphin
[ 0.008272855542600155, 0.018849436193704605, -0.030023837462067604, -0.020389536395668983, 0.03937452286481857, -0.020580949261784554, -0.041581444442272186, 0.046965524554252625, 0.008881008252501488, -0.0007238654070533812, 0.030318934470415115, 0.03356335312128067, -0.04790927469730377, ...
0.843505
0.784686
0.058819
Please write the following solution using ANSI C: You are given a **positive** integer `n`. Let `even` denote the number of even indices in the binary representation of `n` (**0-indexed**) with value `1`. Let `odd` denote the number of odd indices in the binary representation of `n` (**0-indexed**) with value `1`. R...
dolphin
[ 0.02503351680934429, 0.028524668887257576, -0.021584561094641685, -0.03526544198393822, 0.02094894088804722, -0.040715888142585754, -0.04210929200053215, 0.06641864031553268, 0.04405609518289566, -0.01609518565237522, 0.030304960906505585, 0.030261920765042305, -0.046864449977874756, -0.03...
0.828296
0.764277
0.064019
Please write the following solution using Swift: You are standing at position `0` on an infinite number line. There is a destination at position `target`. You can make some number of moves `numMoves` so that: * On each move, you can either go left or right. * During the `ith` move (starting from `i == 1` to `i ==...
dolphin
[ 0.005823143292218447, 0.02364276722073555, -0.01800285093486309, -0.03709660470485687, 0.04144289717078209, -0.002946083899587393, -0.0457080714404583, 0.04477985203266144, 0.030175821855664253, -0.027318637818098068, 0.03912989795207977, 0.01866815984249115, -0.020110486075282097, -0.0288...
0.842936
0.787567
0.055369
Please write the following solution using javascript: You are given a binary array `nums` containing only the integers `0` and `1`. Return _the number of **subarrays** in nums that have **more**_ `1`'_s than_ `0`_'s. Since the answer may be very large, return it **modulo**_ `109 + 7`. A **subarray** is a contiguous se...
dolphin
[ 0.016627296805381775, 0.03089562989771366, -0.03128105401992798, -0.012567696161568165, 0.04779454693198204, -0.02030738815665245, -0.03939005360007286, 0.04716173931956291, 0.03167063742876053, -0.007623175159096718, 0.02275436371564865, 0.01683875545859337, -0.03951317444443703, -0.02896...
0.843421
0.783991
0.05943
Please write the following solution using Kotlin: A die simulator generates a random number from `1` to `6` for each roll. You introduced a constraint to the generator such that it cannot roll the number `i` more than `rollMax[i]` (**1-indexed**) consecutive times. Given an array of integers `rollMax` and an integer `...
dolphin
[ 0.033627696335315704, 0.019375769421458244, -0.011353150941431522, -0.027461906895041466, 0.041667308658361435, -0.017614109441637993, -0.03679167106747627, 0.06488215178251266, 0.026680348441004753, -0.01948484778404236, 0.03883165866136551, 0.02637256681919098, -0.01612667925655842, 0.00...
0.841072
0.781944
0.059128
Please write the following solution using Objective-C: Given an array of **distinct** integers `nums` and a target integer `target`, return _the number of possible combinations that add up to_ `target`. The test cases are generated so that the answer can fit in a **32-bit** integer. **Example 1:** **Input:** nums = ...
dolphin
[ 0.025726286694407463, 0.023146014660596848, -0.020191112533211708, -0.007865224964916706, 0.05099610611796379, -0.020608307793736458, -0.029296759516000748, 0.0590052492916584, 0.03500847890973091, -0.0035553770139813423, 0.024636857211589813, 0.030662408098578453, -0.03703821823000908, -0...
0.83557
0.777732
0.057838