instruction_seed
stringlengths
308
3.48k
source
stringclasses
1 value
embeddings
listlengths
1.02k
1.02k
mean_positive_score
float64
0.8
0.86
mean_negative_score
float64
0.74
0.8
difference_score
float64
0.05
0.07
Please write the following solution using PHP: You are given an integer array `cards` where `cards[i]` represents the **value** of the `ith` card. A pair of cards are **matching** if the cards have the **same** value. Return _the **minimum** number of **consecutive** cards you have to pick up to have a pair of **match...
dolphin
[ 0.01294758915901184, 0.02620692178606987, -0.044791072607040405, -0.025903282687067986, 0.03609189763665199, -0.010239370167255402, -0.026790792122483253, 0.05581175908446312, 0.028779063373804092, -0.03194068372249603, 0.015369176864624023, 0.014591086655855179, -0.028133604675531387, -0....
0.841606
0.785548
0.056057
Please write the following solution using F#: 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:** * `0 <= n <= 109`
dolphin
[ 0.012263145297765732, 0.01881965436041355, -0.022966209799051285, -0.042241185903549194, 0.046342529356479645, -0.0278499573469162, -0.024344636127352715, 0.041471343487501144, 0.02105303294956684, 0.006698167882859707, 0.02924596332013607, 0.030167745426297188, -0.04473034664988518, -0.03...
0.831706
0.778109
0.053597
Please write the following solution using 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 = 2 **Output:** 2 **Explana...
dolphin
[ 0.02883847802877426, 0.014260319992899895, -0.03495603799819946, -0.021837273612618446, 0.058549243956804276, 0.017456630244851112, -0.03772345930337906, 0.0566367544233799, 0.024238310754299164, -0.014719516038894653, 0.03361120447516441, 0.0401909314095974, -0.034648749977350235, -0.0287...
0.839745
0.769364
0.070381
Please write the following solution using Lua: 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.023078633472323418, 0.030380263924598694, -0.02590453252196312, -0.036402203142642975, 0.03964076191186905, -0.01881731115281582, -0.02723301202058792, 0.06022963300347328, 0.02128191664814949, -0.004665321204811335, 0.027063269168138504, 0.014043779112398624, -0.03088158741593361, -0.02...
0.844039
0.783416
0.060623
Please write the following solution using python: You are given several `boxes` with different colors represented by different positive numbers. You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of `k` boxes,...
dolphin
[ 0.027889344841241837, 0.03236784785985947, -0.027438808232545853, -0.022278135642409325, 0.018551809713244438, -0.04275840148329735, -0.020458079874515533, 0.04195442423224449, 0.03626134991645813, -0.009105074219405651, 0.014246494509279728, 0.02997841127216816, -0.019074687734246254, 0.0...
0.842823
0.782042
0.060781
Please write the following solution using Dart: Given an integer array `nums` of length `n` and an integer `target`, find three integers in `nums` such that the sum is closest to `target`. Return _the sum of the three integers_. You may assume that each input would have exactly one solution. **Example 1:** **Input:...
dolphin
[ 0.012061153538525105, 0.020370924845337868, -0.02664599008858204, -0.029361752793192863, 0.05435320362448692, -0.008629709482192993, -0.03256233036518097, 0.030372068285942078, 0.040089670568704605, -0.000007869913133617956, 0.027646005153656006, 0.03792127966880798, -0.03194067254662514, ...
0.831606
0.778258
0.053348
Please focus on the algorithm of this problem and provide code in Scala: You are given an array `nums` consisting of **positive** integers and an integer `k`. **Partition** the array into two ordered **groups** such that each element is in exactly **one** group. A partition is called great if the **sum** of elements o...
dolphin
[ 0.023555586114525795, 0.024248532950878143, -0.03163052350282669, -0.016972027719020844, 0.030957728624343872, -0.034013018012046814, -0.014470377936959267, 0.04547013342380524, 0.017152830958366394, -0.013900825753808022, 0.02897460386157036, 0.021676205098628998, -0.01890423893928528, 0....
0.844724
0.788419
0.056305
Please explain the reasoning behind the following solution and provide code in ANSI C: Given a binary string `s` and a positive integer `n`, return `true` _if the binary representation of all the integers in the range_ `[1, n]` _are **substrings** of_ `s`_, or_ `false` _otherwise_. A **substring** is a contiguous sequ...
dolphin
[ 0.009465677663683891, 0.025733383372426033, -0.027691975235939026, -0.022966234013438225, 0.037899602204561234, -0.0661439299583435, 0.004045295529067516, 0.0840957760810852, 0.024749943986535072, -0.011237524449825287, 0.023726020008325577, 0.023145221173763275, -0.02299247868359089, -0.0...
0.834587
0.780933
0.053655
Please write the following solution using Visual Basic .NET: Given an array of integers `arr` and an integer `k`. Find the _least number of unique integers_ after removing **exactly** `k` elements**.** **Example 1:** **Input:** arr = \[5,5,4\], k = 1 **Output:** 1 **Explanation**: Remove the single 4, only 5 is left....
dolphin
[ 0.026253581047058105, 0.042928218841552734, -0.024263305589556694, -0.03723686933517456, 0.04800562188029289, -0.038197021931409836, -0.016015971079468727, 0.06636063009500504, 0.05642556771636009, -0.01967632584273815, 0.021993443369865417, -0.005820611026138067, -0.0134348776191473, -0.0...
0.848303
0.785815
0.062488
Please explain the following problem in detail and provide code in c++: We have two arrays `arr1` and `arr2` which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions: * `arr1` contains `uniqueCnt1` **distinct** positive integers, each of which is **not ...
dolphin
[ 0.029812131077051163, 0.023264117538928986, -0.01375629473477602, -0.028201691806316376, 0.039176974445581436, 0.00004670278576668352, -0.027225859463214874, 0.09695800393819809, 0.048999737948179245, -0.016206273809075356, 0.020922822877764702, 0.02463093213737011, -0.01361960731446743, -...
0.842156
0.78052
0.061637
Please explain the following problem in detail and provide code in Scheme: 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 ...
dolphin
[ 0.03061913140118122, 0.026562944054603577, -0.0219962690025568, -0.014558712020516396, 0.02977234125137329, -0.02767154946923256, -0.02626836858689785, 0.05134376883506775, 0.04255997762084007, -0.009639902971684933, 0.018133550882339478, 0.05846843495965004, -0.034611765295267105, -0.0207...
0.842842
0.784846
0.057997
Please focus on the functionality of this problem and provide code in python: Given an integer array `nums` and an integer `k`, return _the length of the shortest non-empty **subarray** of_ `nums` _with a sum of at least_ `k`. If there is no such **subarray**, return `-1`. A **subarray** is a **contiguous** part of an...
dolphin
[ 0.012423343025147915, 0.03494046628475189, -0.03749614208936691, -0.025649789720773697, 0.04328063130378723, -0.005998856853693724, -0.030394209548830986, 0.039798934012651443, 0.030624011531472206, -0.0017021053936332464, 0.03165045008063316, 0.025945359840989113, -0.028697989881038666, 0...
0.84572
0.785186
0.060534
Please write the following solution using Scala: You are given an integer array `nums`. In one move, you can choose one element of `nums` and change it to **any value**. Return _the minimum difference between the largest and smallest value of `nums` **after performing at most three moves**_. **Example 1:** **Input:...
dolphin
[ 0.017299694940447807, 0.029909085482358932, -0.018548281863331795, -0.02438918687403202, 0.04892216995358467, -0.022403009235858917, -0.027495596557855606, 0.05676930770277977, 0.026743005961179733, -0.02535303123295307, 0.0396500863134861, 0.03374963998794556, -0.030380230396986008, -0.01...
0.847162
0.790178
0.056984
Please focus on the functionality of this problem and provide code in Objective-C: 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 digi...
dolphin
[ 0.039770279079675674, 0.03085971809923649, -0.031182067468762398, -0.03276539966464043, 0.01264346856623888, -0.035668786615133286, -0.03435232862830162, 0.07482227683067322, 0.023639673367142677, -0.007854470051825047, 0.03167609125375748, 0.031324319541454315, -0.05585964396595955, 0.003...
0.838488
0.782562
0.055926
Please write the following solution using java: Given an array `nums` of `n` integers, return _an array of all the **unique** quadruplets_ `[nums[a], nums[b], nums[c], nums[d]]` such that: * `0 <= a, b, c, d < n` * `a`, `b`, `c`, and `d` are **distinct**. * `nums[a] + nums[b] + nums[c] + nums[d] == target` You ...
dolphin
[ 0.02628682181239128, 0.02368328347802162, -0.026415929198265076, -0.021782632917165756, 0.05417719855904579, -0.014171424321830273, -0.012421351857483387, 0.03848796337842941, 0.03230219706892967, -0.013049107044935226, 0.019348179921507835, 0.003487935522571206, -0.028696173802018166, -0....
0.840238
0.785682
0.054556
Please write the following solution using C#: Given a `triangle` array, return _the minimum path sum from top to bottom_. For each step, you may move to an adjacent number of the row below. More formally, if you are on index `i` on the current row, you may move to either index `i` or index `i + 1` on the next row. **...
dolphin
[ 0.009466983377933502, 0.019510049372911453, -0.029246196150779724, -0.031193649396300316, 0.04408000409603119, -0.03743160516023636, -0.030801743268966675, 0.07961801439523697, 0.04030391201376915, -0.005424648988991976, 0.024225175380706787, 0.015952661633491516, -0.023615652695298195, -0...
0.842082
0.781764
0.060318
Please explain the reasoning behind the following solution and provide code in java: An integer `x` is a **good** if after rotating each digit individually by 180 degrees, we get a valid number that is different from `x`. Each digit must be rotated - we cannot choose to leave it alone. A number is valid if each digit ...
dolphin
[ 0.016831835731863976, 0.012169678695499897, -0.033780135214328766, -0.019065238535404205, 0.012821629643440247, -0.03212916851043701, -0.03615597262978554, 0.030959028750658035, 0.014550482854247093, -0.020731177181005478, 0.006860433146357536, 0.030522093176841736, -0.03528967127203941, -...
0.843757
0.785833
0.057923
Please explain the following problem in detail and provide code in C#: There is an undirected weighted connected graph. You are given a positive integer `n` which denotes that the graph has `n` nodes labeled from `1` to `n`, and an array `edges` where each `edges[i] = [ui, vi, weighti]` denotes that there is an edge be...
dolphin
[ -0.00040720929973758757, 0.03488418459892273, -0.01606658846139908, -0.02553306147456169, 0.03450460731983185, -0.03604584187269211, -0.02710658498108387, 0.07989344000816345, 0.0362529493868351, 0.0006011935765855014, 0.034973595291376114, 0.028562773019075394, -0.023056749254465103, -0.0...
0.84247
0.784841
0.057629
Please explain the reasoning behind the following solution and provide code in C#: Given an integer array `nums`, return `0` _if the sum of the digits of the minimum integer in_ `nums` _is odd, or_ `1` _otherwise_. **Example 1:** **Input:** nums = \[34,23,1,24,75,33,54,8\] **Output:** 0 **Explanation:** The minimal e...
dolphin
[ -0.00043548105168156326, 0.01781061477959156, -0.02628498151898384, -0.03998308628797531, 0.044515013694763184, -0.028933312743902206, -0.015303703024983406, 0.08404739946126938, 0.03650185838341713, -0.0025929869152605534, 0.00733759393915534, 0.013629838824272156, -0.042833734303712845, ...
0.835102
0.781698
0.053404
Please write the following solution using c++: You are given an `m x n` binary matrix `grid`. An island is a group of `1`'s (representing land) connected **4-directionally** (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The **area** of an island is the number of cells wit...
dolphin
[ 0.012013535015285015, 0.017485443502664566, -0.021050412207841873, -0.04962915554642677, 0.055568937212228775, -0.03376556932926178, -0.042830076068639755, 0.08373698592185974, 0.03349755331873894, -0.014907577075064182, 0.029672225937247276, 0.029012029990553856, -0.034052569419145584, -0...
0.824042
0.768521
0.055521
Please write the following solution using ANSI C: Given a binary array `nums`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most one_ `0`. **Example 1:** **Input:** nums = \[1,0,1,1,0\] **Output:** 4 **Explanation:** - If we flip the first zero, nums becomes \[1,1,1,1,0\] and we ...
dolphin
[ 0.002350817434489727, 0.042275357991456985, 0.0036027380265295506, -0.02689388580620289, 0.03058905526995659, -0.01932421512901783, -0.05102287605404854, 0.06414303183555603, 0.032740380614995956, -0.031720973551273346, 0.021627036854624748, 0.012174751609563828, -0.0329521968960762, -0.01...
0.836592
0.766705
0.069887
Please write the following solution using R: You are given a positive integer `p`. Consider an array `nums` (**1-indexed**) that consists of the integers in the **inclusive** range `[1, 2p - 1]` in their binary representations. You are allowed to do the following operation **any** number of times: * Choose two eleme...
dolphin
[ 0.018390512093901634, 0.04010947421193123, -0.025592755526304245, -0.01926458440721035, 0.04653725028038025, -0.026272524148225784, -0.03936099633574486, 0.07078920304775238, 0.04564819484949112, -0.010293086990714073, 0.007475808262825012, 0.025186792016029358, -0.03324848413467407, -0.03...
0.848691
0.793231
0.055459
Please write the following solution using Kotlin: You are visiting a farm that has a single row of fruit trees arranged from left to right. The trees are represented by an integer array `fruits` where `fruits[i]` is the **type** of fruit the `ith` tree produces. You want to collect as much fruit as possible. However, ...
dolphin
[ 0.014468626119196415, 0.028123782947659492, -0.014308905228972435, -0.02989107556641102, 0.01458773948252201, -0.016621166840195656, -0.016221651807427406, 0.06373881548643112, 0.018082652240991592, -0.0241212360560894, 0.01528721023350954, 0.04021528735756874, -0.02077503688633442, 0.0015...
0.841987
0.788716
0.053271
Please focus on the algorithm of this problem and provide code in Objective-C: You are given an array `nums` that consists of non-negative integers. Let us define `rev(x)` as the reverse of the non-negative integer `x`. For example, `rev(123) = 321`, and `rev(120) = 21`. A pair of indices `(i, j)` is **nice** if it sat...
dolphin
[ 0.022548658773303032, 0.021557452157139778, -0.031182553619146347, -0.030085837468504906, 0.0393175408244133, -0.024137703701853752, -0.03815414384007454, 0.06653232872486115, 0.016084721311926842, -0.009457406587898731, 0.028494495898485184, 0.028820039704442024, -0.04157518967986107, -0....
0.845614
0.78932
0.056294
Please explain the following problem in detail and provide code in java: You are given an integer array `cookies`, where `cookies[i]` denotes the number of cookies in the `ith` bag. You are also given an integer `k` that denotes the number of children to distribute **all** the bags of cookies to. All the cookies in the...
dolphin
[ 0.0021636346355080605, 0.03684069961309433, -0.024775085970759392, -0.03536266088485718, 0.02180783636868, -0.003135724924504757, -0.021685441955924034, 0.05833662301301956, 0.02964751422405243, -0.03267408907413483, 0.028634632006287575, 0.023466452956199646, -0.02539108321070671, -0.0039...
0.8397
0.782071
0.057629
Please explain the following problem in detail and provide code in Visual Basic .NET: 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 ri...
dolphin
[ 0.01832263171672821, 0.03134390339255333, -0.022556282579898834, -0.040693581104278564, 0.03307120129466057, -0.01173517294228077, -0.011441652663052082, 0.08171790838241577, 0.04920134320855141, -0.027494540438055992, 0.04028572142124176, 0.03391930088400841, -0.02085370197892189, -0.0289...
0.849141
0.79388
0.055261
Please write the following solution using Swift: 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 interpreted as a binary number, and th...
dolphin
[ 0.00421129958704114, 0.017225319519639015, -0.019599223509430885, -0.047877900302410126, 0.056713659316301346, -0.049028392881155014, -0.04368698224425316, 0.050113365054130554, 0.03307028487324715, -0.003762878943234682, 0.021978387609124184, 0.013959779404103756, -0.04524272307753563, -0...
0.835935
0.781944
0.053991
Please focus on the functionality of this problem and provide code in java: A series of highways connect `n` cities numbered from `0` to `n - 1`. You are given a 2D integer array `highways` where `highways[i] = [city1i, city2i, tolli]` indicates that there is a highway that connects `city1i` and `city2i`, allowing a ca...
dolphin
[ 0.004200504627078772, 0.01971283182501793, -0.029069432988762856, -0.024797039106488228, 0.03710665926337242, -0.01987810991704464, -0.03026355616748333, 0.04657325521111488, 0.031816981732845306, -0.02010163851082325, 0.03523693606257439, 0.019935831427574158, -0.014882546849548817, -0.01...
0.841005
0.786631
0.054374
Please write the following solution using Scheme: Given an array of `points` where `points[i] = [xi, yi]` represents a point on the **X-Y** plane, return _the maximum number of points that lie on the same straight line_. **Example 1:** **Input:** points = \[\[1,1\],\[2,2\],\[3,3\]\] **Output:** 3 **Example 2:** **I...
dolphin
[ 0.007603814825415611, 0.016512535512447357, -0.02594076283276081, -0.045477721840143204, 0.03811153024435043, -0.010411445051431656, -0.041284192353487015, 0.03192785754799843, 0.05008769780397415, -0.007182621862739325, -0.0021726484410464764, 0.028748244047164917, -0.007971664890646935, ...
0.827079
0.76436
0.062719
Please write the following solution using c++: You are given a **0-indexed** array `arr` consisting of `n` positive integers, and a positive integer `k`. The array `arr` is called **K-increasing** if `arr[i-k] <= arr[i]` holds for every index `i`, where `k <= i <= n-1`. * For example, `arr = [4, 1, 5, 2, 6, 2]` is ...
dolphin
[ 0.022933609783649445, 0.04787663742899895, -0.011906774714589119, -0.033713679760694504, 0.02798939310014248, -0.009515783749520779, -0.03419504314661026, 0.11058829724788666, 0.03818916156888008, -0.011911419220268726, 0.023063194006681442, 0.0007754596299491823, -0.02803347259759903, 0.0...
0.844912
0.781312
0.0636
Please explain the reasoning behind the following solution and provide code in python: You are given the array `nums` consisting of `n` positive integers. You computed the sum of all non-empty continuous subarrays from the array and then sorted them in non-decreasing order, creating a new array of `n * (n + 1) / 2` num...
dolphin
[ 0.028381412848830223, 0.0418211854994297, -0.03283633664250374, -0.030085042119026184, 0.03300738334655762, -0.017924416810274124, -0.029388029128313065, 0.038474537432193756, 0.01931028626859188, -0.0021501423325389624, 0.0239018015563488, 0.02305966056883335, -0.0524786114692688, 0.00503...
0.844919
0.787491
0.057427
Please explain the reasoning behind the following solution and provide code in 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 th...
dolphin
[ 0.020950786769390106, 0.025801079347729683, -0.02013275772333145, -0.043305832892656326, 0.03766432777047157, -0.0009047666098922491, -0.025654984638094902, 0.09758336842060089, 0.039946675300598145, -0.017049018293619156, 0.02284909598529339, 0.04316546395421028, -0.03477250784635544, 0.0...
0.835608
0.776483
0.059125
Please focus on the efficiency of this problem and provide code in python: Given an integer array `nums`, return _the number of elements that have **both** a strictly smaller and a strictly greater element appear in_ `nums`. **Example 1:** **Input:** nums = \[11,7,2,15\] **Output:** 2 **Explanation:** The element 7 h...
dolphin
[ 0.011074029840528965, 0.02317851223051548, -0.030630186200141907, -0.024445561692118645, 0.02611897885799408, -0.00498239416629076, -0.033194996416568756, 0.06315720826387405, 0.02460910752415657, -0.01729809120297432, 0.02832927368581295, 0.03560671582818031, -0.03944726660847664, -0.0172...
0.844653
0.789008
0.055645
Please focus on the functionality of this problem and provide code in ANSI C: Given two **sorted 0-indexed** integer arrays `nums1` and `nums2` as well as an integer `k`, return _the_ `kth` _(**1-based**) smallest product of_ `nums1[i] * nums2[j]` _where_ `0 <= i < nums1.length` _and_ `0 <= j < nums2.length`. **Exampl...
dolphin
[ 0.03184397146105766, 0.061270374804735184, -0.021834846585989, -0.040308330208063126, 0.05166810005903244, -0.024540182203054428, -0.02258557267487049, 0.09033659845590591, 0.045423898845911026, -0.014054646715521812, 0.019984424114227295, 0.010140571743249893, -0.02917442098259926, -0.033...
0.837333
0.780357
0.056977
Please explain the following problem in detail and provide code in c++: Given two integer arrays `arr1` and `arr2`, and the integer `d`, _return the distance value between the two arrays_. The distance value is defined as the number of elements `arr1[i]` such that there is not any element `arr2[j]` where `|arr1[i]-arr...
dolphin
[ 0.013225658796727657, 0.015628593042492867, -0.025730589404702187, -0.04332901909947395, 0.045551132410764694, -0.006198788061738014, -0.03899169713258743, 0.09111573547124863, 0.055167920887470245, -0.02379857376217842, 0.027601294219493866, 0.03726250305771828, -0.025687726214528084, 0.0...
0.818983
0.76313
0.055853
Please write the following solution using java: You are given an integer array `nums`. You must perform **exactly one** operation where you can **replace** one element `nums[i]` with `nums[i] * nums[i]`. Return _the **maximum** possible subarray sum after **exactly one** operation_. The subarray must be non-empty. **...
dolphin
[ 0.02987159788608551, 0.04243595898151398, -0.02450336143374443, -0.024002641439437866, 0.04369528219103813, -0.01571367122232914, -0.023205546662211418, 0.05311219021677971, 0.03764861077070236, -0.013044671155512333, 0.027700772508978844, 0.020509278401732445, -0.027881214395165443, -0.02...
0.844608
0.77331
0.071299
Please explain the following problem in detail and provide code in python: 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.01547741238027811, 0.03993386775255203, -0.023137817159295082, -0.03369280695915222, 0.04225137084722519, -0.0324852392077446, -0.014171083457767963, 0.06404701620340347, 0.019489413127303123, -0.00709787430241704, 0.022400280460715294, 0.013416470028460026, -0.020093463361263275, -0.002...
0.847122
0.785677
0.061445
Please explain the following problem in detail and provide code in c++: 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**...
dolphin
[ 0.006888275500386953, 0.01054029818624258, -0.019952116534113884, -0.028211841359734535, 0.047024231404066086, -0.023302780464291573, -0.0323648527264595, 0.08051461726427078, 0.046172451227903366, -0.007318239659070969, 0.04191498085856438, 0.04228076711297035, -0.02268410287797451, 0.017...
0.841446
0.780528
0.060918
Please write the following solution using Objective-C: You are given a string `s` that consists of the digits `'1'` to `'9'` and two integers `k` and `minLength`. A partition of `s` is called **beautiful** if: * `s` is partitioned into `k` non-intersecting substrings. * Each substring has a length of **at least**...
dolphin
[ 0.019202474504709244, 0.01817924529314041, -0.034029219299554825, -0.045951519161462784, 0.04207303002476692, -0.037586312741041183, -0.018218081444501877, 0.05747145786881447, 0.035258397459983826, -0.0091620571911335, 0.04687950015068054, 0.02273567020893097, -0.02438201941549778, 0.0034...
0.85071
0.794133
0.056577
Please write the following solution using Mojo: 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`, re...
dolphin
[ 0.02491573616862297, 0.03252537548542023, -0.01935143955051899, -0.04087916389107704, 0.03012676350772381, -0.00849959161132574, -0.029529865831136703, 0.06290196627378464, 0.04149400815367699, -0.02578006125986576, 0.03400222584605217, 0.026216231286525726, -0.020876096561551094, -0.03111...
0.850967
0.789816
0.061151
Please focus on the algorithm of this problem and provide code in java: 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] XO...
dolphin
[ 0.0374533012509346, 0.02882266789674759, -0.032223813235759735, -0.012136274017393589, 0.018810709938406944, -0.02805214188992977, -0.028954530134797096, 0.057458218187093735, 0.03808284178376198, -0.01437324471771717, 0.026861224323511124, 0.005966782569885254, -0.03740497678518295, -0.01...
0.844136
0.783727
0.060409
Please explain the following problem in detail and provide code in ANSI C: You are given a **0-indexed** integer array `nums` and a positive integer `k`. We call an index `i` **k-big** if the following conditions are satisfied: * There exist at least `k` different indices `idx1` such that `idx1 < i` and `nums[idx1]...
dolphin
[ 0.018275553360581398, 0.047264955937862396, -0.018372058868408203, -0.04097292944788933, 0.024095913395285606, -0.01552662905305624, -0.029852207750082016, 0.07946878671646118, 0.017971301451325417, -0.012733657844364643, 0.031330276280641556, 0.024906925857067108, -0.04392794147133827, -0...
0.839657
0.773117
0.06654
Please explain the reasoning behind the following solution and provide code in Dart: 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 consec...
dolphin
[ 0.01888863556087017, 0.021443599835038185, -0.01695091463625431, -0.0341997891664505, 0.042427945882081985, -0.007003181613981724, -0.027148369699716568, 0.055520638823509216, 0.04160134494304657, -0.004835919011384249, 0.019498903304338455, 0.022410713136196136, -0.035079631954431534, -0....
0.842647
0.788726
0.053921
Please focus on the efficiency of this problem and provide code in java: You are given an integer array `coins` of length `n` which represents the `n` coins that you own. The value of the `ith` coin is `coins[i]`. You can **make** some value `x` if you can choose some of your `n` coins such that their values sum up to ...
dolphin
[ 0.022845681756734848, 0.03459775075316429, -0.030349550768733025, -0.014531736262142658, 0.02978239580988884, -0.030487552285194397, -0.04583548754453659, 0.04125214368104935, 0.03315499797463417, -0.03819100931286812, 0.04299124702811241, 0.03094770573079586, -0.03662563115358353, -0.0205...
0.8485
0.781307
0.067193
Please write the following solution using Dart: Given the array `nums`, obtain a subsequence of the array whose sum of elements is **strictly greater** than the sum of the non included elements in such subsequence. If there are multiple solutions, return the subsequence with **minimum size** and if there still exist m...
dolphin
[ 0.007441679015755653, 0.027264581993222237, -0.019888415932655334, -0.03504258021712303, 0.05377199500799179, -0.00913250632584095, -0.014801984652876854, 0.04660828039050102, 0.04259086027741432, -0.013183413073420525, 0.01930040307343006, 0.02784508466720581, -0.04175965487957001, -0.007...
0.842095
0.784228
0.057867
Please write the following solution using Scala: 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. Return _the **minimum** po...
dolphin
[ 0.025148456916213036, 0.03312496840953827, -0.026890523731708527, -0.02004377357661724, 0.04424317553639412, -0.03343597799539566, -0.0357978418469429, 0.059965793043375015, 0.03714478388428688, -0.010228062979876995, 0.020351992920041084, 0.020605159923434258, -0.021143469959497452, 0.003...
0.845717
0.785464
0.060252
Please focus on the algorithm of this problem and provide code in Scheme: 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.012545302510261536, 0.00410938635468483, -0.029045717790722847, -0.021292157471179962, 0.05256263166666031, -0.005961167626082897, -0.03865787759423256, 0.05135154351592064, 0.0155915142968297, -0.010020876303315163, 0.024353673681616783, 0.03447292000055313, -0.04301448166370392, -0.013...
0.85039
0.784286
0.066104
Please write the following solution using ANSI C: You have `n` dice, and each die has `k` faces numbered from `1` to `k`. Given three integers `n`, `k`, and `target`, return _the number of possible ways (out of the_ `kn` _total ways)_ _to roll the dice, so the sum of the face-up numbers equals_ `target`. Since the ans...
dolphin
[ 0.03150048106908798, 0.04149434715509415, -0.02621706761419773, -0.03266865760087967, 0.04334956407546997, -0.008640042506158352, -0.024689773097634315, 0.05813972279429436, 0.029492875561118126, -0.013240138068795204, 0.04409854859113693, 0.04320070520043373, -0.041215453296899796, -0.015...
0.833393
0.775272
0.058121
Please focus on the functionality of this problem and provide code in ANSI C: Given a digit string `s`, return _the number of **unique substrings** of_ `s` _where every digit appears the same number of times._ **Example 1:** **Input:** s = "1212 " **Output:** 5 **Explanation:** The substrings that meet the requireme...
dolphin
[ 0.005386286415159702, 0.017563676461577415, -0.03636147826910019, -0.023682527244091034, 0.02444877289235592, -0.03565891087055206, -0.02043905481696129, 0.07526969909667969, 0.01687362603843212, 0.004814793821424246, 0.027208469808101654, 0.019365863874554634, -0.03815951943397522, -0.008...
0.837294
0.778653
0.058641
Please write the following solution using ANSI C: Given two positive integers `a` and `b`, return _the number of **common** factors of_ `a` _and_ `b`. An integer `x` is a **common factor** of `a` and `b` if `x` divides both `a` and `b`. **Example 1:** **Input:** a = 12, b = 6 **Output:** 4 **Explanation:** The commo...
dolphin
[ 0.03577479347586632, 0.044508110731840134, -0.03427659347653389, -0.019030094146728516, 0.029588675126433372, -0.009759118780493736, -0.024404441937804222, 0.07562919706106186, 0.025934429839253426, -0.03153209760785103, 0.0131702134385705, 0.0289682075381279, -0.03181396797299385, -0.0335...
0.81141
0.750083
0.061327
Please write the following solution using c++: A **confusing number** is a number that when rotated `180` degrees becomes a different number with **each digit valid**. We can rotate digits of a number by `180` degrees to form new digits. * When `0`, `1`, `6`, `8`, and `9` are rotated `180` degrees, they become `0`,...
dolphin
[ 0.011062338016927242, 0.01941179670393467, -0.006951173301786184, -0.02831195667386055, 0.018191784620285034, -0.018423480913043022, -0.03504268825054169, 0.06036984920501709, 0.02907261624932289, -0.008481433615088463, 0.010094867087900639, 0.0324813649058342, -0.03565847501158714, -0.029...
0.829901
0.769841
0.06006
Please write the following solution using c++: There is an infrastructure of `n` cities with some number of `roads` connecting these cities. Each `roads[i] = [ai, bi]` indicates that there is a bidirectional road between cities `ai` and `bi`. The **network rank** of **two different cities** is defined as the total num...
dolphin
[ 0.03015395998954773, 0.016612587496638298, -0.016222374513745308, -0.01489003375172615, 0.028861569240689278, -0.0012820165138691664, -0.03758896514773369, 0.08135179430246353, 0.04281677305698395, -0.01919110119342804, 0.018631065264344215, 0.0495278462767601, -0.02459963597357273, -0.020...
0.833613
0.777792
0.055821
Please write the following solution using C#: Given an integer array `arr`, and an integer `target`, return the number of tuples `i, j, k` such that `i < j < k` and `arr[i] + arr[j] + arr[k] == target`. As the answer can be very large, return it **modulo** `109 + 7`. **Example 1:** **Input:** arr = \[1,1,2,2,3,3,4,4...
dolphin
[ 0.02546674571931362, 0.028431814163923264, -0.03607376292347908, -0.03151177614927292, 0.04439740255475044, -0.021648051217198372, -0.034790948033332825, 0.07753634452819824, 0.0286631491035223, -0.00705669866874814, 0.022677775472402573, 0.0162718053907156, -0.04541166499257088, -0.025950...
0.846332
0.787147
0.059184
Please write the following solution using PHP: Given an integer `n`, return _the number of strings of length_ `n` _that consist only of vowels (_`a`_,_ `e`_,_ `i`_,_ `o`_,_ `u`_) and are **lexicographically sorted**._ A string `s` is **lexicographically sorted** if for all valid `i`, `s[i]` is the same as or comes bef...
dolphin
[ 0.03606349229812622, 0.032340653240680695, -0.017493532970547676, -0.025868335738778114, 0.03124820441007614, -0.029892995953559875, -0.0353739932179451, 0.06994525343179703, 0.02744246833026409, -0.001414168975315988, 0.02457473613321781, 0.013449681922793388, -0.03413049876689911, -0.044...
0.831248
0.778023
0.053224
Please explain the following problem in detail and provide code in java: You have `n` super washing machines on a line. Initially, each washing machine has some dresses or is empty. For each move, you could choose any `m` (`1 <= m <= n`) washing machines, and pass one dress of each washing machine to one of its adjace...
dolphin
[ 0.01149580255150795, 0.024545669555664062, -0.03952183574438095, -0.030321476981043816, 0.03458719328045845, -0.00650817109271884, -0.040324434638023376, 0.053093764930963516, -0.0013906979002058506, -0.009472912177443504, 0.02743496745824814, 0.03132022172212601, -0.014487982727587223, -0...
0.844837
0.783395
0.061443
Please explain the following problem in detail and provide code in javascript: 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` are ...
dolphin
[ 0.009399003349244595, 0.04592267796397209, -0.028422877192497253, -0.02344297245144844, 0.042902108281850815, -0.017536586150527, -0.018393050879240036, 0.06289254128932953, 0.028793025761842728, -0.0128932548686862, 0.02016887441277504, 0.005324787925928831, -0.04079863429069519, -0.02134...
0.842454
0.783215
0.059239
Please explain the following problem in detail and provide code in Objective-C: You are given an integer `n` and an integer `start`. Define an array `nums` where `nums[i] = start + 2 * i` (**0-indexed**) and `n == nums.length`. Return _the bitwise XOR of all elements of_ `nums`. **Example 1:** **Input:** n = 5, sta...
dolphin
[ 0.03015034832060337, 0.034951161593198776, -0.04254831001162529, -0.0219209473580122, 0.023346420377492905, -0.03942803293466568, -0.022535331547260284, 0.07588964700698853, 0.03512889891862869, -0.014264300465583801, 0.0315568707883358, 0.013564025051891804, -0.05764622986316681, -0.02078...
0.836514
0.782894
0.053621
Please explain the following problem in detail and provide code in Visual Basic .NET: 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 suba...
dolphin
[ 0.02335379458963871, 0.02419796772301197, -0.021172724664211273, -0.028303194791078568, 0.030118141323328018, -0.02554246596992016, -0.03781510517001152, 0.07404610514640808, 0.04994436725974083, -0.016920320689678192, 0.02615879662334919, 0.0294206403195858, -0.038678720593452454, -0.0087...
0.843036
0.781464
0.061572
Please write the following solution using Scheme: You are given the `head` of a linked list containing unique integer values and an integer array `nums` that is a subset of the linked list values. Return _the number of connected components in_ `nums` _where two values are connected if they appear **consecutively** in ...
dolphin
[ 0.033412039279937744, 0.024949699640274048, -0.025080913677811623, -0.013446644879877567, 0.041081517934799194, -0.018197307363152504, -0.02316157892346382, 0.05061991512775421, 0.03618311509490013, 0.007456444203853607, 0.019302353262901306, 0.016888150945305824, -0.01757119409739971, -0....
0.83241
0.766002
0.066408
Please focus on the algorithm of this problem and provide code in Kotlin: Given two integers `n` and `k`, return _all possible combinations of_ `k` _numbers chosen from the range_ `[1, n]`. You may return the answer in **any order**. **Example 1:** **Input:** n = 4, k = 2 **Output:** \[\[1,2\],\[1,3\],\[1,4\],\[2,3\...
dolphin
[ 0.025028131902217865, 0.030960235744714737, -0.012052616104483604, -0.029189156368374825, 0.04712241515517235, -0.0363723449409008, -0.009861696511507034, 0.047987163066864014, 0.02574440836906433, -0.0036899929400533438, 0.03734100982546806, 0.0405406653881073, -0.028882605955004692, 0.00...
0.831364
0.776738
0.054626
Please focus on the functionality of this problem and provide code in c++: You are given a **0-indexed** integer array `nums` of **even** length. As long as `nums` is **not** empty, you must repetitively: * Find the minimum number in `nums` and remove it. * Find the maximum number in `nums` and remove it. * Cal...
dolphin
[ 0.008860484696924686, 0.02212056890130043, -0.026080574840307236, -0.022773688659071922, 0.0463680624961853, -0.02473200112581253, -0.044274378567934036, 0.09235785901546478, 0.04511455446481705, -0.01820448413491249, 0.014740437269210815, 0.0036713152658194304, -0.03139244392514229, -0.01...
0.835177
0.781879
0.053298
Please explain the following problem in detail and provide code in c++: Winston was given the above mysterious function `func`. He has an integer array `arr` and an integer `target` and he wants to find the values `l` and `r` that make the value `|func(arr, l, r) - target|` minimum possible. Return _the minimum possib...
dolphin
[ 0.019443703815340996, 0.031104424968361855, -0.027398627251386642, -0.03142659366130829, 0.05747923254966736, -0.006085013970732689, -0.04454512521624565, 0.08649090677499771, 0.045517757534980774, -0.02263367921113968, 0.031620997935533524, 0.03160713613033295, -0.016191426664590836, -0.0...
0.840999
0.783836
0.057163
Please write the following solution using Julia: Given an array `nums` of integers, return how many of them contain an **even number** of digits. **Example 1:** **Input:** nums = \[12,345,2,6,7896\] **Output:** 2 **Explanation:** 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of dig...
dolphin
[ 0.0026978019159287214, 0.012089925818145275, -0.015552428551018238, -0.03917287290096283, 0.028854748234152794, -0.015990495681762695, -0.030357608571648598, 0.048014067113399506, 0.01851355843245983, 0.008206043392419815, 0.008166821673512459, 0.03133251145482063, -0.03630039468407631, -0...
0.82989
0.774336
0.055553
Please explain the reasoning behind the following solution and provide code in java: Given the `root` of a binary tree, return the most frequent **subtree sum**. If there is a tie, return all the values with the highest frequency in any order. The **subtree sum** of a node is defined as the sum of all the node values ...
dolphin
[ 0.02315332554280758, 0.02507249265909195, -0.040919478982686996, -0.016352340579032898, 0.023801075294613838, -0.03585648164153099, -0.0012682235101237893, 0.03983939439058304, 0.014101669192314148, 0.0030548335053026676, 0.0438271090388298, 0.0196406077593565, -0.03839239850640297, 0.0179...
0.831557
0.774833
0.056724
Please explain the following problem in detail and provide code in Scheme: You are given a **0-indexed** array `nums` of length `n`, consisting of non-negative integers. For each index `i` from `0` to `n - 1`, you must determine the size of the **minimum sized** non-empty subarray of `nums` starting at `i` (**inclusive...
dolphin
[ 0.010271718725562096, 0.023525377735495567, -0.037037402391433716, -0.009041771292686462, 0.026230338960886, -0.026755716651678085, -0.03425925597548485, 0.05110225826501846, 0.041786905378103256, -0.00745930103585124, 0.03050003945827484, 0.0289885476231575, -0.035750504583120346, 0.00319...
0.851709
0.783941
0.067768
Please write the following solution using Kotlin: Given an array of integers `nums` which is sorted in ascending order, and an integer `target`, write a function to search `target` in `nums`. If `target` exists, then return its index. Otherwise, return `-1`. You must write an algorithm with `O(log n)` runtime complexi...
dolphin
[ 0.01931440830230713, 0.04019184410572052, -0.025105200707912445, -0.013742118142545223, 0.03735879436135292, -0.0063582113943994045, -0.02462092414498329, 0.04871276021003723, 0.02597692236304283, -0.012649592012166977, 0.02891910821199417, 0.0125301918014884, -0.023610403761267662, -0.005...
0.838752
0.784419
0.054332
Please write the following solution using Scheme: Given a string `s` of lowercase letters, you need to find the maximum number of **non-empty** substrings of `s` that meet the following conditions: 1. The substrings do not overlap, that is for any two substrings `s[i..j]` and `s[x..y]`, either `j < x` or `i > y` is t...
dolphin
[ 0.025911841541528702, 0.013064724393188953, -0.030590053647756577, -0.018125753849744797, 0.05015266314148903, -0.025102397426962852, -0.019342895597219467, 0.03734632208943367, 0.024730408564209938, -0.020274482667446136, 0.027945145964622498, 0.029386892914772034, -0.036233123391866684, ...
0.845419
0.789191
0.056228
Please write the following solution using Haskell: You are given an integer array `nums`. A number `x` is **lonely** when it appears only **once**, and no **adjacent** numbers (i.e. `x + 1` and `x - 1)` appear in the array. Return _**all** lonely numbers in_ `nums`. You may return the answer in **any order**. **Examp...
dolphin
[ 0.022233452647924423, 0.03388660401105881, -0.009547095745801926, -0.02625185064971447, 0.04019562527537346, -0.025355264544487, -0.008086176589131355, 0.042186710983514786, 0.04034404084086418, -0.012128271162509918, 0.019048606976866722, 0.010198395699262619, -0.030102815479040146, -0.02...
0.839786
0.781291
0.058495
Please write the following solution using Elixir: You are given an integer array `nums`. A subsequence of `nums` is called a **square streak** if: * The length of the subsequence is at least `2`, and * **after** sorting the subsequence, each element (except the first element) is the **square** of the previous numb...
dolphin
[ 0.0037299618124961853, 0.030578667297959328, -0.03171723708510399, -0.047686200588941574, 0.03427385538816452, -0.02007060870528221, -0.03457788750529289, 0.05795549228787422, 0.04091492295265198, -0.003897320246323943, 0.03406146168708801, 0.019606195390224457, -0.027903839945793152, -0.0...
0.851219
0.792404
0.058815
Please write the following solution using c++: You are given an array `points` representing integer coordinates of some points on a 2D-plane, where `points[i] = [xi, yi]`. The cost of connecting two points `[xi, yi]` and `[xj, yj]` is the **manhattan distance** between them: `|xi - xj| + |yi - yj|`, where `|val|` deno...
dolphin
[ 0.0021558119915425777, 0.03161058947443962, -0.028684694319963455, -0.01659148931503296, 0.034047745168209076, -0.011340868659317493, -0.021422168239951134, 0.06253128498792648, 0.06736651062965393, -0.014424053020775318, 0.03090468794107437, 0.03692587465047836, -0.005306950770318508, -0....
0.832027
0.776761
0.055266
Please explain the reasoning behind the following solution and provide code in java: 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`, ...
dolphin
[ 0.005415559746325016, 0.030953722074627876, -0.027209950610995293, -0.02364213392138481, 0.04366526007652283, -0.034072279930114746, -0.030838467180728912, 0.03992704302072525, 0.029347151517868042, -0.01495600026100874, 0.02747388184070587, 0.026266882196068764, -0.028146961703896523, 0.0...
0.847542
0.785544
0.061999
Please explain the following problem in detail and provide code in R: 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 all...
dolphin
[ 0.011546901427209377, 0.026096826419234276, -0.019687481224536896, -0.02045675553381443, 0.049008943140506744, -0.026019876822829247, -0.04579465836286545, 0.0321362167596817, 0.04070331156253815, -0.005462345667183399, 0.012622089125216007, 0.03237428143620491, -0.03062201850116253, -0.01...
0.824526
0.767231
0.057295
Please write the following solution using PHP: You are given two **sorted** arrays of distinct integers `nums1` and `nums2.` A **valid path** is defined as follows: * Choose array `nums1` or `nums2` to traverse (from index-0). * Traverse the current array from left to right. * If you are reading any value that ...
dolphin
[ 0.00936804711818695, 0.021549349650740623, -0.025685012340545654, -0.023906931281089783, 0.024008337408304214, -0.024990139529109, -0.039001304656267166, 0.05382392928004265, 0.04595139995217323, -0.024697862565517426, 0.03287876397371292, 0.02988465130329132, -0.02030133828520775, -0.0171...
0.84778
0.787687
0.060093
Please write the following solution using F#: You are given an integer array `nums` and an integer `k`. Find the maximum subarray sum of all the subarrays of `nums` that meet the following conditions: * The length of the subarray is `k`, and * All the elements of the subarray are **distinct**. Return _the maximum...
dolphin
[ 0.012773703783750534, 0.01776917651295662, -0.028919000178575516, -0.037040725350379944, 0.05359429493546486, -0.02210531197488308, -0.018102465197443962, 0.05875381454825401, 0.0304642915725708, 0.004084527026861906, 0.03538835048675537, 0.033939048647880554, -0.0443015955388546, -0.00265...
0.847204
0.788211
0.058993
Please explain the following problem in detail and provide code in R: Given an integer array `nums` of length `n` and an integer `k`, return _the_ `kth` _**smallest subarray sum**._ A **subarray** is defined as a **non-empty** contiguous sequence of elements in an array. A **subarray sum** is the sum of all elements i...
dolphin
[ 0.010284584946930408, 0.049645718187093735, -0.0250265933573246, -0.041284870356321335, 0.05282493680715561, 0.0008944731671363115, -0.022572685033082962, 0.03432552516460419, 0.03693282604217529, 0.006336802616715431, 0.018249543383717537, 0.032171715050935745, -0.038237009197473526, -0.0...
0.83317
0.776589
0.056581
Please write the following solution using Fortran: There is an undirected tree with `n` nodes labeled from `0` to `n - 1`. You are given the integer `n` and a 2D integer array `edges` of length `n - 1`, where `edges[i] = [ai, bi]` indicates that there is an edge between nodes `ai` and `bi` in the tree. The root of the ...
dolphin
[ 0.007066653110086918, 0.020254608243703842, -0.02824637107551098, -0.024922862648963928, 0.025850581005215645, -0.02671118639409542, -0.0023055230267345905, 0.06400294601917267, 0.029172565788030624, -0.001415940816514194, 0.04326396808028221, 0.02594817988574505, -0.025511855259537697, -0...
0.846363
0.790894
0.055469
Please write the following solution using PHP: 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 ...
dolphin
[ 0.02056032605469227, 0.03887471184134483, -0.017563119530677795, -0.039133090525865555, 0.025082409381866455, -0.018444009125232697, -0.04224880412220955, 0.06263639032840729, 0.0288907028734684, -0.004372309427708387, 0.014702769927680492, 0.014034447260200977, -0.022303912788629532, -0.0...
0.835039
0.780826
0.054212
Please explain the reasoning behind the following solution and provide code in Julia: Given an integer array `nums`, return _the maximum difference between two successive elements in its sorted form_. If the array contains less than two elements, return `0`. You must write an algorithm that runs in linear time and use...
dolphin
[ 0.00684720603749156, 0.022006409242749214, -0.026683500036597252, -0.025795582681894302, 0.03685073181986809, -0.010213733650743961, -0.03835730254650116, 0.07008066773414612, 0.03871816024184227, -0.01796329766511917, 0.027700388804078102, 0.03706945851445198, -0.02867445908486843, 0.0063...
0.846625
0.787727
0.058899
Please write the following solution using Kotlin: You are climbing a staircase. It takes `n` steps to reach the top. Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top? **Example 1:** **Input:** n = 2 **Output:** 2 **Explanation:** There are two ways to climb to the t...
dolphin
[ 0.03012133575975895, 0.019941668957471848, 0.0026055050548166037, -0.03647693991661072, 0.03571103885769844, -0.0032247358467429876, -0.020294077694416046, 0.07228616625070572, 0.024497946724295616, -0.013361142948269844, 0.031101439148187637, 0.03788936883211136, -0.04625382646918297, -0....
0.839555
0.781377
0.058177
Please write the following solution using ANSI C: You are given the `root` of a **binary search tree** and an array `queries` of size `n` consisting of positive integers. Find a **2D** array `answer` of size `n` where `answer[i] = [mini, maxi]`: * `mini` is the **largest** value in the tree that is smaller than or ...
dolphin
[ 0.028861865401268005, 0.037726983428001404, -0.039345718920230865, -0.041398629546165466, 0.019193759188055992, -0.02996365912258625, -0.007532084360718727, 0.08148977160453796, 0.026282047852873802, -0.031576160341501236, 0.046847257763147354, 0.020516278222203255, -0.04832102730870247, -...
0.842797
0.788363
0.054434
Please explain the following problem in detail and provide code in Objective-C: There is a **bi-directional** graph with `n` vertices, where each vertex is labeled from `0` to `n - 1`. The edges in the graph are represented by a given 2D integer array `edges`, where `edges[i] = [ui, vi]` denotes an edge between vertex ...
dolphin
[ -0.003009401960298419, 0.021887848153710365, -0.03316693753004074, -0.02556902915239334, 0.03720684349536896, -0.03386351466178894, -0.0314420722424984, 0.06249691918492317, 0.02649683877825737, -0.01559325773268938, 0.0376458577811718, 0.001115939230658114, -0.010439971461892128, -0.01531...
0.83484
0.780328
0.054511
Please explain the following problem in detail and provide code in ANSI C: Given an integer array **sorted** in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time, return that integer. **Example 1:** **Input:** arr = \[1,2,2,6,6,6,6,7,10\] **Output:** 6 **Example 2:...
dolphin
[ 0.019468260928988457, 0.03345383331179619, -0.009170453064143658, -0.03828529268503189, 0.0270612183958292, -0.035841602832078934, -0.037367843091487885, 0.076570525765419, 0.013302001170814037, -0.009922600351274014, 0.033469438552856445, 0.013094695284962654, -0.046144478023052216, -0.01...
0.835718
0.778822
0.056896
Please write the following solution using COBOL: Given a **0-indexed** integer array `nums` of size `n` and two integers `lower` and `upper`, return _the number of fair pairs_. A pair `(i, j)` is **fair** if: * `0 <= i < j < n`, and * `lower <= nums[i] + nums[j] <= upper` **Example 1:** **Input:** nums = \[0,1,...
dolphin
[ 0.009725305251777172, 0.02552907168865204, -0.04066316783428192, -0.019796328619122505, 0.042589638382196426, 0.004375809337943792, -0.024104880169034004, 0.06962903589010239, 0.03312135115265846, -0.02440079301595688, 0.030668089166283607, 0.03494848310947418, -0.03550419956445694, -0.034...
0.854365
0.791048
0.063317
Please explain the following problem in detail and provide code in python: 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 leng...
dolphin
[ 0.014911177568137646, 0.027548888698220253, -0.04556714743375778, -0.03332075849175453, 0.056863684207201004, -0.008669178932905197, -0.03529524430632591, 0.029403727501630783, 0.03309604898095131, -0.014572756364941597, 0.026137784123420715, 0.01611419767141342, -0.02981548383831978, -0.0...
0.841421
0.787399
0.054022
Please write the following solution using Fortran: Given an integer array `arr` and an integer `difference`, return the length of the longest subsequence in `arr` which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals `difference`. A **subsequence** is a sequence t...
dolphin
[ 0.042800310999155045, 0.017193466424942017, -0.016369549557566643, -0.04646824300289154, 0.038510847836732864, -0.0201824102550745, -0.03510548174381256, 0.06517118960618973, 0.05938931182026863, -0.017514578998088837, 0.02492590621113777, 0.016307340934872627, -0.03238101676106453, 0.0011...
0.839364
0.776178
0.063186
Please write the following solution using javascript: 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 maximum number of co...
dolphin
[ 0.016437195241451263, 0.04087628796696663, -0.015968022868037224, -0.03709179162979126, 0.04393291100859642, -0.023133154958486557, -0.04094535857439041, 0.050494156777858734, 0.03671858832240105, -0.021138302981853485, 0.0320751927793026, 0.01214627455919981, -0.032192256301641464, -0.007...
0.833634
0.771297
0.062337
Please write the following solution using Scala: 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` ...
dolphin
[ 0.017769750207662582, 0.020757703110575676, -0.03071105107665062, -0.029100678861141205, 0.048718009144067764, -0.028759289532899857, -0.022596513852477074, 0.05896018445491791, 0.0361563079059124, -0.02590288780629635, 0.021680202335119247, 0.02755311317741871, -0.028521062806248665, -0.0...
0.849905
0.790104
0.059801
Please explain the reasoning behind the following solution and provide code in Kotlin: Given an array of integers `nums` and an integer `k`, return _the number of **unique** k-diff pairs in the array_. A **k-diff** pair is an integer pair `(nums[i], nums[j])`, where the following are true: * `0 <= i, j < nums.lengt...
dolphin
[ -0.0014530204934999347, 0.029436144977808, -0.019114891067147255, -0.03225564956665039, 0.05445605143904686, -0.017388269305229187, -0.02514381892979145, 0.06466983258724213, 0.04428752139210701, -0.010525129735469818, 0.01444536168128252, 0.007731403224170208, -0.020168134942650795, 0.012...
0.841093
0.783546
0.057548
Please explain the reasoning behind the following solution and provide code in ANSI C: You may recall that an array `arr` is a **mountain array** if and only if: * `arr.length >= 3` * There exists some index `i` (**0-indexed**) with `0 < i < arr.length - 1` such that: * `arr[0] < arr[1] < ... < arr[i - 1] < ...
dolphin
[ 0.023659463971853256, 0.03672347590327263, -0.027959102764725685, -0.026883676648139954, 0.03927217796444893, -0.05209880694746971, -0.0464358888566494, 0.08524422347545624, 0.040647540241479874, -0.022895218804478645, 0.013049336150288582, 0.009592073038220406, -0.04157433286309242, -0.02...
0.841752
0.785322
0.05643
Please explain the following problem in detail and provide code in Go: Given an integer array `nums` of `2n` integers, group these integers into `n` pairs `(a1, b1), (a2, b2), ..., (an, bn)` such that the sum of `min(ai, bi)` for all `i` is **maximized**. Return _the maximized sum_. **Example 1:** **Input:** nums = \...
dolphin
[ 0.005716382991522551, 0.028194058686494827, -0.031567979604005814, -0.026204174384474754, 0.04543869197368622, -0.010754140093922615, -0.02544870413839817, 0.04316700994968414, 0.04369528964161873, 0.00014289548562373966, 0.012466964311897755, 0.034076642245054245, -0.03493010625243187, -0...
0.836336
0.783104
0.053232
Please explain the following problem in detail and provide code in python: There are `m` boys and `n` girls in a class attending an upcoming party. You are given an `m x n` integer matrix `grid`, where `grid[i][j]` equals `0` or `1`. If `grid[i][j] == 1`, then that means the `ith` boy can invite the `jth` girl to the ...
dolphin
[ -0.002113098744302988, 0.026673568412661552, -0.022252816706895828, -0.04133281484246254, 0.0349869541823864, -0.05426144227385521, -0.027778448536992073, 0.034846190363168716, 0.03425399959087372, -0.00820829626172781, 0.025142846629023552, 0.039490483701229095, -0.022623570635914803, -0....
0.841512
0.785658
0.055854
Please focus on the functionality of this problem and provide code in F#: Given a binary array `nums`, return _the maximum length of a contiguous subarray with an equal number of_ `0` _and_ `1`. **Example 1:** **Input:** nums = \[0,1\] **Output:** 2 **Explanation:** \[0, 1\] is the longest contiguous subarray with an...
dolphin
[ 0.01826886273920536, 0.02344582788646221, -0.01628524251282215, -0.034447453916072845, 0.03633016347885132, -0.02590434066951275, -0.03688893839716911, 0.06219416484236717, 0.04755929857492447, -0.013528821058571339, 0.024641772732138634, 0.02936740778386593, -0.03865458443760872, -0.00747...
0.844975
0.79022
0.054754
Please focus on the efficiency of this problem and provide code in Scheme: 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 ...
dolphin
[ 0.03552679717540741, 0.02493269555270672, -0.01983911171555519, -0.022035138681530952, 0.01771608553826809, -0.03031991235911846, -0.06006356328725815, 0.026755593717098236, 0.041845981031656265, -0.028783423826098442, 0.01729959063231945, 0.02497733011841774, -0.03163257986307144, -0.0014...
0.83908
0.779049
0.060031
Please write the following solution using C#: You are given an integer array `nums`. The unique elements of an array are the elements that appear **exactly once** in the array. Return _the **sum** of all the unique elements of_ `nums`. **Example 1:** **Input:** nums = \[1,2,3,2\] **Output:** 4 **Explanation:** The u...
dolphin
[ 0.0023651858791708946, 0.023887285962700844, -0.019137272611260414, -0.02353452518582344, 0.05389324948191643, -0.02312231808900833, -0.014740429818630219, 0.06452304869890213, 0.038901831954717636, -0.0008002594113349915, 0.013639336451888084, 0.004292663652449846, -0.03858138993382454, -...
0.815037
0.745193
0.069844
Please focus on the efficiency of this problem and provide code in C#: You are given an array of strings `nums` and an integer `k`. Each string in `nums` represents an integer without leading zeros. Return _the string that represents the_ `kth` _**largest integer** in_ `nums`. **Note**: Duplicate numbers should be co...
dolphin
[ 0.03569362685084343, 0.04956762492656708, -0.03055867739021778, -0.042711131274700165, 0.03049546852707863, -0.040306877344846725, -0.02220166102051735, 0.05998796224594116, 0.03308098390698433, -0.01297367550432682, 0.0308824609965086, 0.028342436999082565, -0.04029884561896324, -0.005513...
0.844204
0.790308
0.053896
Please focus on the efficiency of this problem and provide code in javascript: 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` * `...
dolphin
[ 0.029345516115427017, 0.037325579673051834, -0.030469631776213646, -0.03243629261851311, 0.021944107487797737, -0.010529775172472, -0.02348656952381134, 0.06618205457925797, 0.0450485497713089, -0.02498422935605049, 0.034437522292137146, 0.019964206963777542, -0.04933702200651169, -0.00568...
0.848671
0.791318
0.057353
Please explain the following problem in detail and provide code in R: You are given two integers `m` and `n`. Consider an `m x n` grid where each cell is initially white. You can paint each cell **red**, **green**, or **blue**. All cells **must** be painted. Return _the number of ways to color the grid with **no two a...
dolphin
[ 0.020862916484475136, 0.023894060403108597, -0.02486233599483967, -0.03865136206150055, 0.02172836661338806, -0.0294204019010067, -0.04075299948453903, 0.06096005067229271, 0.03481944277882576, -0.024709906429052353, 0.02198198065161705, 0.031704045832157135, -0.009996707551181316, -0.0284...
0.833878
0.777481
0.056397
Please focus on the functionality of this problem and provide code in Visual Basic .NET: Given a **(0-indexed)** integer array `nums` and two integers `low` and `high`, return _the number of **nice pairs**_. A **nice pair** is a pair `(i, j)` where `0 <= i < j < nums.length` and `low <= (nums[i] XOR nums[j]) <= high`....
dolphin
[ 0.008393797092139721, 0.015401889570057392, -0.04397518187761307, -0.0026542148552834988, 0.03745941072702408, -0.01080639474093914, -0.02824135683476925, 0.06828045099973679, 0.03598516806960106, -0.007985183037817478, 0.023897456005215645, 0.029092414304614067, -0.04695937782526016, -0.0...
0.84696
0.793109
0.05385
Please write the following solution using Elixir: You are given two positive integers `n` and `k`. A factor of an integer `n` is defined as an integer `i` where `n % i == 0`. Consider a list of all factors of `n` sorted in **ascending order**, return _the_ `kth` _factor_ in this list or return `-1` if `n` has less tha...
dolphin
[ 0.042374853044748306, 0.057189200073480606, -0.021442677825689316, -0.03657600283622742, 0.026814257726073265, -0.021106528118252754, -0.01658071018755436, 0.051395054906606674, 0.03193369880318642, -0.009538366459310055, 0.019726430997252464, 0.030224572867155075, -0.040870677679777145, -...
0.838202
0.782306
0.055896
Please write the following solution using Haskell: 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.02597523294389248, 0.012198388576507568, -0.021357936784625053, -0.038171522319316864, 0.030770713463425636, -0.03751039877533913, -0.03109842538833618, 0.030137522146105766, 0.014083235524594784, -0.009657016955316067, 0.031008005142211914, 0.046502355486154556, -0.034480612725019455, -...
0.846288
0.792234
0.054054