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 Visual Basic .NET: You are given a **0-indexed** integer array `tasks`, where `tasks[i]` represents the difficulty level of a task. In each round, you can complete either 2 or 3 tasks of the **same difficulty level**. Return _the **minimum** rounds req...
dolphin
[ 0.0141339972615242, 0.03846393898129463, -0.024033106863498688, -0.026110077276825905, 0.050254035741090775, -0.018049685284495354, -0.015176821500062943, 0.07098031044006348, 0.03221036493778229, -0.0005036134971305728, 0.013026709668338299, 0.020290035754442215, -0.03221110627055168, -0....
0.846332
0.792275
0.054058
Please write the following solution using javascript: 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:** Each of the 1s a...
dolphin
[ 0.012226606719195843, 0.03651774302124977, -0.019620075821876526, -0.033220261335372925, 0.04367244988679886, -0.025824474170804024, -0.0081718685105443, 0.06544050574302673, 0.028054937720298767, -0.013001997023820877, 0.020292535424232483, 0.011688824743032455, -0.021494539454579353, -0....
0.840835
0.781833
0.059002
Please explain the reasoning behind the following solution and provide code in Kotlin: A **square triple** `(a,b,c)` is a triple where `a`, `b`, and `c` are **integers** and `a2 + b2 = c2`. Given an integer `n`, return _the number of **square triples** such that_ `1 <= a, b, c <= n`. **Example 1:** **Input:** n = 5 ...
dolphin
[ 0.014713731594383717, 0.032478462904691696, -0.023892853409051895, -0.042694706469774246, 0.039641257375478745, -0.015000608749687672, -0.022121252492070198, 0.055257294327020645, 0.009938111528754234, 0.003541384357959032, 0.012724732980132103, 0.034557729959487915, -0.05317411199212074, ...
0.836746
0.78346
0.053285
Please write the following solution using Go: You are given a **0-indexed**, **strictly increasing** integer array `nums` and a positive integer `diff`. A triplet `(i, j, k)` is an **arithmetic triplet** if the following conditions are met: * `i < j < k`, * `nums[j] - nums[i] == diff`, and * `nums[k] - nums[j] =...
dolphin
[ 0.019473744556307793, 0.02319967746734619, -0.013579289428889751, -0.035255905240774155, 0.047366298735141754, -0.019082721322774887, -0.03245865926146507, 0.06580069661140442, 0.04606827720999718, -0.009000682272017002, 0.017310170456767082, -0.00006032506644260138, -0.04450449347496033, ...
0.841755
0.78839
0.053366
Please explain the reasoning behind the following solution and provide code in c++: Given an integer array `arr`, return _the length of a maximum size turbulent subarray of_ `arr`. A subarray is **turbulent** if the comparison sign flips between each adjacent pair of elements in the subarray. More formally, a subarra...
dolphin
[ 0.01461756695061922, 0.029091065749526024, -0.02657281793653965, -0.02348599024116993, 0.0333077646791935, -0.010643446817994118, -0.054632820188999176, 0.08831091225147247, 0.02823525294661522, -0.009700561873614788, 0.024356435984373093, 0.023004615679383278, -0.024389417842030525, -0.00...
0.840712
0.780567
0.060145
Please write the following solution using javascript: A **square triple** `(a,b,c)` is a triple where `a`, `b`, and `c` are **integers** and `a2 + b2 = c2`. Given an integer `n`, return _the number of **square triples** such that_ `1 <= a, b, c <= n`. **Example 1:** **Input:** n = 5 **Output:** 2 **Explanation**: Th...
dolphin
[ 0.022253310307860374, 0.03187822550535202, -0.04030657932162285, -0.037084270268678665, 0.03849624842405319, -0.006076009012758732, -0.017443332821130753, 0.05080697685480118, 0.01610010489821434, 0.0073851170018315315, 0.023069163784384727, 0.02707057073712349, -0.06231033802032471, -0.03...
0.831264
0.776211
0.055053
Please write the following solution using Object Pascal: Given an integer array `nums`, _find three numbers whose product is maximum and return the maximum product_. **Example 1:** **Input:** nums = \[1,2,3\] **Output:** 6 **Example 2:** **Input:** nums = \[1,2,3,4\] **Output:** 24 **Example 3:** **Input:** nums ...
dolphin
[ 0.03592672571539879, 0.026680922135710716, -0.027366630733013153, -0.015604903921484947, 0.050995778292417526, -0.011672358959913254, -0.02947952039539814, 0.046341490000486374, 0.029107391834259033, -0.0029298686422407627, 0.024584315717220306, 0.04472724348306656, -0.043018847703933716, ...
0.824429
0.770521
0.053908
Please write the following solution using Rust: You are given an integer array `arr`. You can choose a set of integers and remove all the occurrences of these integers in the array. Return _the minimum size of the set so that **at least** half of the integers of the array are removed_. **Example 1:** **Input:** arr ...
dolphin
[ 0.029145048931241035, 0.03585455194115639, -0.023662874475121498, -0.037072405219078064, 0.03634003549814224, -0.039314690977334976, -0.03592134639620781, 0.06343571841716766, 0.057547371834516525, -0.026196831837296486, 0.013598296791315079, 0.008834403939545155, -0.0250810869038105, -0.0...
0.841168
0.786004
0.055164
Please write the following solution using Groovy: The **pair sum** of a pair `(a,b)` is equal to `a + b`. The **maximum pair sum** is the largest **pair sum** in a list of pairs. * For example, if we have pairs `(1,5)`, `(2,3)`, and `(4,4)`, the **maximum pair sum** would be `max(1+5, 2+3, 4+4) = max(6, 5, 8) = 8`. ...
dolphin
[ 0.01842534728348255, 0.01856027916073799, -0.04150925204157829, -0.03574429452419281, 0.040132615715265274, -0.008085958659648895, -0.018645046278834343, 0.020145250484347343, 0.03120328299701214, -0.020241079851984978, 0.018057353794574738, 0.04372171685099602, -0.02461734041571617, -0.00...
0.83559
0.781117
0.054473
Please write the following solution using Swift: You are given an `m x n` matrix `M` initialized with all `0`'s and an array of operations `ops`, where `ops[i] = [ai, bi]` means `M[x][y]` should be incremented by one for all `0 <= x < ai` and `0 <= y < bi`. Count and return _the number of maximum integers in the matri...
dolphin
[ 0.03826785087585449, 0.01879110187292099, -0.033001698553562164, -0.03672342002391815, 0.047363921999931335, -0.025013228878378868, -0.05340469628572464, 0.05693292245268822, 0.03668032959103584, -0.013194038532674313, 0.011963433586061, 0.021822722628712654, -0.036187030375003815, -0.0291...
0.848536
0.786899
0.061637
Please explain the following problem in detail and provide code in Elixir: You are given an array `nums` consisting of **positive** integers. We call a subarray of `nums` **nice** if the bitwise **AND** of every pair of elements that are in **different** positions in the subarray is equal to `0`. Return _the length o...
dolphin
[ 0.0072547672316432, 0.017494002357125282, -0.03051389940083027, -0.02603290043771267, 0.03014824166893959, -0.03421085327863693, -0.038390856236219406, 0.03400464728474617, 0.03140123561024666, -0.006345051806420088, 0.043371766805648804, 0.024263417348265648, -0.02888433262705803, -0.0202...
0.850007
0.795417
0.05459
Please write the following solution using Objective-C: There is an **undirected** graph with `n` nodes, numbered from `0` to `n - 1`. You are given a **0-indexed** integer array `scores` of length `n` where `scores[i]` denotes the score of node `i`. You are also given a 2D integer array `edges` where `edges[i] = [ai, ...
dolphin
[ 0.001854690839536488, 0.023811502382159233, -0.02050488442182541, -0.026150742545723915, 0.03101782128214836, -0.03529098629951477, -0.031226344406604767, 0.06355439871549606, 0.02107144147157669, -0.005959232337772846, 0.028580468147993088, 0.012236280366778374, -0.020752491429448128, -0....
0.845781
0.78702
0.058761
Please focus on the efficiency of this problem and provide code in Objective-C: You are given an integer array `nums` and an integer `k`. Find the **largest even sum** of any subsequence of `nums` that has a length of `k`. Return _this sum, or_ `-1` _if such a sum does not exist_. A **subsequence** is an array that c...
dolphin
[ 0.02382575161755085, 0.03385892137885094, -0.029050610959529877, -0.0412842258810997, 0.025943215936422348, -0.015974871814250946, -0.02946147322654724, 0.06953898072242737, 0.03154319152235985, -0.022305015474557877, 0.030718212947249413, 0.026454830542206764, -0.03872744366526604, 0.0017...
0.835662
0.779069
0.056593
Please write the following solution using Fortran: 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,2,3,4,5,6,7,8,9\] **Ex...
dolphin
[ 0.04397841542959213, 0.03716519847512245, -0.020618852227926254, -0.040428340435028076, 0.033078622072935104, -0.027445169165730476, -0.03438796475529671, 0.03640333190560341, 0.018376216292381287, -0.01399125624448061, 0.019453560933470726, 0.03975672647356987, -0.04337581619620323, -0.02...
0.837677
0.775854
0.061824
Please write the following solution using c++: Given an initial array `arr`, every day you produce a new array using the array of the previous day. On the `i`\-th day, you do the following operations on the array of day `i-1` to produce the array of day `i`: 1. If an element is smaller than both its left neighbor an...
dolphin
[ 0.01833932101726532, 0.033970411866903305, -0.021842701360583305, -0.031936921179294586, 0.020331094041466713, -0.028549063950777054, -0.026849500834941864, 0.11314254999160767, 0.0422392375767231, -0.03266084939241409, 0.025861041620373726, 0.012158368714153767, -0.02868138626217842, -0.0...
0.844925
0.787121
0.057803
Please write the following solution using Scala: You are given a **0-indexed** integer array `nums`, where `nums[i]` represents the score of the `ith` student. You are also given an integer `k`. Pick the scores of any `k` students from the array so that the **difference** between the **highest** and the **lowest** of ...
dolphin
[ 0.009860023856163025, 0.01760856620967388, -0.022958796471357346, -0.03035840578377247, 0.05294932797551155, -0.03433215990662575, -0.023600894957780838, 0.03872194141149521, 0.0349087119102478, -0.01117241382598877, 0.04647519066929817, 0.042557548731565475, -0.01544730644673109, 0.016563...
0.843131
0.789772
0.05336
Please write the following solution using Kotlin: You are given two **positive** integers `startPos` and `endPos`. Initially, you are standing at position `startPos` on an **infinite** number line. With one step, you can move either one position to the left, or one position to the right. Given a positive integer `k`, ...
dolphin
[ 0.01876922883093357, 0.028687097132205963, -0.012615321204066277, -0.04012881591916084, 0.03313734754920006, -0.005222613457590342, -0.022617680951952934, 0.059847887605428696, 0.03832162171602249, -0.029092758893966675, 0.03165818750858307, 0.035146042704582214, -0.012348027899861336, -0....
0.851866
0.78962
0.062246
Please write the following solution using Object Pascal: 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` different integers: `...
dolphin
[ 0.022507095709443092, 0.02946414053440094, -0.03236578777432442, -0.022169746458530426, 0.04575158655643463, -0.017090782523155212, -0.03435973450541496, 0.029836811125278473, 0.03827495127916336, 0.004270530305802822, 0.025225969031453133, 0.024518707767128944, -0.021143769845366478, -0.0...
0.841178
0.783546
0.057632
Please focus on the efficiency of this problem and provide code in Kotlin: Given an integer array `nums` and two integers `k` and `p`, return _the number of **distinct subarrays** which have **at most**_ `k` _elements divisible by_ `p`. Two arrays `nums1` and `nums2` are said to be **distinct** if: * They are of **...
dolphin
[ 0.019418196752667427, 0.025325242429971695, -0.028992392122745514, -0.015834249556064606, 0.03259868547320366, -0.02705731987953186, -0.027894483879208565, 0.05373236536979675, 0.03147108107805252, 0.0006662855157628655, 0.03154231980443001, 0.026698531582951546, -0.026325557380914688, 0.0...
0.842243
0.782194
0.06005
Please explain the reasoning behind the following solution and provide code in Objective-C: Return the number of permutations of 1 to `n` so that prime numbers are at prime indices (1-indexed.) _(Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two positive int...
dolphin
[ 0.03724749758839607, 0.030475173145532608, -0.006001616362482309, -0.03877100348472595, 0.03658990561962128, -0.04794459044933319, -0.022738071158528328, 0.05091620981693268, 0.019101450219750404, -0.02724423259496689, 0.040135543793439865, 0.023886531591415405, -0.03947586566209793, -0.01...
0.836226
0.78166
0.054567
Please focus on the functionality of this problem and provide code in Clojure: 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 ele...
dolphin
[ 0.009020164608955383, 0.03851013630628586, -0.023411884903907776, -0.023081224411725998, 0.02952301874756813, -0.017212795093655586, -0.023576071485877037, 0.022382279857993126, 0.03382646292448044, 0.00030686543323099613, 0.044332973659038544, 0.042561132460832596, -0.02491781674325466, -...
0.840289
0.782252
0.058038
Please explain the following problem in detail and provide code in C#: You are given two integers `n` and `maxValue`, which are used to describe an **ideal** array. A **0-indexed** integer array `arr` of length `n` is considered **ideal** if the following conditions hold: * Every `arr[i]` is a value from `1` to `ma...
dolphin
[ 0.0370665118098259, 0.023511864244937897, -0.03170875832438469, -0.023250732570886612, 0.03288564831018448, -0.04646351560950279, -0.048852697014808655, 0.07496717572212219, 0.030315428972244263, -0.018267840147018433, 0.03678625449538231, 0.025688113644719124, -0.052184347063302994, -0.03...
0.842832
0.775173
0.06766
Please write the following solution using Swift: 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 **Explanatio...
dolphin
[ 0.017372282221913338, 0.02994009666144848, -0.03501806780695915, -0.022403890267014503, 0.05240940675139427, -0.01612459309399128, -0.024018945172429085, 0.04873911663889885, 0.02999582700431347, 0.000034321787097724155, 0.03167679160833359, 0.025322139263153076, -0.03431792929768562, -0.0...
0.834889
0.768964
0.065925
Please focus on the algorithm of this problem and provide code in Elixir: Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`. A **circular array** means the end of the array connects to the beginning of the array. Formally, the next element ...
dolphin
[ 0.008858982473611832, 0.027283091098070145, -0.015445885248482227, -0.031262289732694626, 0.018524182960391045, -0.015577584505081177, -0.026729868724942207, 0.031325310468673706, 0.025019414722919464, -0.0009907599305734038, 0.046898648142814636, 0.03715076670050621, -0.02410011924803257, ...
0.84556
0.788413
0.057147
Please focus on the efficiency of this problem and provide code in Object Pascal: Given an array of positive integers `nums` and a positive integer `target`, return _the **minimal length** of a_ _subarray_ _whose sum is greater than or equal to_ `target`. If there is no such subarray, return `0` instead. **Example 1:*...
dolphin
[ 0.012157120741903782, 0.0229840986430645, -0.0299642663449049, -0.022559432312846184, 0.04135999456048012, -0.013457629829645157, -0.02310544066131115, 0.04458343982696533, 0.046844787895679474, -0.0018807178130373359, 0.02324466034770012, 0.026461226865649223, -0.030694035813212395, -0.01...
0.852772
0.793588
0.059184
Please explain the following problem in detail and provide code in c++: You are given an integer array `nums`. Splitting of an integer array `nums` into **subarrays** is **valid** if: * the _greatest common divisor_ of the first and last elements of each subarray is **greater** than `1`, and * each element of `nu...
dolphin
[ 0.02243172936141491, 0.030974334105849266, -0.02667865715920925, -0.01871485635638237, 0.038832247257232666, -0.00833064503967762, -0.039903175085783005, 0.09221190214157104, 0.027035316452383995, -0.01888333261013031, 0.023034116253256798, 0.02361140213906765, -0.015291293151676655, -0.00...
0.839487
0.777304
0.062183
Please write the following solution using Fortran: You are given an array of integers `arr` and an integer `target`. You have to find **two non-overlapping sub-arrays** of `arr` each with a sum equal `target`. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-array...
dolphin
[ 0.019379854202270508, 0.02497423253953457, -0.0337500162422657, -0.043019186705350876, 0.06379301100969315, -0.006526688113808632, -0.03155078738927841, 0.04198455810546875, 0.040947090834379196, -0.018701504915952682, 0.02123263105750084, 0.02593807503581047, -0.03184732422232628, -0.0220...
0.842537
0.789031
0.053506
Please explain the following problem in detail and provide code in R: An array `arr` a **mountain** if the following properties hold: * `arr.length >= 3` * There exists some `i` with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < arr[i]` * `arr[i] > arr[i + 1] > ... > arr[a...
dolphin
[ 0.03124711662530899, 0.03944230079650879, -0.03181000426411629, -0.04121432080864906, 0.024422846734523773, -0.031078914180397987, -0.05078849941492081, 0.08202460408210754, 0.02860814519226551, -0.01125055830925703, 0.012966952286660671, 0.0180785171687603, -0.04389866068959236, -0.023349...
0.839661
0.779602
0.060059
Please write the following solution using Lua: You are given an array `nums` consisting of positive integers. Starting with `score = 0`, apply the following algorithm: * Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index. * Add the value of the c...
dolphin
[ 0.018148936331272125, 0.042407527565956116, -0.02647472731769085, -0.042577069252729416, 0.045836664736270905, -0.004101251717656851, -0.022143539041280746, 0.05097965896129608, 0.028290744870901108, -0.012047281488776207, 0.028818609192967415, 0.028053993359208107, -0.023236751556396484, ...
0.853757
0.798687
0.055071
Please explain the following problem in detail and provide code in Scheme: Given an integer array `arr`, count how many elements `x` there are, such that `x + 1` is also in `arr`. If there are duplicates in `arr`, count them separately. **Example 1:** **Input:** arr = \[1,2,3\] **Output:** 2 **Explanation:** 1 and 2 ...
dolphin
[ 0.01582094095647335, 0.024949578568339348, -0.037640925496816635, -0.027022186666727066, 0.03977901488542557, -0.03274458274245262, -0.02742169238626957, 0.058161865919828415, 0.03265996649861336, -0.01708303764462471, 0.013235540129244328, -0.011027701199054718, -0.03606728836894035, -0.0...
0.825383
0.764131
0.061253
Please focus on the efficiency of this problem and provide code in javascript: Given an integer array `arr`, return _the number of distinct bitwise ORs of all the non-empty subarrays of_ `arr`. The bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise OR of a subarray of one integer i...
dolphin
[ 0.01741417869925499, 0.025919532403349876, -0.045475054532289505, 0.00019046130182687193, 0.026426993310451508, -0.03387274593114853, -0.039923861622810364, 0.04907282441854477, 0.05091436952352524, -0.014143484644591808, 0.022327711805701256, -0.004917964804917574, -0.03158425912261009, -...
0.84002
0.778197
0.061823
Please explain the reasoning behind the following solution and provide code in Visual Basic .NET: You are given an array `nums` consisting of positive integers. Starting with `score = 0`, apply the following algorithm: * Choose the smallest integer of the array that is not marked. If there is a tie, choose the one ...
dolphin
[ 0.022529292851686478, 0.03782268613576889, -0.02459690161049366, -0.028360972180962563, 0.04406627267599106, -0.019726643338799477, -0.016180654987692833, 0.07997395843267441, 0.039309389889240265, -0.005812314338982105, 0.0229016225785017, 0.023632265627384186, -0.030636513605713844, -0.0...
0.853135
0.797094
0.056041
Please explain the reasoning behind the following solution and provide code in Scheme: You are given a **0-indexed** integer array `nums`. * The **low** score of `nums` is the minimum value of `|nums[i] - nums[j]|` over all `0 <= i < j < nums.length`. * The **high** score of `nums` is the maximum value of `|nums[i...
dolphin
[ 0.010584207251667976, 0.022475741803646088, -0.023365002125501633, -0.01662125624716282, 0.05014271289110184, -0.03920702263712883, -0.043960090726614, 0.06036398559808731, 0.04415273666381836, -0.01210020948201418, 0.018538834527134895, 0.024635760113596916, -0.033548250794410706, -0.0043...
0.850065
0.790788
0.059277
Please focus on the functionality of this problem and provide code in c++: You are given a **0-indexed** positive integer array `nums` and a positive integer `k`. A pair of numbers `(num1, num2)` is called **excellent** if the following conditions are satisfied: * **Both** the numbers `num1` and `num2` exist in the...
dolphin
[ 0.013067624531686306, 0.01785467192530632, -0.03572729229927063, -0.0202469564974308, 0.036852169781923294, -0.01954253762960434, -0.04642801359295845, 0.08765222877264023, 0.04520260542631149, -0.01955471560359001, 0.02170572057366371, 0.03126467764377594, -0.028890006244182587, -0.010541...
0.849911
0.787751
0.062159
Please write the following solution using ANSI C: Given the `edges` of a directed graph where `edges[i] = [ai, bi]` indicates there is an edge between nodes `ai` and `bi`, and two nodes `source` and `destination` of this graph, determine whether or not all paths starting from `source` eventually, end at `destination`, ...
dolphin
[ 0.00908853393048048, 0.016990911215543747, -0.011927192099392414, -0.02462863363325596, 0.01969604566693306, -0.03397425636649132, -0.008229429833590984, 0.08228494971990585, 0.03047197125852108, -0.014702923595905304, 0.018898583948612213, 0.02126745693385601, -0.0073578632436692715, -0.0...
0.844251
0.788161
0.05609
Please explain the reasoning behind the following solution and provide code in Objective-C: Given an integer array `nums` and an integer `k`, return _the_ `kth` _largest element in the array_. Note that it is the `kth` largest element in the sorted order, not the `kth` distinct element. You must solve it in `O(n)` ti...
dolphin
[ 0.04653327912092209, 0.05378538370132446, -0.028890933841466904, -0.04627097770571709, 0.038355499505996704, -0.03304660692811012, -0.025456435978412628, 0.0629623681306839, 0.03022836707532406, -0.020171405747532845, 0.04044816642999649, 0.023883597925305367, -0.04934230446815491, 0.00595...
0.83237
0.776529
0.055841
Please explain the reasoning behind the following solution and provide code in ANSI C: There is an `m x n` matrix that is initialized to all `0`'s. There is also a 2D array `indices` where each `indices[i] = [ri, ci]` represents a **0-indexed location** to perform some increment operations on the matrix. For each loca...
dolphin
[ 0.017298022285103798, 0.027982497587800026, -0.02878793329000473, -0.03739180043339729, 0.032871097326278687, -0.02718837931752205, -0.03743381053209305, 0.10035787522792816, 0.050295598804950714, -0.03053506463766098, 0.011246059089899063, -0.0004105929401703179, -0.03841741755604744, -0....
0.841154
0.787209
0.053945
Please explain the following problem in detail and provide code in ANSI C: Given an `m x n` integers `matrix`, return _the length of the longest increasing path in_ `matrix`. From each cell, you can either move in four directions: left, right, up, or down. You **may not** move **diagonally** or move **outside the boun...
dolphin
[ 0.020810531452298164, 0.03103029355406761, -0.02624211087822914, -0.04224509000778198, 0.027494193986058235, -0.043486855924129486, -0.04564611613750458, 0.07100403308868408, 0.03891219198703766, -0.018652917817234993, 0.029931405559182167, 0.01530770305544138, -0.034228235483169556, -0.02...
0.834603
0.775534
0.05907
Please focus on the algorithm of this problem and provide code in Swift: Given a non-empty array of non-negative integers `nums`, the **degree** of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of `nums`, that has...
dolphin
[ -0.007317532319575548, 0.013657994568347931, -0.032017774879932404, -0.020615819841623306, 0.03429442644119263, -0.01815779134631157, -0.04414262995123863, 0.05339130386710167, 0.03454304859042168, -0.014462456107139587, 0.039859361946582794, 0.012491820380091667, -0.020267978310585022, 0....
0.838116
0.784209
0.053907
Please focus on the efficiency of this problem and provide code in c++: You are given an `m x n` matrix `M` initialized with all `0`'s and an array of operations `ops`, where `ops[i] = [ai, bi]` means `M[x][y]` should be incremented by one for all `0 <= x < ai` and `0 <= y < bi`. Count and return _the number of maximu...
dolphin
[ 0.03776722773909569, 0.015801716595888138, -0.03177432715892792, -0.031077435240149498, 0.033187005668878555, -0.009886280633509159, -0.05238346755504608, 0.09751617908477783, 0.03474344313144684, -0.010772328823804855, 0.011425720527768135, 0.030509907752275467, -0.030182374641299248, -0....
0.846337
0.781371
0.064966
Please focus on the functionality of this problem and provide code in Object Pascal: You are given an integer array `arr`. In one move, you can select a **palindromic** subarray `arr[i], arr[i + 1], ..., arr[j]` where `i <= j`, and remove that subarray from the given array. Note that after removing a subarray, the ele...
dolphin
[ 0.02082916907966137, 0.03127628192305565, -0.029795782640576363, -0.031092453747987747, 0.03898916020989418, -0.02074306644499302, -0.01772424764931202, 0.05474299192428589, 0.0499599426984787, -0.0005864282720722258, 0.027647020295262337, 0.014099108055233955, -0.0232385341078043, -0.0230...
0.844037
0.783244
0.060794
Please write the following solution using Erlang: You are given an integer array `nums` with the following properties: * `nums.length == 2 * n`. * `nums` contains `n + 1` **unique** elements. * Exactly one element of `nums` is repeated `n` times. Return _the element that is repeated_ `n` _times_. **Example 1:*...
dolphin
[ 0.025019902735948563, 0.028067195788025856, -0.017277346923947334, -0.037348710000514984, 0.030864259228110313, -0.020386870950460434, -0.023073965683579445, 0.07338160276412964, 0.02562825009226799, -0.0018106598872691393, 0.025085072964429855, 0.019469404593110085, -0.024190885946154594, ...
0.845669
0.787929
0.057741
Please focus on the functionality of this problem and provide code in Scheme: You are given three positive integers: `n`, `index`, and `maxSum`. You want to construct an array `nums` (**0-indexed**) that satisfies the following conditions: * `nums.length == n` * `nums[i]` is a **positive** integer where `0 <= i < ...
dolphin
[ 0.035362813621759415, 0.02805578149855137, -0.030537065118551254, -0.02708487957715988, 0.04199526831507683, -0.027444124221801758, -0.044024765491485596, 0.042732249945402145, 0.032694607973098755, -0.013964232057332993, 0.03738583251833916, 0.03801681846380234, -0.044970013201236725, -0....
0.843672
0.779083
0.06459
Please write the following solution using ANSI C: Write an algorithm to determine if a number `n` is happy. A **happy number** is a number defined by the following process: * Starting with any positive integer, replace the number by the sum of the squares of its digits. * Repeat the process until the number equal...
dolphin
[ 0.00955573283135891, 0.041395608335733414, -0.02434118650853634, -0.049919698387384415, 0.03408593311905861, -0.0304779764264822, -0.0054285842925310135, 0.07124842703342438, 0.012551817111670971, -0.01577877625823021, 0.024386145174503326, 0.017905347049236298, -0.030863715335726738, -0.0...
0.824915
0.771383
0.053531
Please write the following solution using Rust: You are given a **0-indexed** integer array `nums` consisting of `3 * n` elements. You are allowed to remove any **subsequence** of elements of size **exactly** `n` from `nums`. The remaining `2 * n` elements will be divided into two **equal** parts: * The first `n` e...
dolphin
[ 0.018936721608042717, 0.020749641582369804, -0.0255576241761446, -0.036112841218709946, 0.03733979910612106, -0.021083442494273186, -0.02411521226167679, 0.0727110356092453, 0.05351422354578972, -0.020510446280241013, 0.019663982093334198, 0.029837872833013535, -0.031145596876740456, -0.01...
0.848204
0.792488
0.055716
Please explain the following problem in detail and provide code in Julia: 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 label...
dolphin
[ 0.017020409926772118, 0.008771400898694992, -0.02122698538005352, -0.04523122310638428, 0.02850283682346344, -0.021056288853287697, -0.012446037493646145, 0.051235396414995193, 0.040282197296619415, -0.017727356404066086, 0.038383662700653076, 0.0504470095038414, -0.0178038589656353, -0.01...
0.847409
0.793392
0.054017
Please write the following solution using c++: Given an array of integers `nums`, return _the number of **good pairs**_. A pair `(i, j)` is called _good_ if `nums[i] == nums[j]` and `i` < `j`. **Example 1:** **Input:** nums = \[1,2,3,1,1,3\] **Output:** 4 **Explanation:** There are 4 good pairs (0,3), (0,4), (3,4), ...
dolphin
[ 0.020493173971772194, 0.006184485740959644, -0.03571454808115959, -0.02654378116130829, 0.041851747781038284, -0.005460287444293499, -0.036446359008550644, 0.0737723857164383, 0.03267509490251541, -0.02294270694255829, 0.011511270888149738, 0.026228103786706924, -0.02796885371208191, -0.02...
0.838753
0.769041
0.069711
Please explain the following problem in detail and provide code in R: You are given an integer array `nums`. In one move, you can pick an index `i` where `0 <= i < nums.length` and increment `nums[i]` by `1`. Return _the minimum number of moves to make every value in_ `nums` _**unique**_. The test cases are generated...
dolphin
[ 0.00490911677479744, 0.035448480397462845, -0.010221285745501518, -0.02310732752084732, 0.03813643008470535, -0.015856903046369553, -0.03392177075147629, 0.06831293553113937, 0.033021215349435806, -0.017987653613090515, 0.02704457938671112, 0.011742953211069107, -0.03030107356607914, -0.02...
0.845185
0.784485
0.0607
Please explain the following problem in detail and provide code in C#: A **subarray** of a **0-indexed** integer array is a contiguous **non-empty** sequence of elements within an array. The **alternating subarray sum** of a subarray that ranges from index `i` to `j` (**inclusive**, `0 <= i <= j < nums.length`) is `nu...
dolphin
[ 0.01620970293879509, 0.02674230933189392, -0.015802133828401566, -0.022611666470766068, 0.02436964213848114, -0.029583146795630455, -0.03721815347671509, 0.08425354957580566, 0.048035915940999985, -0.005887484643608332, 0.02832947112619877, 0.016460485756397247, -0.06060939282178879, -0.00...
0.827219
0.764342
0.062877
Please explain the following problem in detail and provide code in Object Pascal: 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 case...
dolphin
[ 0.032246869057416916, 0.024419570341706276, -0.03475886955857277, -0.015677668154239655, 0.0313236229121685, 0.0039780475199222565, -0.028254372999072075, 0.05577269196510315, 0.03821272775530815, -0.00409597298130393, 0.03517461568117142, 0.05121928080916405, -0.030121514573693275, -0.012...
0.845892
0.780326
0.065565
Please explain the following problem in detail and provide code in Kotlin: You are given two positive integer arrays `nums` and `target`, of the same length. In one operation, you can choose any two **distinct** indices `i` and `j` where `0 <= i, j < nums.length` and: * set `nums[i] = nums[i] + 2` and * set `nums...
dolphin
[ 0.012957879342138767, 0.027000872418284416, -0.0175491776317358, -0.02440105937421322, 0.046137820929288864, -0.017925061285495758, -0.02182907983660698, 0.07060261070728302, 0.026336921378970146, -0.020825842395424843, 0.011939581483602524, 0.012603622861206532, -0.0283124390989542, -0.00...
0.854684
0.796645
0.058039
Please explain the reasoning behind the following solution and provide code in Scala: Given a set of **distinct** positive integers `nums`, return the largest subset `answer` such that every pair `(answer[i], answer[j])` of elements in this subset satisfies: * `answer[i] % answer[j] == 0`, or * `answer[j] % answer...
dolphin
[ 0.03702733665704727, 0.023847034201025963, -0.02484973520040512, -0.022959817200899124, 0.0400884747505188, -0.032263707369565964, -0.002741627162322402, 0.055479951202869415, 0.032041285187006, -0.016286596655845642, 0.032936226576566696, 0.02495923824608326, -0.019004346802830696, -0.005...
0.846907
0.786818
0.060089
Please focus on the efficiency of this problem and provide code in Lua: 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 **Explanation:...
dolphin
[ 0.01685613952577114, 0.02313205786049366, -0.031315192580223083, -0.04382872208952904, 0.03269078955054283, -0.01855160854756832, -0.04368279129266739, 0.046929799020290375, 0.03586071729660034, -0.026513757184147835, 0.0354367271065712, 0.026539547368884087, -0.034470029175281525, -0.0039...
0.84167
0.786871
0.054799
Please focus on the efficiency of this problem and provide code in Visual Basic .NET: 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 ...
dolphin
[ 0.036827072501182556, 0.0322163961827755, -0.02118431031703949, -0.014273734763264656, 0.035592127591371536, -0.043441202491521835, -0.007412601727992296, 0.0702703595161438, 0.05912024900317192, -0.021556727588176727, 0.03973647952079773, 0.024450700730085373, -0.046897973865270615, -0.03...
0.846654
0.792867
0.053788
Please focus on the efficiency of this problem and provide code in PHP: Given an integer `n`, return _the least number of perfect square numbers that sum to_ `n`. A **perfect square** is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, `1`, `4`, `...
dolphin
[ 0.011072148568928242, 0.05106152594089508, -0.029867025092244148, -0.04715145379304886, 0.04153842478990555, -0.023336702957749367, -0.025643236935138702, 0.04850947484374046, 0.04080033302307129, 0.004054545890539885, 0.02821199782192707, 0.03693171963095665, -0.04825272783637047, -0.0392...
0.825587
0.76898
0.056607
Please focus on the functionality of this problem and provide code in Julia: 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]` i...
dolphin
[ 0.027629170566797256, 0.04037310183048248, -0.031193137168884277, -0.03494879975914955, 0.033542755991220474, -0.02590644545853138, -0.03702542185783386, 0.06282966583967209, 0.029879532754421234, -0.004969413857907057, 0.03151142597198486, 0.014156032353639603, -0.021380377933382988, -0.0...
0.844372
0.785567
0.058805
Please explain the reasoning behind the following solution and provide code in R: 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.02573147788643837, 0.025074632838368416, -0.03570665791630745, -0.026408283039927483, 0.021357472985982895, -0.01922966167330742, -0.020835721865296364, 0.05260656028985977, 0.03301268815994263, 0.012200510129332542, 0.017679650336503983, 0.020409220829606056, -0.02361218072474003, -0.02...
0.833383
0.773648
0.059734
Please focus on the algorithm of this problem and provide code in ANSI C: Given an array `nums` and an integer `target`, return _the maximum number of **non-empty** **non-overlapping** subarrays such that the sum of values in each subarray is equal to_ `target`. **Example 1:** **Input:** nums = \[1,1,1,1,1\], target ...
dolphin
[ 0.016250398010015488, 0.017428336665034294, -0.028319770470261574, -0.018898913636803627, 0.047939494252204895, -0.0028360302094370127, -0.03636972978711128, 0.052497901022434235, 0.015722205862402916, -0.021183736622333527, 0.036810487508773804, 0.0334121473133564, -0.04261881485581398, -...
0.845096
0.781584
0.063512
Please write the following solution using F#: You are given two **0-indexed** arrays `nums` and `cost` consisting each of `n` **positive** integers. You can do the following operation **any** number of times: * Increase or decrease **any** element of the array `nums` by `1`. The cost of doing one operation on the ...
dolphin
[ 0.012098773382604122, 0.02948477305471897, -0.025664443150162697, -0.03375575318932533, 0.041310690343379974, -0.02418431080877781, -0.013037454336881638, 0.07487820833921432, 0.04280228540301323, -0.015290917828679085, 0.02978760004043579, 0.014836852438747883, -0.03858782723546028, -0.03...
0.856758
0.802376
0.054382
Please write the following solution using Lisp: Given an integer array `nums`, return _the value of the bitwise_ **OR** _of the sum of all possible **subsequences** in the array_. A **subsequence** is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of t...
dolphin
[ -0.003562494646757841, 0.03408971056342125, -0.021214988082647324, -0.021346701309084892, 0.039870843291282654, -0.030629152432084084, -0.02841160260140896, 0.04809901863336563, 0.05126741901040077, -0.006219880655407906, 0.02640429325401783, 0.02733437344431877, -0.03729262948036194, -0.0...
0.835928
0.78205
0.053878
Please write the following solution using Rust: You are given two integer arrays `nums1` and `nums2` both of the same length. The **advantage** of `nums1` with respect to `nums2` is the number of indices `i` for which `nums1[i] > nums2[i]`. Return _any permutation of_ `nums1` _that maximizes its **advantage** with res...
dolphin
[ 0.02298407256603241, 0.028956733644008636, -0.006607298739254475, -0.0341666005551815, 0.019966410472989082, -0.016483187675476074, -0.035199124366045, 0.07275820523500443, 0.04544204846024513, -0.019644111394882202, 0.012499168515205383, 0.024739425629377365, -0.03233451023697853, -0.0176...
0.834598
0.773588
0.061009
Please explain the following problem in detail and provide code in Scheme: Given a string `s` and an integer `k`, return _the length of the longest_ _substring_ _of_ `s` _that contains at most_ `k` _**distinct** characters_. **Example 1:** **Input:** s = "eceba ", k = 2 **Output:** 3 **Explanation:** The substring i...
dolphin
[ 0.028475601226091385, 0.03514522686600685, -0.019388573244214058, -0.05109154433012009, 0.038499537855386734, -0.046625230461359024, -0.013701415620744228, 0.03781542181968689, 0.03164253011345863, -0.011768505908548832, 0.03538183495402336, 0.02795744128525257, -0.015118022449314594, 0.01...
0.826658
0.771786
0.054872
Please write the following solution using PHP: Given an array of integers `nums`, sort the array in ascending order and return it. You must solve the problem **without using any built-in** functions in `O(nlog(n))` time complexity and with the smallest space complexity possible. **Example 1:** **Input:** nums = \[5,...
dolphin
[ 0.01872674748301506, 0.03881409764289856, -0.005851981230080128, -0.005741695407778025, 0.0308278426527977, -0.02938828244805336, -0.025776756927371025, 0.0640886127948761, 0.03663061559200287, -0.010364597663283348, 0.022063786163926125, 0.003215820761397481, -0.04155677556991577, -0.0027...
0.818577
0.7641
0.054478
Please write the following solution using ANSI C: You are given a positive integer array `grades` which represents the grades of students in a university. You would like to enter **all** these students into a competition in **ordered** non-empty groups, such that the ordering meets the following conditions: * The su...
dolphin
[ 0.009272538125514984, 0.026462651789188385, -0.032222680747509, -0.04848432168364525, 0.04115141183137894, -0.02707827091217041, -0.047081537544727325, 0.06992775946855545, 0.012674766592681408, -0.010115103796124458, 0.011146657168865204, 0.026006044819951057, -0.05592241883277893, -0.034...
0.837906
0.774451
0.063455
Please explain the following problem in detail and provide code in Objective-C: You are given an integer array `nums` of length `n` which represents a permutation of all the integers in the range `[0, n - 1]`. The number of **global inversions** is the number of the different pairs `(i, j)` where: * `0 <= i < j < n...
dolphin
[ 0.005910049192607403, 0.036779262125492096, -0.018587153404951096, -0.017691200599074364, 0.04335055127739906, -0.0317913219332695, -0.017153315246105194, 0.08731641620397568, 0.018819842487573624, -0.012152996845543385, 0.022157948464155197, 0.023465005680918694, -0.037609294056892395, -0...
0.846477
0.791242
0.055235
Please write the following solution using Perl: You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length `n` and a positive integer `k`. You must choose a **subsequence** of indices from `nums1` of length `k`. For chosen indices `i0`, `i1`, ..., `ik - 1`, your **score** is defined as: * Th...
dolphin
[ 0.006848389282822609, 0.033430684357881546, -0.028386246412992477, -0.03093549981713295, 0.04620937258005142, -0.021508941426873207, -0.02286207489669323, 0.05166364088654518, 0.03693653270602226, -0.009068580344319344, 0.029768822714686394, 0.036855291575193405, -0.026153577491641045, 0.0...
0.846957
0.793375
0.053582
Please write the following solution using Scheme: There are `3n` piles of coins of varying size, you and your friends will take piles of coins as follows: * In each step, you will choose **any** `3` piles of coins (not necessarily consecutive). * Of your choice, Alice will pick the pile with the maximum number of ...
dolphin
[ 0.03662366420030594, 0.016775481402873993, -0.03318015858530998, -0.02988871932029724, 0.02661900594830513, -0.042885132133960724, -0.04385538399219513, 0.03277641907334328, 0.005421664100140333, -0.008531021885573864, 0.03523282706737518, 0.046392641961574554, -0.03930402919650078, -0.013...
0.850096
0.789295
0.0608
Please explain the reasoning behind the following solution and provide code in javascript: You are given an integer `n`. You roll a fair 6-sided dice `n` times. Determine the total number of **distinct** sequences of rolls possible such that the following conditions are satisfied: 1. The **greatest common divisor** o...
dolphin
[ 0.021344950422644615, 0.019908156245946884, -0.017720703035593033, -0.027297481894493103, 0.03485048934817314, -0.026201341301202774, -0.032117944210767746, 0.06000445410609245, 0.023302488029003143, -0.01288849487900734, 0.035482581704854965, 0.022006353363394737, -0.03791782259941101, -0...
0.846609
0.788415
0.058194
Please explain the reasoning behind the following solution and provide code in Scheme: 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 define...
dolphin
[ 0.027108239009976387, 0.043366361409425735, -0.02587900683283806, -0.027048004791140556, 0.03295442834496498, -0.023726515471935272, -0.04980120062828064, 0.060109008103609085, 0.04097301885485649, -0.020384974777698517, 0.023698091506958008, 0.014176765456795692, -0.03344988450407982, 0.0...
0.832494
0.777948
0.054546
Please write the following solution using F#: There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices. Each monkey moves simultaneously to a neighb...
dolphin
[ 0.006741040851920843, 0.036520205438137054, -0.007651059422641993, -0.01707945391535759, 0.029901165515184402, -0.011713268235325813, -0.03553362935781479, 0.0612926110625267, 0.04829053580760956, -0.00584483053535223, 0.028992164880037308, 0.02745448611676693, -0.031146494671702385, -0.04...
0.841612
0.787357
0.054255
Please write the following solution using c++: 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 = \[3,5,2,1,6,4\] **Output:** \[3,5,1,6,2,4\] **Explanation:** \[1,6,2,5,3,4\] is ...
dolphin
[ 0.01795269548892975, 0.02840961329638958, -0.004225849639624357, -0.01630721054971218, 0.027444133535027504, -0.008986348286271095, -0.032974496483802795, 0.09271404892206192, 0.03581015393137932, -0.006392488721758127, 0.008340398781001568, 0.01021531317383051, -0.036763861775398254, -0.0...
0.838975
0.777315
0.06166
Please explain the following problem in detail and provide code in java: You are given a 2D integer array `rectangles` where `rectangles[i] = [li, hi]` indicates that `ith` rectangle has a length of `li` and a height of `hi`. You are also given a 2D integer array `points` where `points[j] = [xj, yj]` is a point with co...
dolphin
[ -0.0029789565596729517, 0.03238129988312721, -0.034034568816423416, -0.02259206771850586, 0.02114347741007805, -0.026614753529429436, -0.02868369035422802, 0.044908057898283005, 0.027251888066530228, -0.008558623492717743, 0.013897974975407124, 0.03594661131501198, -0.02210705727338791, -0...
0.8358
0.777705
0.058094
Please explain the following problem in detail and provide code in Mojo: Given a string of digits `s`, return _the number of **palindromic subsequences** of_ `s` _having length_ `5`. Since the answer may be very large, return it **modulo** `109 + 7`. **Note:** * A string is **palindromic** if it reads the same forw...
dolphin
[ 0.005679370369762182, 0.004075870383530855, -0.03774337098002434, -0.04000912979245186, 0.03420082852244377, -0.0349709652364254, -0.030768215656280518, 0.055932577699422836, 0.026799894869327545, 0.001730039482936263, 0.031825315207242966, 0.02656683139503002, -0.03713211044669151, -0.012...
0.840341
0.786228
0.054113
Please focus on the efficiency of this problem and provide code in ANSI C: 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.029300596565008163, 0.030330829322338104, -0.01712128147482872, -0.016493961215019226, 0.02225572057068348, -0.02874961867928505, -0.04706086963415146, 0.07308865338563919, 0.03806228190660477, -0.0286693274974823, 0.02078893408179283, 0.016443608328700066, -0.02673354558646679, -0.02399...
0.842926
0.788413
0.054512
Please focus on the efficiency of this problem and provide code in java: You are given a **0-indexed** array `nums` consisting of positive integers, representing targets on a number line. You are also given an integer `space`. You have a machine which can destroy targets. **Seeding** the machine with some `nums[i]` al...
dolphin
[ 0.021715644747018814, 0.038887131959199905, -0.036754440516233444, -0.01921345666050911, 0.048327233642339706, -0.021678028628230095, -0.035427652299404144, 0.0572890043258667, 0.038890138268470764, -0.017814991995692253, 0.019355731084942818, 0.02289419434964657, -0.03537660092115402, -0....
0.851057
0.797823
0.053234
Please write the following solution using Swift: You are given an integer array `nums` of size `n` containing **each** element from `0` to `n - 1` (**inclusive**). Each of the elements from `1` to `n - 1` represents an item, and the element `0` represents an empty space. In one operation, you can move **any** item to ...
dolphin
[ 0.019081633538007736, 0.018262632191181183, -0.025736594572663307, -0.02049449272453785, 0.044984590262174606, -0.0057256161235272884, -0.032144732773303986, 0.06180322542786598, 0.031053025275468826, -0.008016216568648815, 0.019761256873607635, 0.005999229848384857, -0.031059032306075096, ...
0.845076
0.786728
0.058348
Please focus on the algorithm of this problem and provide code in Objective-C: You are given a **0-indexed** integer array `nums`. You are also given an integer `key`, which is present in `nums`. For every unique integer `target` in `nums`, **count** the number of times `target` immediately follows an occurrence of `k...
dolphin
[ 0.02476988546550274, 0.022753074765205383, -0.035610634833574295, -0.010809458792209625, 0.03433818370103836, -0.021234067156910896, -0.04348567873239517, 0.07395977526903152, 0.01941346377134323, -0.0184036735445261, 0.02989513985812664, 0.007559949532151222, -0.02966531738638878, 0.00308...
0.848278
0.794133
0.054145
Please focus on the algorithm of this problem and provide code in Mojo: You are given an integer array `nums`. We call a subset of `nums` **good** if its product can be represented as a product of one or more **distinct prime** numbers. * For example, if `nums = [1, 2, 3, 4]`: * `[2, 3]`, `[1, 2, 3]`, and `[1,...
dolphin
[ 0.02791842259466648, 0.014934173785150051, -0.025793027132749557, -0.03198548033833504, 0.034617241472005844, -0.038562506437301636, -0.03479567542672157, 0.05978751555085182, 0.0420825220644474, -0.01018813718110323, 0.027475818991661072, 0.016553375869989395, -0.03107147291302681, -0.018...
0.849454
0.794974
0.05448
Please write the following solution using F#: You are given an array `nums` consisting of positive integers. Split the array into **one or more** disjoint subarrays such that: * Each element of the array belongs to **exactly one** subarray, and * The **GCD** of the elements of each subarray is strictly greater th...
dolphin
[ 0.021376755088567734, 0.03472498059272766, -0.014211416244506836, -0.03267399221658707, 0.048574257642030716, -0.024921482428908348, -0.02320939302444458, 0.06332147866487503, 0.03237088769674301, -0.004242511931806803, 0.015088243409991264, 0.013175641186535358, -0.03012518584728241, -0.0...
0.849362
0.79294
0.056422
Please explain the following problem in detail and provide code in java: You are given a **0-indexed** array `nums` comprising of `n` non-negative integers. In one operation, you must: * Choose an integer `i` such that `1 <= i < n` and `nums[i] > 0`. * Decrease `nums[i]` by 1. * Increase `nums[i - 1]` by 1. Re...
dolphin
[ 0.021498916670680046, 0.03410759195685387, -0.04086598753929138, -0.016161080449819565, 0.0377458892762661, -0.03346981480717659, -0.039506591856479645, 0.054054144769907, 0.04247253015637398, -0.008659699000418186, 0.022781183943152428, 0.014388098381459713, -0.03349209204316139, 0.004222...
0.843745
0.775506
0.068239
Please explain the reasoning behind the following solution and provide code in Scheme: There is a set of `n` items. You are given two integer arrays `values` and `labels` where the value and the label of the `ith` element are `values[i]` and `labels[i]` respectively. You are also given two integers `numWanted` and `use...
dolphin
[ 0.01428279373794794, 0.023858247324824333, -0.035733528435230255, -0.017098231241106987, 0.05040685832500458, -0.03855147585272789, -0.0495138056576252, 0.04655591771006584, 0.027417529374361038, -0.004841651301831007, 0.03465096652507782, 0.04052630066871643, -0.036733996123075485, 0.0042...
0.851117
0.796842
0.054275
Please explain the following problem in detail and provide code in c++: Given a positive integer `n`, find and return _the **longest distance** between any two **adjacent**_ `1`_'s in the binary representation of_ `n`_. If there are no two adjacent_ `1`_'s, return_ `0`_._ Two `1`'s are **adjacent** if there are only `...
dolphin
[ 0.03241465613245964, 0.02530006505548954, -0.02455291338264942, -0.030271558091044426, 0.03135620057582855, -0.02321222610771656, -0.045307692140340805, 0.08650195598602295, 0.041827794164419174, -0.01078936830163002, 0.03862820193171501, 0.03263653442263603, -0.03458365797996521, 0.006072...
0.841091
0.773857
0.067234
Please write the following solution using java: The **bitwise AND** of an array `nums` is the bitwise AND of all integers in `nums`. * For example, for `nums = [1, 5, 3]`, the bitwise AND is equal to `1 & 5 & 3 = 1`. * Also, for `nums = [7]`, the bitwise AND is `7`. You are given an array of positive integers `ca...
dolphin
[ 0.019038569182157516, 0.03232236206531525, -0.030367258936166763, -0.014304162003099918, 0.04094521701335907, -0.01626582257449627, -0.02945956401526928, 0.03701077401638031, 0.022212039679288864, -0.013916117139160633, 0.03764684498310089, 0.0393681637942791, -0.03451741114258766, -0.0227...
0.840426
0.771745
0.068681
Please focus on the functionality of this problem and provide code in PHP: Given the `root` of a binary tree, return _the length of the longest consecutive path in the tree_. A consecutive path is a path where the values of the consecutive nodes in the path differ by one. This path can be either increasing or decreasi...
dolphin
[ 0.030113300308585167, 0.03666947782039642, -0.017224954441189766, -0.032339394092559814, 0.026133066043257713, -0.03311927244067192, -0.03102334775030613, 0.06534009426832199, 0.04415807127952576, -0.025750452652573586, 0.04313834011554718, 0.01283988542854786, -0.032847922295331955, -0.00...
0.831208
0.772586
0.058622
Please explain the following problem in detail and provide code in C#: You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either do...
dolphin
[ 0.0019682052079588175, 0.023269182071089745, -0.006609365344047546, -0.03365003317594528, 0.026954984292387962, -0.02923014760017395, -0.03003561869263649, 0.08375338464975357, 0.051376841962337494, -0.01611776277422905, 0.01213541254401207, 0.0324292853474617, -0.021396080031991005, -0.04...
0.845449
0.78995
0.055499
Please write the following solution using Scheme: You are given a **0-indexed** array `nums` consisting of positive integers, representing targets on a number line. You are also given an integer `space`. You have a machine which can destroy targets. **Seeding** the machine with some `nums[i]` allows it to destroy all ...
dolphin
[ 0.03255829960107803, 0.035538338124752045, -0.0353342667222023, -0.022454794496297836, 0.06097206100821495, -0.018153337761759758, -0.038141123950481415, 0.05817123502492905, 0.03833915293216705, -0.006825914140790701, 0.013149267062544823, 0.029136763885617256, -0.03410996496677399, -0.03...
0.850327
0.793797
0.05653
Please explain the following problem in detail and provide code in ANSI C: **Special binary strings** are binary strings with the following two properties: * The number of `0`'s is equal to the number of `1`'s. * Every prefix of the binary string has at least as many `1`'s as `0`'s. You are given a **special bina...
dolphin
[ 0.03217444568872452, 0.04078629985451698, -0.008242755196988583, -0.037088025361299515, 0.014542395249009132, -0.04311737045645714, -0.040492478758096695, 0.07328861206769943, 0.02914418652653694, -0.03680118918418884, 0.045892857015132904, 0.020434003323316574, -0.0552939772605896, -0.029...
0.831028
0.773686
0.057342
Please write the following solution using c++: You are given a **0-indexed** `m x n` integer matrix `grid` and an integer `k`. You are currently at position `(0, 0)` and you want to reach position `(m - 1, n - 1)` moving only **down** or **right**. Return _the number of paths where the sum of the elements on the path ...
dolphin
[ 0.015152103267610073, 0.023178597912192345, -0.020474262535572052, -0.04636234790086746, 0.048188142478466034, -0.034707002341747284, -0.022948434576392174, 0.09382539987564087, 0.03656649962067604, -0.009205903857946396, 0.027592701837420464, 0.019589511677622795, -0.022328242659568787, -...
0.845116
0.777549
0.067567
Please focus on the functionality of this problem and provide code in Scheme: 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 ge...
dolphin
[ 0.05439038202166557, 0.023502128198742867, -0.0319492369890213, -0.04076788201928139, 0.031065305694937706, -0.03370114415884018, -0.025687627494335175, 0.02024850994348526, 0.027696551755070686, -0.0064961789175868034, 0.015545990318059921, 0.022012853994965553, -0.04851644113659859, -0.0...
0.83454
0.78102
0.05352
Please write the following solution using Elixir: You are given `m` `arrays`, where each array is sorted in **ascending order**. You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers `a` and `b` to be their absolute differe...
dolphin
[ 0.036582812666893005, 0.023364009335637093, -0.013200986199080944, -0.03402291238307953, 0.021410049870610237, -0.03306965157389641, -0.05852910876274109, 0.025800520554184914, 0.04292474314570427, -0.02945186384022236, 0.02005763165652752, 0.022350825369358063, -0.03332603722810745, -0.00...
0.840433
0.780335
0.060098
Please focus on the efficiency of this problem and provide code in Scheme: You are given a **0-indexed** `m x n` integer matrix `grid` and an integer `k`. You are currently at position `(0, 0)` and you want to reach position `(m - 1, n - 1)` moving only **down** or **right**. Return _the number of paths where the sum ...
dolphin
[ 0.01707104779779911, 0.028948912397027016, -0.023162322118878365, -0.036386702209711075, 0.04076485335826874, -0.04320751503109932, -0.02405126579105854, 0.055828846991062164, 0.030066613107919693, -0.012401205487549305, 0.02400277554988861, 0.010992463678121567, -0.025374915450811386, -0....
0.852854
0.790751
0.062103
Please focus on the functionality of this problem and provide code in c++: Given an integer array `nums` of size `n`, return _the minimum number of moves required to make all array elements equal_. In one move, you can increment or decrement an element of the array by `1`. Test cases are designed so that the answer w...
dolphin
[ 0.016040688380599022, 0.0046181692741811275, -0.03142891451716423, -0.0365646593272686, 0.04228007048368454, -0.01753131113946438, -0.020409956574440002, 0.09931489080190659, 0.03126799315214157, -0.0336708202958107, 0.041884902864694595, 0.018027912825345993, -0.033694710582494736, -0.010...
0.84928
0.786963
0.062318
Please explain the following problem in detail and provide code in ANSI C: There are `n` cities numbered from `1` to `n`. You are given an array `edges` of size `n-1`, where `edges[i] = [ui, vi]` represents a bidirectional edge between cities `ui` and `vi`. There exists a unique path between each pair of cities. In oth...
dolphin
[ 0.008014569990336895, 0.027771474793553352, -0.01887090504169464, -0.02398681826889515, 0.013174431398510933, -0.020221101120114326, -0.025848520919680595, 0.06487073749303818, 0.029690450057387352, -0.0076995003037154675, 0.05074719712138176, 0.02738102525472641, -0.03583510220050812, -0....
0.840336
0.779665
0.060671
Please write the following solution using Kotlin: Given an integer array `nums`, return _the value of the bitwise_ **OR** _of the sum of all possible **subsequences** in the array_. A **subsequence** is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of...
dolphin
[ -0.0034921143669635057, 0.01973917707800865, -0.01780855283141136, -0.012575309723615646, 0.04481422156095505, -0.025002118200063705, -0.030350130051374435, 0.05639277771115303, 0.051083870232105255, -0.006746640428900719, 0.013957011513411999, 0.02203931100666523, -0.03585764020681381, -0...
0.838722
0.771212
0.067511
Please explain the following problem in detail and provide code in Scheme: 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 **Explanatio...
dolphin
[ 0.014749555848538876, 0.03652634844183922, -0.020270125940442085, -0.033311717212200165, 0.04514744505286217, -0.0326315313577652, -0.01325619500130415, 0.06618501991033554, 0.025339191779494286, -0.010056225582957268, 0.02067779190838337, 0.013100936077535152, -0.020675117149949074, -0.00...
0.845619
0.7822
0.063419
Please focus on the functionality of this problem and provide code in Haskell: Given an array of integers `nums` and an integer `k`, return _the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than_ `k`. **Example 1:** **Input:** nums = \[10,5,2,6\], k = 100 **Out...
dolphin
[ 0.022729750722646713, 0.02978944405913353, -0.025180315598845482, -0.012638074345886707, 0.052866216748952866, -0.013955782167613506, -0.029020685702562332, 0.05445199832320213, 0.04088805243372917, -0.0021827728487551212, 0.006857084110379219, 0.03440818935632706, -0.017995094880461693, -...
0.845316
0.790412
0.054904
Please write the following solution using Kotlin: Given an integer array `nums` that **does not contain** any zeros, find **the largest positive** integer `k` such that `-k` also exists in the array. Return _the positive integer_ `k`. If there is no such integer, return `-1`. **Example 1:** **Input:** nums = \[-1,2,...
dolphin
[ 0.022764649242162704, 0.031032798811793327, -0.017740506678819656, -0.035132408142089844, 0.044219035655260086, -0.022693734616041183, -0.02006159909069538, 0.04317634552717209, 0.02594633959233761, -0.026453813537955284, 0.025694258511066437, 0.04047749936580658, -0.02946235053241253, -0....
0.838811
0.783462
0.055348
Please write the following solution using Perl: Given an integer `n`, return _the number of ways you can write_ `n` _as the sum of consecutive positive integers._ **Example 1:** **Input:** n = 5 **Output:** 2 **Explanation:** 5 = 2 + 3 **Example 2:** **Input:** n = 9 **Output:** 3 **Explanation:** 9 = 4 + 5 = 2 + 3...
dolphin
[ 0.02545931003987789, 0.010364150628447533, -0.015392936766147614, -0.03802407532930374, 0.040576595813035965, -0.020259857177734375, -0.045238275080919266, 0.048968520015478134, 0.049676381051540375, -0.005462809465825558, 0.03429766744375229, 0.04505649581551552, -0.04781116917729378, -0....
0.820536
0.764637
0.055899
Please write the following solution using Haskell: Given an `n x n` array of integers `matrix`, return _the **minimum sum** of any **falling path** through_ `matrix`. A **falling path** starts at any element in the first row and chooses the element in the next row that is either directly below or diagonally left/right...
dolphin
[ 0.0014285218203440309, 0.005383817013353109, -0.02548757754266262, -0.0410645455121994, 0.05876984819769859, -0.0261151771992445, -0.012446664273738861, 0.04779189079999924, 0.046020831912755966, -0.020556112751364708, 0.020181236788630486, 0.008168146945536137, -0.02391216903924942, -0.02...
0.837715
0.782195
0.055521
Please focus on the functionality of this problem and provide code in PHP: 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 `...
dolphin
[ 0.03136057406663895, 0.027244742959737778, -0.01987440139055252, -0.017482584342360497, 0.0339103564620018, -0.020341891795396805, -0.041542813181877136, 0.07223813980817795, 0.03173395246267319, -0.011873946525156498, 0.04061209037899971, 0.025028442963957787, -0.02122710831463337, -0.000...
0.843113
0.787172
0.05594