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 Swift: 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 re...
dolphin
[ 0.023061638697981834, 0.02718072570860386, -0.01709379442036152, -0.027692127972841263, 0.03301921859383583, -0.017669877037405968, -0.0391751192510128, 0.06603191047906876, 0.039580054581165314, -0.022175336256623268, 0.0149520980194211, 0.015626274049282074, -0.03916009142994881, -0.0153...
0.831442
0.763725
0.067716
Please write the following solution using Scheme: Given an integer array `nums` of size `n`, return _the number with the value **closest** to_ `0` _in_ `nums`. If there are multiple answers, return _the number with the **largest** value_. **Example 1:** **Input:** nums = \[-4,-2,1,4,8\] **Output:** 1 **Explanation:**...
dolphin
[ 0.03622978925704956, 0.04337037727236748, -0.024569373577833176, -0.03027135320007801, 0.04462527111172676, -0.03169531747698784, -0.03894034028053284, 0.04110339656472206, 0.03037126176059246, -0.018192147836089134, 0.024134691804647446, 0.033744990825653076, -0.030513256788253784, -0.021...
0.832399
0.763546
0.068853
Please write the following solution using ANSI C: Given an integer `n`, return _the number of prime numbers that are strictly less than_ `n`. **Example 1:** **Input:** n = 10 **Output:** 4 **Explanation:** There are 4 prime numbers less than 10, they are 2, 3, 5, 7. **Example 2:** **Input:** n = 0 **Output:** 0 **...
dolphin
[ 0.02113836072385311, 0.03152480721473694, -0.004952362272888422, -0.0300556942820549, 0.034370724111795425, -0.0334029421210289, -0.018120964989066124, 0.05688326060771942, 0.032322730869054794, -0.006377791985869408, 0.02612145245075226, 0.02963985875248909, -0.044424958527088165, -0.0479...
0.824263
0.767936
0.056327
Please write the following solution using java: You are given an integer array `nums`. In one operation, you can replace **any** element in `nums` with **any** integer. `nums` is considered **continuous** if both of the following conditions are fulfilled: * All elements in `nums` are **unique**. * The difference ...
dolphin
[ 0.021527495235204697, 0.03635455667972565, -0.016515200957655907, -0.015046830289065838, 0.03241444379091263, -0.028708986937999725, -0.039524536579847336, 0.0715780258178711, 0.036395363509655, -0.026699231937527657, 0.028565360233187675, 0.011348424479365349, -0.021191399544477463, -0.00...
0.846005
0.785254
0.060751
Please write the following solution using c++: You are given a binary array `nums` and an integer `k`. A **k-bit flip** is choosing a **subarray** of length `k` from `nums` and simultaneously changing every `0` in the subarray to `1`, and every `1` in the subarray to `0`. Return _the minimum number of **k-bit flips**...
dolphin
[ -0.002378114266321063, 0.036815859377384186, -0.0058662849478423595, -0.02310206927359104, 0.032704081386327744, -0.012466502375900745, -0.03638019040226936, 0.08536241948604584, 0.03435066342353821, -0.018738841637969017, 0.024652903899550438, 0.0140222804620862, -0.0189795084297657, -0.0...
0.843083
0.782698
0.060385
Please explain the following problem in detail and provide code in Object Pascal: 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 elemen...
dolphin
[ -0.0059773679822683334, 0.02547471970319748, -0.01516044046729803, -0.00907199177891016, 0.0417289175093174, -0.02606717310845852, -0.015769999474287033, 0.05340650677680969, 0.05366384983062744, 0.008270790800452232, 0.02169453166425228, 0.0283491387963295, -0.035368531942367554, -0.01880...
0.837701
0.778835
0.058866
Please explain the reasoning behind the following solution and provide code in Object Pascal: You are given two **non-increasing 0-indexed** integer arrays `nums1`​​​​​​ and `nums2`​​​​​​. A pair of indices `(i, j)`, where `0 <= i < nums1.length` and `0 <= j < nums2.length`, is **valid** if both `i <= j` and `nums1[i]...
dolphin
[ 0.014823278412222862, 0.029938865453004837, -0.021409275010228157, -0.025762373581528664, 0.042057693004608154, -0.01631484366953373, -0.024392077699303627, 0.06169489771127701, 0.04180285334587097, -0.010470479726791382, 0.02980831265449524, 0.025946352630853653, -0.028210893273353577, -0...
0.850947
0.793797
0.057151
Please explain the following problem in detail and provide code in Julia: 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 diffe...
dolphin
[ -0.0001846391533035785, 0.04556570574641228, -0.028930528089404106, -0.029459988698363304, 0.04294470325112343, -0.01945713721215725, -0.020365623757243156, 0.0639064759016037, 0.030027063563466072, -0.010055424645543098, 0.017842886969447136, 0.011932636611163616, -0.03247051686048508, -0...
0.84293
0.786129
0.056802
Please write the following solution using Object Pascal: Given the array of integers `nums`, you will choose two different indices `i` and `j` of that array. _Return the maximum value of_ `(nums[i]-1)*(nums[j]-1)`. **Example 1:** **Input:** nums = \[3,4,5,2\] **Output:** 12 **Explanation:** If you choose the indices...
dolphin
[ 0.04010530561208725, 0.04993211477994919, -0.024290354922413826, -0.02342630922794342, 0.05089209973812103, -0.02997210994362831, -0.010385634377598763, 0.06025313213467598, 0.036956775933504105, -0.004862740635871887, 0.032440513372421265, 0.032951969653367996, -0.03950883820652962, -0.02...
0.842953
0.781389
0.061564
Please write the following solution using Go: You are given two **0-indexed** binary arrays `nums1` and `nums2`. Find the **widest** pair of indices `(i, j)` such that `i <= j` and `nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]`. The **widest** pair of indices is the pair with the **...
dolphin
[ 0.014647872187197208, 0.029587894678115845, -0.02063269354403019, -0.04490496590733528, 0.0419672355055809, -0.024215122684836388, -0.04446874186396599, 0.06223910674452782, 0.04673950746655464, -0.021101366728544235, 0.021745124831795692, 0.010291690938174725, -0.03080468252301216, -0.025...
0.848097
0.793503
0.054594
Please write the following solution using Visual Basic .NET: You are given a **0-indexed** string `pattern` of length `n` consisting of the characters `'I'` meaning **increasing** and `'D'` meaning **decreasing**. A **0-indexed** string `num` of length `n + 1` is created using the following conditions: * `num` cons...
dolphin
[ 0.0037177572958171368, 0.022097501903772354, -0.02287079393863678, -0.038321953266859055, 0.03631129488348961, -0.030694060027599335, -0.006852669641375542, 0.0758761391043663, 0.0332101508975029, -0.009911052882671356, 0.026756558567285538, 0.01984304003417492, -0.04353128746151924, -0.02...
0.850332
0.796696
0.053635
Please explain the following problem in detail and provide code in Julia: 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** ...
dolphin
[ 0.00010353375546401367, 0.027511443942785263, -0.028706731274724007, -0.031353920698165894, 0.05237260088324547, -0.014756151475012302, -0.01148463785648346, 0.05384240299463272, 0.04129674285650253, -0.007766899187117815, 0.021815825253725052, 0.029306115582585335, -0.041047800332307816, ...
0.845191
0.791839
0.053351
Please explain the following problem in detail and provide code in python: 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 `n - 1` elements of the array by `1`. **Example 1:** **Input:** nums = \[1,2,3\] **Outpu...
dolphin
[ 0.023744570091366768, 0.017935484647750854, -0.027328237891197205, -0.033621981739997864, 0.032864950597286224, -0.027021653950214386, -0.01822449266910553, 0.05626050382852554, 0.018338235095143318, -0.026186149567365646, 0.03391445800662041, 0.013185788877308369, -0.04355894401669502, -0...
0.85328
0.792116
0.061164
Please focus on the efficiency of this problem and provide code in java: 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.03052416443824768, 0.030063671991229057, -0.02572018653154373, -0.020098747685551643, 0.03429621458053589, -0.0158859733492136, -0.029156440868973732, 0.05111226812005043, 0.040125563740730286, -0.025509078055620193, 0.026050731539726257, 0.01586160436272621, -0.015074582770466805, -0.01...
0.845929
0.790077
0.055852
Please write the following solution using Dart: Given a binary string `s`, return the number of non-empty substrings that have the same number of `0`'s and `1`'s, and all the `0`'s and all the `1`'s in these substrings are grouped consecutively. Substrings that occur multiple times are counted the number of times they...
dolphin
[ 0.0031059505417943, 0.014117992483079433, -0.021784964948892593, -0.03739023581147194, 0.038024939596652985, -0.03268256038427353, -0.03314638510346413, 0.06398928910493851, 0.02088974229991436, -0.00855473056435585, 0.02543186955153942, 0.008354268968105316, -0.03224847838282585, -0.01879...
0.839376
0.782926
0.05645
Please explain the following problem in detail and provide code in Clojure: An array `nums` of length `n` is **beautiful** if: * `nums` is a permutation of the integers in the range `[1, n]`. * For every `0 <= i < j < n`, there is no index `k` with `i < k < j` where `2 * nums[k] == nums[i] + nums[j]`. Given the i...
dolphin
[ 0.025460567325353622, 0.04321352764964104, -0.023300228640437126, -0.03522087633609772, 0.03800332173705101, -0.0403442308306694, -0.02830994687974453, 0.04062560945749283, 0.03827890753746033, -0.007927837781608105, 0.03575083240866661, 0.04413691535592079, -0.025323254987597466, -0.02860...
0.838787
0.785061
0.053726
Please focus on the functionality of this problem and provide code in java: Given an integer array `nums`, return _the **third distinct maximum** number in this array. If the third maximum does not exist, return the **maximum** number_. **Example 1:** **Input:** nums = \[3,2,1\] **Output:** 1 **Explanation:** The fir...
dolphin
[ 0.031859684735536575, 0.031725186854600906, -0.035623613744974136, -0.016808632761240005, 0.03442852944135666, -0.025747068226337433, -0.03474384546279907, 0.04875044524669647, 0.018340956419706345, -0.015595766715705395, 0.03620006516575813, 0.020016098394989967, -0.0402822382748127, -0.0...
0.834461
0.77536
0.059101
Please explain the following problem in detail and provide code in ANSI C: Alice and Bob have an undirected graph of `n` nodes and three types of edges: * Type 1: Can be traversed by Alice only. * Type 2: Can be traversed by Bob only. * Type 3: Can be traversed by both Alice and Bob. Given an array `edges` wher...
dolphin
[ 0.02023649588227272, 0.031053727492690086, -0.022611238062381744, -0.029107356444001198, 0.023380707949399948, -0.04156753048300743, -0.01993475668132305, 0.06496624648571014, 0.03765152394771576, -0.011838437058031559, 0.02998584881424904, 0.02604932337999344, -0.01880176179111004, -0.030...
0.843212
0.787716
0.055496
Please explain the reasoning behind the following solution and provide code in C#: 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 ...
dolphin
[ 0.021575046703219414, 0.02995663695037365, -0.02230346016585827, -0.014495126903057098, 0.04150667414069176, -0.02535860799252987, -0.015709517523646355, 0.07881569862365723, 0.03860664367675781, 0.0077146426774561405, 0.019878601655364037, 0.022705992683768272, -0.017014730721712112, -0.0...
0.836971
0.780193
0.056778
Please focus on the algorithm of this problem and provide code in Object Pascal: 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 uses lin...
dolphin
[ 0.011453931219875813, 0.01880689337849617, -0.015719063580036163, -0.018348518759012222, 0.03794755041599274, -0.013224483467638493, -0.030279802158474922, 0.06960620731115341, 0.036313168704509735, -0.017107762396335602, 0.03353797644376755, 0.037774235010147095, -0.029879139736294746, 0....
0.844624
0.784036
0.060588
Please write the following solution using ANSI C: You are given an integer array `arr`. Sort the integers in the array in ascending order by the number of `1`'s in their binary representation and in case of two or more integers have the same number of `1`'s you have to sort them in ascending order. Return _the array a...
dolphin
[ 0.029716791585087776, 0.04163123294711113, -0.00621564406901598, -0.02369530126452446, 0.03709739074110985, -0.040160465985536575, -0.0401451513171196, 0.07189591974020004, 0.024304060265421867, -0.023063084110617638, 0.021611498668789864, -0.014289150014519691, -0.0475333034992218, -0.013...
0.820707
0.758452
0.062255
Please explain the following problem in detail and provide code in R: 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 other wo...
dolphin
[ 0.0038534244522452354, 0.028300564736127853, -0.02307005785405636, -0.02839680202305317, 0.0203785989433527, -0.01453736424446106, -0.026323093101382256, 0.04775247722864151, 0.03435990586876869, 0.0010782642057165504, 0.033122673630714417, 0.028282033279538155, -0.03053763508796692, -0.00...
0.833836
0.779984
0.053853
Please focus on the efficiency of this problem and provide code in Kotlin: Given an integer array `nums` and an integer `k`, return `true` _if there are two **distinct indices**_ `i` _and_ `j` _in the array such that_ `nums[i] == nums[j]` _and_ `abs(i - j) <= k`. **Example 1:** **Input:** nums = \[1,2,3,1\], k = 3 **...
dolphin
[ 0.019525468349456787, 0.02778494916856289, -0.02730746939778328, -0.01930464431643486, 0.03577062860131264, -0.02452891506254673, -0.019970716908574104, 0.0686286985874176, 0.03817948326468468, -0.027123378589749336, 0.020721087232232094, 0.02097039856016636, -0.020156217738986015, -0.0074...
0.854154
0.796073
0.058081
Please write the following solution using ANSI C: You are given a **0-indexed** integer array `nums`. You can apply the following operation any number of times: * Pick any element from `nums` and put it at the end of `nums`. The prefix sum array of `nums` is an array `prefix` of the same length as `nums` such that ...
dolphin
[ 0.012048094533383846, 0.02435912936925888, -0.014764835126698017, -0.024587590247392654, 0.023295849561691284, -0.018518317490816116, -0.02503112703561783, 0.07406382262706757, 0.03956839442253113, -0.009532597847282887, 0.007447369862347841, 0.023473704233765602, -0.031222695484757423, -0...
0.844433
0.775445
0.068988
Please write the following solution using c++: You are given an `m x n` integer matrix `grid` and an array `queries` of size `k`. Find an array `answer` of size `k` such that for each integer `queries[i]` you start in the **top left** cell of the matrix and repeat the following process: * If `queries[i]` is **stric...
dolphin
[ 0.008909220807254314, 0.02015944942831993, -0.020146336406469345, -0.042731791734695435, 0.028036270290613174, -0.02088984102010727, -0.015966521576046944, 0.09353861212730408, 0.03284377232193947, -0.014362037181854248, 0.028608184307813644, 0.03375514596700668, -0.03942177817225456, -0.0...
0.845924
0.789013
0.056912
Please write the following solution using Visual Basic .NET: You are given an integer array, `nums`, and an integer `k`. `nums` comprises of only `0`'s and `1`'s. In one move, you can choose two **adjacent** indices and swap their values. Return _the **minimum** number of moves required so that_ `nums` _has_ `k` _**co...
dolphin
[ 0.00482958322390914, 0.040205612778663635, -0.016484390944242477, -0.031344372779130936, 0.04915172979235649, -0.014979524537920952, -0.025496751070022583, 0.08202307671308517, 0.03181063011288643, -0.02400454692542553, 0.02935189940035343, 0.009915878064930439, -0.03643018752336502, -0.02...
0.849008
0.789676
0.059332
Please write the following solution using ANSI C: Given an integer array `nums` and an integer `k`, return _the number of **good** subarrays of_ `nums`. A subarray `arr` is **good** if it there are **at least** `k` pairs of indices `(i, j)` such that `i < j` and `arr[i] == arr[j]`. A **subarray** is a contiguous **no...
dolphin
[ 0.022287027910351753, 0.028448136523365974, -0.03833739459514618, -0.02657388150691986, 0.03884318843483925, -0.015338384546339512, -0.04338318109512329, 0.04859311133623123, 0.02928619459271431, -0.008470144122838974, 0.01904251053929329, 0.018220623955130577, -0.02853478491306305, -0.014...
0.841837
0.774572
0.067265
Please explain the reasoning behind the following solution and provide code in c++: You are given an array `target` that consists of **distinct** integers and another integer array `arr` that **can** have duplicates. In one operation, you can insert any integer at any position in `arr`. For example, if `arr = [1,4,1,2...
dolphin
[ 0.024552544578909874, 0.01786075346171856, -0.02020963653922081, -0.02041705511510372, 0.043861307203769684, 0.012067317962646484, -0.037748437374830246, 0.09601368755102158, 0.04728703573346138, -0.021639833226799965, 0.016913412138819695, 0.01867789588868618, -0.02157173864543438, -0.020...
0.843878
0.79001
0.053867
Please explain the reasoning behind the following solution and provide code in python: You are given a **0-indexed** array of integers `nums` of length `n`. You are initially positioned at `nums[0]`. Each element `nums[i]` represents the maximum length of a forward jump from index `i`. In other words, if you are at `n...
dolphin
[ 0.01541029755026102, 0.026780162006616592, -0.019218385219573975, -0.02095283567905426, 0.048313356935977936, -0.026223475113511086, -0.02768481895327568, 0.05231457203626633, 0.02649189531803131, -0.0059555391781032085, 0.013540578074753284, 0.03151971474289894, -0.02809859625995159, -0.0...
0.845317
0.79156
0.053756
Please focus on the efficiency of this problem and provide code in ANSI C: You are given a string `s` of length `n` where `s[i]` is either: * `'D'` means decreasing, or * `'I'` means increasing. A permutation `perm` of `n + 1` integers of all the integers in the range `[0, n]` is called a **valid permutation** if...
dolphin
[ 0.008809112012386322, 0.020632321015000343, -0.017717571929097176, -0.037845682352781296, 0.02155732922255993, -0.03789004310965538, -0.034578870981931686, 0.08498673141002655, 0.03253498673439026, -0.016464078798890114, 0.03152788057923317, 0.030140984803438187, -0.038340091705322266, -0....
0.854989
0.791207
0.063783
Please write the following solution using Dart: An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters: * `'A'`: Absent. * `'L'`: Late. * `'P'`: Present....
dolphin
[ 0.005131079349666834, 0.013818161562085152, -0.010687780566513538, -0.030191641300916672, 0.025315647944808006, -0.03571474552154541, -0.04463387280702591, 0.05086921527981758, 0.022165365517139435, -0.007462558802217245, 0.022131135687232018, 0.04872603341937065, -0.025745630264282227, -0...
0.852718
0.798543
0.054175
Please focus on the functionality of this problem and provide code in ANSI C: 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 ...
dolphin
[ 0.009593719616532326, 0.02459391951560974, -0.02225422114133835, -0.02581242099404335, 0.03113187849521637, -0.006556669250130653, -0.033280566334724426, 0.08221833407878876, 0.031371403485536575, -0.022798694670200348, 0.03083754889667034, 0.033239636570215225, -0.04904520884156227, -0.02...
0.843497
0.780758
0.062739
Please explain the reasoning behind the following solution and provide code in Kotlin: 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 i...
dolphin
[ 0.012237628921866417, 0.020570427179336548, -0.02594849467277527, -0.015494054183363914, 0.03557346761226654, -0.038371823728084564, -0.03958984836935997, 0.05343228951096535, 0.04802894964814186, -0.016490114852786064, 0.01719594933092594, 0.003951734397560358, -0.03245784714818001, -0.00...
0.84123
0.785851
0.055379
Please write the following solution using Julia: You are given two **0-indexed** binary arrays `nums1` and `nums2`. Find the **widest** pair of indices `(i, j)` such that `i <= j` and `nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]`. The **widest** pair of indices is the pair with the...
dolphin
[ 0.014321488328278065, 0.03141656890511513, -0.03583194687962532, -0.03975322097539902, 0.043604083359241486, -0.019196022301912308, -0.043777525424957275, 0.0663934051990509, 0.04202387109398842, -0.02358003705739975, 0.02415435016155243, 0.011380218900740147, -0.02558722160756588, -0.0167...
0.852037
0.791334
0.060702
Please write the following solution using Fortran: 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.0292030181735754, 0.03090508282184601, -0.02195199579000473, -0.03384247049689293, 0.026913484558463097, -0.03924105316400528, -0.015143544413149357, 0.05601208284497261, 0.041538529098033905, -0.01015616673976183, 0.012257074005901814, 0.039206139743328094, -0.021389422938227654, -0.011...
0.84769
0.790887
0.056803
Please write the following solution using Rust: Given an array of integers `nums` and an integer `k`, return _the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than_ `k`. **Example 1:** **Input:** nums = \[10,5,2,6\], k = 100 **Output:** 8 **Explanation:** The 8...
dolphin
[ 0.026137178763747215, 0.03727913647890091, -0.025615829974412918, -0.01590918004512787, 0.04714496433734894, -0.012293820269405842, -0.03234802559018135, 0.06280362606048584, 0.04728168994188309, 0.00016167796275112778, 0.009191301651299, 0.03638242557644844, -0.019076630473136902, -0.0138...
0.842273
0.787269
0.055004
Please explain the following problem in detail and provide code in Perl: Given a 2D `grid` of `0`s and `1`s, return the number of elements in the largest **square** subgrid that has all `1`s on its **border**, or `0` if such a subgrid doesn't exist in the `grid`. **Example 1:** **Input:** grid = \[\[1,1,1\],\[1,0,1\]...
dolphin
[ 0.00042726751416921616, 0.030259383842349052, -0.02338895946741104, -0.03943806514143944, 0.03337064012885094, -0.02502831257879734, -0.02168099395930767, 0.05213066190481186, 0.03228585794568062, -0.00450501125305891, 0.02452266961336136, 0.032558977603912354, -0.03176208958029747, -0.018...
0.834461
0.781144
0.053317
Please write the following solution using Elixir: You are given an integer array `nums` and an integer `k`. For each index `i` where `0 <= i < nums.length`, change `nums[i]` to be either `nums[i] + k` or `nums[i] - k`. The **score** of `nums` is the difference between the maximum and minimum elements in `nums`. Retu...
dolphin
[ 0.01701609417796135, 0.027634670957922935, -0.023313654586672783, -0.035869795829057693, 0.045384734869003296, -0.03459545969963074, -0.041089948266744614, 0.05052073299884796, 0.03544986993074417, -0.009284810163080692, 0.026777144521474838, 0.026900462806224823, -0.03254040703177452, 0.0...
0.847871
0.789939
0.057932
Please focus on the efficiency of this problem and provide code in Scala: 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 ...
dolphin
[ 0.015496260486543179, 0.013986087404191494, -0.03796745091676712, -0.01839899830520153, 0.03368842229247093, -0.02012169547379017, -0.03654035925865173, 0.04152025654911995, 0.02437715046107769, -0.02328972890973091, 0.015399925410747528, 0.026813417673110962, -0.01801544427871704, -0.0233...
0.848629
0.789688
0.058941
translate this code from ANSI C to Groovy: ```c #include <stdio.h> #define MOD 1000000007 int sum_of_mins(int arr[], int n) { int left[n], right[n]; int st[n], top = -1; for (int i = 0; i < n; i++) { while (top >= 0 && arr[st[top]] > arr[i]) { top--; } left[i] = (top >=...
dolphin
[ 0.02276657521724701, 0.027398688718676567, -0.01487253699451685, -0.03679376468062401, 0.03266218304634094, -0.021334154531359673, -0.03017638809978962, 0.03565163165330887, 0.04060078784823418, -0.02040274627506733, 0.02440924383699894, 0.026631778106093407, -0.023062946274876595, -0.0039...
0.851054
0.792749
0.058305
Please write the following solution using Swift: You have a list `arr` of all integers in the range `[1, n]` sorted in a strictly increasing order. Apply the following algorithm on `arr`: * Starting from left to right, remove the first number and every other number afterward until you reach the end of the list. * ...
dolphin
[ 0.03481815755367279, 0.0366046279668808, -0.023407522588968277, -0.04853160306811333, 0.03335259482264519, -0.03261439502239227, -0.04720989242196083, 0.051829200237989426, 0.03842907026410103, -0.02050594799220562, 0.0231777336448431, 0.010507790371775627, -0.030599646270275116, -0.012580...
0.845757
0.782632
0.063125
Please write the following solution using Erlang: 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 equal number of 0 and 1...
dolphin
[ 0.027199696749448776, 0.026240898296236992, -0.014475871808826923, -0.03873700276017189, 0.02633809670805931, -0.01632138527929783, -0.04198819026350975, 0.058490678668022156, 0.04313456267118454, -0.017071034759283066, 0.02864295057952404, 0.032867249101400375, -0.026022618636488914, 0.00...
0.837282
0.777981
0.059301
Please write the following solution using c++: There are `n` houses evenly lined up on the street, and each house is beautifully painted. You are given a **0-indexed** integer array `colors` of length `n`, where `colors[i]` represents the color of the `ith` house. Return _the **maximum** distance between **two** house...
dolphin
[ 0.006391413975507021, 0.03684920445084572, -0.01962452009320259, -0.026102697476744652, 0.028466910123825073, -0.01417748536914587, -0.04013046994805336, 0.0816706046462059, 0.040482860058546066, -0.02873682975769043, 0.03953627124428749, 0.05591311678290367, -0.015890026465058327, -0.0109...
0.838211
0.781377
0.056834
Please explain the following problem in detail and provide code in Scheme: Given the `root` of a binary tree, return the most frequent **subtree sum**. If there is a tie, return all the values with the highest frequency in any order. The **subtree sum** of a node is defined as the sum of all the node values formed by ...
dolphin
[ 0.02692108228802681, 0.028373505920171738, -0.036012426018714905, -0.020667091012001038, 0.02005394920706749, -0.029972057789564133, -0.00158417085185647, 0.03977888450026512, 0.01677808351814747, 0.008286962285637856, 0.04343961179256439, 0.022280851379036903, -0.037430111318826675, 0.015...
0.826995
0.766956
0.060039
Please write the following solution using ANSI C: You are given an integer array, `nums`, and an integer `k`. `nums` comprises of only `0`'s and `1`'s. In one move, you can choose two **adjacent** indices and swap their values. Return _the **minimum** number of moves required so that_ `nums` _has_ `k` _**consecutive**...
dolphin
[ 0.0077819423750042915, 0.04730937257409096, -0.006902619730681181, -0.03670816868543625, 0.04319761320948601, -0.01097196713089943, -0.040534477680921555, 0.083437480032444, 0.023187100887298584, -0.025305017828941345, 0.03299190476536751, 0.002434128662571311, -0.036990441381931305, -0.01...
0.843367
0.776426
0.066941
Please focus on the efficiency of this problem and provide code in Visual Basic .NET: 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 `perm...
dolphin
[ 0.01004024501889944, 0.04081439971923828, -0.03426780924201012, -0.02592100016772747, 0.03619341552257538, -0.025202833116054535, -0.012861688621342182, 0.08359918743371964, 0.03261473402380943, -0.019670013338327408, 0.02057245746254921, 0.014553909189999104, -0.04006515070796013, -0.0386...
0.844319
0.78794
0.056379
Please write the following solution using PHP: 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 t...
dolphin
[ 0.021085381507873535, 0.04125174880027771, -0.019702265039086342, -0.021486898884177208, 0.04182414337992668, -0.017284508794546127, -0.033765245229005814, 0.06672210246324539, 0.03315097838640213, -0.0009184901136904955, 0.01510788593441248, 0.010422304272651672, -0.024878855794668198, -0...
0.846236
0.787224
0.059012
Please write the following solution using Ruby: Given an integer array `nums` of size `n`, return _the number with the value **closest** to_ `0` _in_ `nums`. If there are multiple answers, return _the number with the **largest** value_. **Example 1:** **Input:** nums = \[-4,-2,1,4,8\] **Output:** 1 **Explanation:** T...
dolphin
[ 0.031487591564655304, 0.04644908383488655, -0.03027072176337242, -0.03961990028619766, 0.041295696049928665, -0.030985821038484573, -0.03157229721546173, 0.039635032415390015, 0.029652271419763565, -0.027750423178076744, 0.03128931671380997, 0.03195549175143242, -0.029813701286911964, -0.0...
0.832789
0.775751
0.057038
Please explain the following problem in detail and provide code in Swift: 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 `[...
dolphin
[ 0.0294762272387743, 0.01563471555709839, -0.028809698298573494, -0.027490004897117615, 0.04357710853219032, -0.03247011825442314, -0.031244546175003052, 0.05340315029025078, 0.0461411252617836, -0.009250523522496223, 0.029019471257925034, 0.0129817184060812, -0.027558470144867897, -0.01399...
0.841983
0.787211
0.054772
Please write the following solution using C#: You are given a **0-indexed** array `nums` of length `n`, consisting of non-negative integers. For each index `i` from `0` to `n - 1`, you must determine the size of the **minimum sized** non-empty subarray of `nums` starting at `i` (**inclusive**) that has the **maximum** ...
dolphin
[ 0.009829552844166756, 0.020655151456594467, -0.034605853259563446, -0.010375771671533585, 0.025860244408249855, -0.031383007764816284, -0.03233640640974045, 0.07611532509326935, 0.04891575872898102, -0.006102835293859243, 0.027395637705922127, 0.02445410005748272, -0.038430534303188324, -0...
0.848248
0.783074
0.065174
Please focus on the functionality of this problem and provide code in C#: 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 adjac...
dolphin
[ 0.01020091399550438, 0.022974098101258278, -0.03658217564225197, -0.028359010815620422, 0.02987956441938877, -0.014005866833031178, -0.03684685006737709, 0.08511237055063248, 0.009458390064537525, -0.006888477131724358, 0.021827664226293564, 0.03276862949132919, -0.018402250483632088, -0.0...
0.845543
0.790091
0.055452
Please write the following solution using Swift: A **self-dividing number** is a number that is divisible by every digit it contains. * For example, `128` is **a self-dividing number** because `128 % 1 == 0`, `128 % 2 == 0`, and `128 % 8 == 0`. A **self-dividing number** is not allowed to contain the digit zero. G...
dolphin
[ 0.03246677666902542, 0.030240880325436592, -0.016887500882148743, -0.04064195230603218, 0.02947106957435608, -0.02037569135427475, -0.020737510174512863, 0.0524737685918808, 0.04119369387626648, -0.01527482271194458, 0.038056571036577225, 0.012953998520970345, -0.03195235878229141, -0.0184...
0.82327
0.764839
0.058431
Please write the following solution using Elixir: You are given an integer array `nums` of length `n`. Assume `arrk` to be an array obtained by rotating `nums` by `k` positions clock-wise. We define the **rotation function** `F` on `nums` as follow: * `F(k) = 0 * arrk[0] + 1 * arrk[1] + ... + (n - 1) * arrk[n - 1]....
dolphin
[ 0.02542927674949169, 0.02183852531015873, -0.013179311528801918, -0.026150893419981003, 0.02356784977018833, -0.024250464513897896, -0.024678101763129234, 0.033506207168102264, 0.017856953665614128, -0.007884575985372066, 0.039569757878780365, 0.0353417694568634, -0.03807058185338974, -0.0...
0.85184
0.796487
0.055353
Please write the following solution using Dart: 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.02021002396941185, 0.02402888797223568, -0.015559407882392406, -0.030170807614922523, 0.019730759784579277, -0.037363242357969284, -0.026416154578328133, 0.05133100226521492, 0.04379147291183472, -0.015922188758850098, 0.01098657213151455, 0.03414753079414368, -0.019765585660934448, -0.0...
0.843071
0.787083
0.055988
Please focus on the efficiency of this problem and provide code in javascript: There is an undirected tree with `n` nodes labeled from `0` to `n - 1`. You are given a **0-indexed** integer array `nums` of length `n` where `nums[i]` represents the value of the `ith` node. You are also given a 2D integer array `edges` o...
dolphin
[ 0.01306819636374712, 0.02651362307369709, -0.03017207235097885, -0.023281902074813843, 0.034514617174863815, -0.019944405183196068, -0.006229165475815535, 0.05652759224176407, 0.03771781548857689, -0.012752990238368511, 0.040569622069597244, 0.009211769327521324, -0.02551760897040367, -0.0...
0.852629
0.798248
0.054381
Please write the following solution using Object Pascal: You are given an **even** number of people `numPeople` that stand around a circle and each person shakes hands with someone else so that there are `numPeople / 2` handshakes total. Return _the number of ways these handshakes could occur such that none of the han...
dolphin
[ 0.03466746211051941, 0.023095719516277313, -0.02849815972149372, -0.025065110996365547, 0.0345010943710804, -0.016506316140294075, -0.01933661848306656, 0.024181600660085678, 0.030261686071753502, -0.02692476473748684, 0.03347485512495041, 0.041741907596588135, -0.01992613822221756, -0.037...
0.833227
0.775838
0.057389
Please explain the following problem in detail and provide code in Kotlin: Given an integer array `nums`, return _an integer array_ `counts` _where_ `counts[i]` _is the number of smaller elements to the right of_ `nums[i]`. **Example 1:** **Input:** nums = \[5,2,6,1\] **Output:** \[2,1,1,0\] **Explanation:** To the r...
dolphin
[ 0.010284791700541973, 0.03863506764173508, -0.018715322017669678, -0.025923945009708405, 0.02844623103737831, -0.005244308151304722, -0.016087936237454414, 0.06062721088528633, 0.03245783969759941, -0.004800555761903524, 0.013774634338915348, 0.026787418872117996, -0.024906888604164124, -0...
0.841108
0.779832
0.061276
Please write the following solution using ANSI C: You are given a **0-indexed** integer array `nums` and an integer `k`. You have a **starting score** of `0`. In one **operation**: 1. choose an index `i` such that `0 <= i < nums.length`, 2. increase your **score** by `nums[i]`, and 3. replace `nums[i]` with `ceil(...
dolphin
[ 0.015731122344732285, 0.04428616166114807, -0.016562651842832565, -0.030431611463427544, 0.028817951679229736, -0.02996722422540188, -0.03953244164586067, 0.08052371442317963, 0.02146342024207115, -0.010033913888037205, 0.027277879416942596, 0.011418567970395088, -0.04853659123182297, -0.0...
0.848517
0.790249
0.058268
Please write the following solution using javascript: Given an integer array `nums` of length `n`, return `true` if there is a triplet `(i, j, k)` which satisfies the following conditions: * `0 < i, i + 1 < j, j + 1 < k < n - 1` * The sum of subarrays `(0, i - 1)`, `(i + 1, j - 1)`, `(j + 1, k - 1)` and `(k + 1, n...
dolphin
[ 0.011320650577545166, 0.02229321002960205, -0.035458363592624664, -0.028495296835899353, 0.05240307375788689, -0.013606056571006775, -0.0034213666804134846, 0.06414387375116348, 0.018233735114336014, -0.010806543752551079, 0.015549859032034874, 0.016999198123812675, -0.036025624722242355, ...
0.846096
0.790045
0.056051
Please explain the following problem in detail and provide code in java: There is a robot on an `m x n` grid. The robot is 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 down or right ...
dolphin
[ 0.009290575049817562, 0.025163738057017326, -0.019912470132112503, -0.025620408356189728, 0.02676069363951683, -0.022193992510437965, -0.032664913684129715, 0.043234750628471375, 0.03240258991718292, -0.01750657521188259, 0.025415852665901184, 0.04455376788973808, -0.02327764965593815, -0....
0.844425
0.783182
0.061243
Please explain the reasoning behind the following solution and provide code in ANSI C: Given an integer array of even length `arr`, return `true` _if it is possible to reorder_ `arr` _such that_ `arr[2 * i + 1] = 2 * arr[2 * i]` _for every_ `0 <= i < len(arr) / 2`_, or_ `false` _otherwise_. **Example 1:** **Input:** ...
dolphin
[ 0.02742067165672779, 0.032911937683820724, -0.010547383688390255, -0.04067622125148773, 0.02897173911333084, -0.03243045508861542, -0.021225951611995697, 0.09090042114257812, 0.023502523079514503, -0.025174537673592567, 0.011945778504014015, 0.007921085692942142, -0.04363137483596802, -0.0...
0.84022
0.786741
0.053479
Please explain the following problem in detail and provide code in Groovy: Given an array `nums` of size `n`, return _the majority element_. The majority element is the element that appears more than `⌊n / 2⌋` times. You may assume that the majority element always exists in the array. **Example 1:** **Input:** nums ...
dolphin
[ 0.009300462901592255, 0.02518337219953537, -0.031192880123853683, -0.023679599165916443, 0.038283780217170715, -0.036829110234975815, -0.02305757999420166, 0.04156317561864853, 0.02964412234723568, -0.008469464257359505, 0.02737676352262497, 0.028271475806832314, -0.014874005690217018, 0.0...
0.84147
0.786027
0.055443
Please explain the following problem in detail and provide code in C#: Given an integer array `nums`, return _the length of the longest **strictly increasing**_ _**subsequence**_. **Example 1:** **Input:** nums = \[10,9,2,5,3,7,101,18\] **Output:** 4 **Explanation:** The longest increasing subsequence is \[2,3,7,101\...
dolphin
[ 0.0038297735154628754, 0.03406086936593056, -0.02285935916006565, -0.025526033714413643, 0.018711596727371216, -0.031764186918735504, -0.04051218554377556, 0.08967755734920502, 0.044099289923906326, -0.014708016999065876, 0.02310309000313282, 0.00816508661955595, -0.0475459098815918, -0.00...
0.839043
0.781257
0.057786
Please write the following solution using Mojo: You are given a string `num` representing **the digits** of a very large integer and an integer `k`. You are allowed to swap any two adjacent digits of the integer **at most** `k` times. Return _the minimum integer you can obtain also as a string_. **Example 1:** **Inp...
dolphin
[ 0.020587224513292313, 0.03901439160108566, -0.013766367919743061, -0.03461321443319321, 0.03540569916367531, -0.023539742454886436, -0.02227523736655712, 0.04540371149778366, 0.029743991792201996, -0.00543175870552659, 0.030055399984121323, 0.0188294667750597, -0.026615053415298462, 0.0011...
0.841965
0.787718
0.054246
Please explain the following problem in detail and provide code in javascript: Given an integer number `n`, return the difference between the product of its digits and the sum of its digits. **Example 1:** **Input:** n = 234 **Output:** 15 **Explanation:** Product of digits = 2 \* 3 \* 4 = 24 Sum of digits = 2 + 3...
dolphin
[ 0.024127131327986717, 0.024880308657884598, -0.02997124008834362, -0.040532391518354416, 0.05121750757098198, -0.019326934590935707, -0.03672971576452255, 0.05826825648546219, 0.040038127452135086, 0.005740093532949686, 0.016249286010861397, 0.03521250933408737, -0.06267844885587692, -0.01...
0.834215
0.780255
0.05396
Please explain the reasoning behind the following solution and provide code in C#: There is a tree (i.e. a connected, undirected graph with no cycles) consisting of `n` nodes numbered from `0` to `n - 1` and exactly `n - 1` edges. You are given a **0-indexed** integer array `vals` of length `n` where `vals[i]` denotes...
dolphin
[ 0.021232234314084053, 0.012078390456736088, -0.028852909803390503, -0.02589108981192112, 0.02483414113521576, -0.039870936423540115, -0.01559689361602068, 0.08266960084438324, 0.03372904285788536, -0.007822858169674873, 0.02493426762521267, 0.009188956581056118, -0.017727846279740334, -0.0...
0.850609
0.794239
0.05637
Please write the following solution using Mojo: You are given a **0-indexed** binary string `s` and two integers `minJump` and `maxJump`. In the beginning, you are standing at index `0`, which is equal to `'0'`. You can move from index `i` to index `j` if the following conditions are fulfilled: * `i + minJump <= j <...
dolphin
[ 0.014903562143445015, 0.02679290436208248, -0.0074145118705928326, -0.034609824419021606, 0.04834463447332382, -0.040090322494506836, -0.016203882172703743, 0.07911747694015503, 0.015901032835245132, -0.003560638055205345, 0.01613820716738701, 0.018519941717386246, -0.02800794318318367, -0...
0.843044
0.789082
0.053963
Please write the following solution using Scheme: You are given two **0-indexed** binary arrays `nums1` and `nums2`. Find the **widest** pair of indices `(i, j)` such that `i <= j` and `nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]`. The **widest** pair of indices is the pair with th...
dolphin
[ 0.030583947896957397, 0.028328992426395416, -0.033574458211660385, -0.04011682793498039, 0.04585558921098709, -0.02385741099715233, -0.04553462937474251, 0.059629932045936584, 0.037307094782590866, -0.027580928057432175, 0.026274507865309715, 0.015472492203116417, -0.028084680438041687, -0...
0.852517
0.788124
0.064393
Please write the following solution using PHP: Suppose you have `n` integers labeled `1` through `n`. A permutation of those `n` integers `perm` (**1-indexed**) is considered a **beautiful arrangement** if for every `i` (`1 <= i <= n`), **either** of the following is true: * `perm[i]` is divisible by `i`. * `i` is...
dolphin
[ 0.03707009181380272, 0.044252242892980576, -0.024568971246480942, -0.037210457026958466, 0.03522839769721031, -0.026007406413555145, -0.036954645067453384, 0.06758099049329758, 0.03391876444220543, -0.004736286588013172, 0.03618469834327698, 0.011552848853170872, -0.028686918318271637, -0....
0.841885
0.780672
0.061213
Please explain the following problem in detail and provide code in Swift: You have a graph of `n` nodes. You are given an integer `n` and an array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between `ai` and `bi` in the graph. Return _the number of connected components in the graph_. **Example...
dolphin
[ 0.02722039259970188, 0.024884764105081558, -0.03307671099901199, -0.02171625941991806, 0.027190277352929115, -0.02244105190038681, -0.018298743292689323, 0.044738102704286575, 0.03282460570335388, 0.0071122907102108, 0.027958650141954422, 0.012035862542688847, -0.02002113126218319, -0.0275...
0.836953
0.774094
0.062859
Please explain the following problem in detail and provide code in Object Pascal: You are given two **0-indexed** integer arrays `nums1` and `nums2`, each of size `n`, and an integer `diff`. Find the number of **pairs** `(i, j)` such that: * `0 <= i < j <= n - 1` **and** * `nums1[i] - nums1[j] <= nums2[i] - nums2[...
dolphin
[ 0.010022344999015331, 0.018896354362368584, -0.027046112343668938, -0.030123135074973106, 0.05379267409443855, -0.004495101049542427, -0.025398440659046173, 0.05951552838087082, 0.04519857093691826, -0.0008485373109579086, 0.019049393013119698, 0.03166336566209793, -0.042382802814245224, -...
0.851647
0.791554
0.060093
Please explain the reasoning behind the following solution and provide code in PHP: 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 inte...
dolphin
[ 0.014553097076714039, 0.029021188616752625, -0.032003726810216904, -0.004324500914663076, 0.03576706349849701, -0.037876006215810776, -0.04556716978549957, 0.062309909611940384, 0.05467696487903595, -0.010179691947996616, 0.023327374830842018, 0.001981025096029043, -0.039164118468761444, -...
0.836859
0.782598
0.05426
Please explain the following problem in detail and provide code in java: You are given an integer array `nums` and an integer `k`. In one operation, you can pick two numbers from the array whose sum equals `k` and remove them from the array. Return _the maximum number of operations you can perform on the array_. **E...
dolphin
[ 0.022635824978351593, 0.03630601987242699, -0.026688696816563606, -0.028873395174741745, 0.03873356431722641, -0.01923314668238163, -0.031381361186504364, 0.050430577248334885, 0.04323691874742508, -0.009568549692630768, 0.016936063766479492, 0.020069561898708344, -0.02105151303112507, -0....
0.842381
0.77687
0.065511
Please focus on the algorithm of this problem and provide code in Scala: Given an array of integers `arr` and an integer `d`. In one step you can jump from index `i` to index: * `i + x` where: `i + x < arr.length` and `0 < x <= d`. * `i - x` where: `i - x >= 0` and `0 < x <= d`. In addition, you can only jump fro...
dolphin
[ 0.011491074226796627, 0.027134330943226814, -0.0022365772165358067, -0.012680686078965664, 0.04298301413655281, -0.03324233368039131, -0.025784634053707123, 0.044909603893756866, 0.02614440582692623, -0.021778440102934837, 0.021540571004152298, 0.028483841568231583, -0.022869179025292397, ...
0.837303
0.783991
0.053312
Please focus on the efficiency of this problem and provide code in TypeScript: Given an integer array `nums` and two integers `left` and `right`, return _the number of contiguous non-empty **subarrays** such that the value of the maximum array element in that subarray is in the range_ `[left, right]`. The test cases a...
dolphin
[ 0.03101949766278267, 0.02266680635511875, -0.03521380200982094, -0.015116660855710506, 0.020094046369194984, 0.004633740056306124, -0.03389519825577736, 0.06404777616262436, 0.037864550948143005, -0.003976799082010984, 0.029795797541737556, 0.04471380636096001, -0.025886427611112595, -0.01...
0.847951
0.790737
0.057213
Please write the following solution using Fortran: You are given an integer array `nums` of length `n` and an integer `numSlots` such that `2 * numSlots >= n`. There are `numSlots` slots numbered from `1` to `numSlots`. You have to place all `n` integers into the slots such that each slot contains at **most** two numb...
dolphin
[ 0.0047243195585906506, 0.02226218953728676, -0.031505782157182693, -0.017243042588233948, 0.03642270341515541, -0.00912108551710844, -0.0403704009950161, 0.05144091323018074, 0.02927868813276291, -0.005084492731839418, 0.018293673172593117, 0.05788235738873482, -0.04163239151239395, -0.023...
0.845506
0.788647
0.056859
Please focus on the functionality of this problem and provide code in c++: You are given a 2D `matrix` of size `m x n`, consisting of non-negative integers. You are also given an integer `k`. The **value** of coordinate `(a, b)` of the matrix is the XOR of all `matrix[i][j]` where `0 <= i <= a < m` and `0 <= j <= b < ...
dolphin
[ 0.04523543640971184, 0.038555532693862915, -0.02906344272196293, -0.03766592592000961, 0.03996100649237633, -0.023448381572961807, -0.028405658900737762, 0.08212181180715561, 0.04334573447704315, -0.016445891931653023, 0.022956354543566704, 0.02463204227387905, -0.03326907008886337, -0.002...
0.8394
0.777488
0.061912
Please write the following solution using c++: There are several stones **arranged in a row**, and each stone has an associated value which is an integer given in the array `stoneValue`. In each round of the game, Alice divides the row into **two non-empty rows** (i.e. left row and right row), then Bob calculates the ...
dolphin
[ 0.03140559047460556, 0.014111224561929703, -0.040956538170576096, -0.02668657712638378, 0.031119151040911674, -0.03079606033861637, -0.035649433732032776, 0.10200926661491394, 0.04058041051030159, -0.018926504999399185, 0.04011162742972374, 0.03928053751587868, -0.029159171506762505, -0.00...
0.836985
0.778664
0.058321
Please focus on the efficiency of this problem and provide code in python: You are given a **0-indexed** integer array `nums`. In one operation, you may do the following: * Choose **two** integers in `nums` that are **equal**. * Remove both integers from `nums`, forming a **pair**. The operation is done on `nums`...
dolphin
[ 0.02572278119623661, 0.036921966820955276, -0.038314417004585266, -0.01906283013522625, 0.027328820899128914, -0.024298686534166336, -0.03331852704286575, 0.06765347719192505, 0.042342670261859894, -0.024156685918569565, 0.016238311305642128, 0.018120262771844864, -0.024887094274163246, -0...
0.856786
0.801037
0.055749
Please write the following solution using c++: A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array `lights`. Each `lights[i] = [positioni, rangei]` indicates that there is a street lamp at position `positioni` that lights up the area ...
dolphin
[ 0.015796955674886703, 0.03810911625623703, -0.027972295880317688, -0.03306475281715393, 0.04572424665093422, -0.02846122719347477, -0.028907224535942078, 0.08948096632957458, 0.045740991830825806, -0.018030714243650436, 0.028316613286733627, 0.05082891508936882, -0.031065644696354866, -0.0...
0.838444
0.782863
0.055581
Please write the following solution using c++: You are given an integer array, `nums`, and an integer `k`. `nums` comprises of only `0`'s and `1`'s. In one move, you can choose two **adjacent** indices and swap their values. Return _the **minimum** number of moves required so that_ `nums` _has_ `k` _**consecutive**_ `...
dolphin
[ 0.007270392961800098, 0.03690127283334732, -0.007346555590629578, -0.034603919833898544, 0.04860813170671463, 0.002246794058009982, -0.040864940732717514, 0.09913402050733566, 0.025948280468583107, -0.021289298310875893, 0.030033234506845474, 0.01136285811662674, -0.026362955570220947, -0....
0.843834
0.776564
0.06727
Please write the following solution using c++: Given two arrays `arr1` and `arr2`, the elements of `arr2` are distinct, and all elements in `arr2` are also in `arr1`. Sort the elements of `arr1` such that the relative ordering of items in `arr1` are the same as in `arr2`. Elements that do not appear in `arr2` should b...
dolphin
[ 0.02034549042582512, 0.02116222307085991, -0.022368622943758965, -0.0358118861913681, 0.03230609744787216, -0.012403687462210655, -0.024577829986810684, 0.08318597078323364, 0.04562099650502205, -0.027393659576773643, 0.022095954045653343, -0.007461278233677149, -0.02334165759384632, 0.000...
0.819079
0.761595
0.057484
Please explain the reasoning behind the following solution and provide code in C#: An array `nums` of length `n` is **beautiful** if: * `nums` is a permutation of the integers in the range `[1, n]`. * For every `0 <= i < j < n`, there is no index `k` with `i < k < j` where `2 * nums[k] == nums[i] + nums[j]`. Give...
dolphin
[ 0.028735550120472908, 0.03597334399819374, -0.02427058108150959, -0.027996767312288284, 0.04034098610281944, -0.041697900742292404, -0.03388078138232231, 0.07443001121282578, 0.04168834164738655, -0.009541069157421589, 0.029726563021540642, 0.04115501791238785, -0.037604477256536484, -0.02...
0.841906
0.781993
0.059913
Please explain the reasoning behind the following solution and provide code in Haskell: 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...
dolphin
[ 0.015155378729104996, 0.023810043931007385, -0.014819038100540638, -0.02213647961616516, 0.04544110968708992, -0.017106492072343826, -0.021933699026703835, 0.04101787135004997, 0.03414139524102211, -0.012600197456777096, 0.029056517407298088, 0.04643161594867706, -0.02644677460193634, -0.0...
0.838589
0.785369
0.05322
Please explain the reasoning behind the following solution and provide code in C#: 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...
dolphin
[ 0.026520458981394768, 0.021660583093762398, -0.01953277736902237, -0.02307042106986046, 0.02514694258570671, -0.043166693300008774, -0.04893207922577858, 0.06032610684633255, 0.04307481274008751, -0.022186359390616417, 0.012886320240795612, 0.024319754913449287, -0.04306357353925705, -0.00...
0.834962
0.780368
0.054593
Please focus on the functionality of this problem and provide code in Object Pascal: The **width** of a sequence is the difference between the maximum and minimum elements in the sequence. Given an array of integers `nums`, return _the sum of the **widths** of all the non-empty **subsequences** of_ `nums`. Since the a...
dolphin
[ 0.005518925841897726, 0.020656533539295197, -0.02796396054327488, -0.020761186257004738, 0.05620303004980087, -0.007855147123336792, -0.034562524408102036, 0.04827747493982315, 0.03796139359474182, -0.004146922379732132, 0.03486630693078041, 0.04362570494413376, -0.04053791984915733, -0.01...
0.845785
0.784407
0.061378
Please write the following solution using C#: You are given an array `words` of size `n` consisting of **non-empty** strings. We define the **score** of a string `word` as the **number** of strings `words[i]` such that `word` is a **prefix** of `words[i]`. * For example, if `words = [ "a ", "ab ", "abc ", "cab "]`,...
dolphin
[ -0.0016382635803893209, 0.006824641488492489, -0.01909492164850235, -0.03898217901587486, 0.027050960808992386, -0.057823970913887024, -0.017463628202676773, 0.06808705627918243, 0.03039379231631756, -0.005332187283784151, 0.0040408773347735405, 0.014338466338813305, -0.04966844618320465, ...
0.834063
0.778785
0.055278
Please focus on the efficiency of this problem and provide code in R: You are given an array of `n` pairs `pairs` where `pairs[i] = [lefti, righti]` and `lefti < righti`. A pair `p2 = [c, d]` **follows** a pair `p1 = [a, b]` if `b < c`. A **chain** of pairs can be formed in this fashion. Return _the length longest ch...
dolphin
[ 0.0377834178507328, 0.034852322190999985, -0.03793146833777428, -0.03248009458184242, 0.01683623157441616, -0.00771919172257185, -0.040532659739255905, 0.057088837027549744, 0.018782896921038628, -0.016890425235033035, 0.00037289297324605286, 0.03787548467516899, -0.020260876044631004, -0....
0.840966
0.785987
0.054979
Please explain the following problem in detail and provide code in c++: Given an integer array `nums`, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in **any order**. You must write an algorithm tha...
dolphin
[ 0.010314666666090488, 0.0247780904173851, -0.014045348390936852, -0.024574805051088333, 0.03713689744472504, -0.0033483062870800495, -0.033325087279081345, 0.0980786606669426, 0.03604293242096901, -0.004950022790580988, 0.029168449342250824, 0.01758257858455181, -0.014484403654932976, -0.0...
0.846652
0.790746
0.055906
Please focus on the efficiency of this problem and provide code in Fortran: 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 **Expl...
dolphin
[ 0.026588933542370796, 0.01412135362625122, -0.00982036255300045, -0.03840864077210426, 0.02892923168838024, -0.02382417768239975, -0.044668711721897125, 0.05966814607381821, 0.05045240372419357, -0.005745656788349152, 0.02969740703701973, 0.04561229795217514, -0.043639566749334335, -0.0361...
0.834671
0.779398
0.055273
Please explain the following problem in detail and provide code in Dart: A sequence is **special** if it consists of a **positive** number of `0`s, followed by a **positive** number of `1`s, then a **positive** number of `2`s. * For example, `[0,1,2]` and `[0,0,1,1,1,2]` are special. * In contrast, `[2,1,0]`, `[1]...
dolphin
[ 0.0011670810636132956, 0.023827852681279182, -0.00974882859736681, -0.019676795229315758, 0.03432515263557434, -0.019646817818284035, -0.04966435953974724, 0.06118738651275635, 0.04946444183588028, -0.016222672536969185, 0.017907166853547096, 0.02992955408990383, -0.0334819033741951, -0.00...
0.851618
0.797113
0.054504
Please write the following solution using c++: There is a ball in a `maze` with empty spaces (represented as `0`) and walls (represented as `1`). The ball can go through the empty spaces by rolling **up, down, left or right**, but it won't stop rolling until hitting a wall. When the ball stops, it could choose the next...
dolphin
[ 0.01931207999587059, 0.01903468184173107, -0.018824143335223198, -0.03387776389718056, 0.05368530750274658, 0.003139380132779479, -0.04161474481225014, 0.07281623780727386, 0.044886767864227295, -0.014727171510457993, 0.0226957555860281, 0.03277309611439705, -0.005519180092960596, -0.01965...
0.833848
0.774134
0.059714
Please focus on the efficiency of this problem and provide code in Groovy: Given an integer array `nums` and an integer `k`, return the maximum sum of a **non-empty** subsequence of that array such that for every two **consecutive** integers in the subsequence, `nums[i]` and `nums[j]`, where `i < j`, the condition `j -...
dolphin
[ 0.01858464814722538, 0.026261618360877037, -0.03280897065997124, -0.02851608209311962, 0.03516938164830208, -0.008317654952406883, -0.03135212883353233, 0.04429659619927406, 0.0367320217192173, -0.017939196899533272, 0.037249188870191574, 0.043415624648332596, -0.03457900509238243, 0.02657...
0.844042
0.785346
0.058696
Please explain the reasoning behind the following solution and provide code in Mojo: There are some prizes on the **X-axis**. You are given an integer array `prizePositions` that is **sorted in non-decreasing order**, where `prizePositions[i]` is the position of the `ith` prize. There could be different prizes at the s...
dolphin
[ 0.0023083477281033993, 0.0076449899934232235, -0.03274105116724968, -0.030944954603910446, 0.022359216585755348, -0.029550980776548386, -0.03836395964026451, 0.04049983248114586, 0.03496284410357475, -0.0019343761960044503, 0.03756801411509514, 0.03535216301679611, -0.023051075637340546, 0...
0.847897
0.794212
0.053685
Please write the following solution using javascript: You are given a **directed** graph of `n` nodes numbered from `0` to `n - 1`, where each node has **at most one** outgoing edge. The graph is represented with a given **0-indexed** array `edges` of size `n`, indicating that there is a directed edge from node `i` to...
dolphin
[ 0.018718473613262177, 0.015471880324184895, -0.036718834191560745, -0.028946129605174065, 0.027498047798871994, -0.029831675812602043, -0.02163666859269142, 0.05460239201784134, 0.03203901648521423, -0.022614754736423492, 0.03429024666547775, -0.000495198997668922, -0.02718879096210003, -0...
0.836557
0.781779
0.054777
Please focus on the algorithm of this problem and provide code in Kotlin: You are given a **0-indexed** integer array `nums` of length `n`. `nums` contains a **valid split** at index `i` if the following are true: * The sum of the first `i + 1` elements is **greater than or equal to** the sum of the last `n - i - 1...
dolphin
[ 0.014576575718820095, 0.024473492056131363, -0.014608001336455345, -0.018627149984240532, 0.04017465189099312, -0.007162795402109623, -0.026608822867274284, 0.07195058465003967, 0.01761084981262684, -0.010226949118077755, 0.01691065914928913, 0.02138751745223999, -0.025469420477747917, -0....
0.84775
0.78733
0.060421
Please focus on the efficiency of this problem and provide code in Visual Basic .NET: 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.014090800657868385, 0.02424619160592556, -0.027716517448425293, -0.019094986841082573, 0.02915784902870655, -0.0161554217338562, -0.03685331344604492, 0.08538329601287842, 0.042463209480047226, -0.027549002319574356, 0.032965488731861115, 0.034822072833776474, -0.035641904920339584, -0.0...
0.846465
0.78747
0.058995
Please write the following solution using ANSI C: Given a **0-indexed** integer array `nums`, find the **leftmost** `middleIndex` (i.e., the smallest amongst all the possible ones). A `middleIndex` is an index where `nums[0] + nums[1] + ... + nums[middleIndex-1] == nums[middleIndex+1] + nums[middleIndex+2] + ... + num...
dolphin
[ 0.02035638876259327, 0.03773137927055359, -0.01728815957903862, -0.041063252836465836, 0.0318681038916111, -0.008165757171809673, -0.030458619818091393, 0.07486488670110703, 0.02789013832807541, -0.01961478404700756, 0.028266189619898796, 0.007596893236041069, -0.03927610069513321, -0.0347...
0.838937
0.779721
0.059217
Please explain the following problem in detail and provide code in c++: 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 it...
dolphin
[ 0.020124802365899086, 0.020985281094908714, -0.01582559570670128, -0.028678080067038536, 0.026842482388019562, -0.0075211310759186745, -0.03777923807501793, 0.10181348025798798, 0.043617699295282364, -0.02087472379207611, 0.01780984364449978, 0.028638146817684174, -0.033529557287693024, -0...
0.835209
0.767075
0.068135
Please write the following solution using ANSI C: Given two integer arrays `pushed` and `popped` each with distinct values, return `true` _if this could have been the result of a sequence of push and pop operations on an initially empty stack, or_ `false` _otherwise._ **Example 1:** **Input:** pushed = \[1,2,3,4,5\],...
dolphin
[ 0.03822148218750954, 0.031437527388334274, -0.00301061337813735, -0.018013818189501762, 0.02466704696416855, -0.03648265823721886, -0.006661555264145136, 0.10428201407194138, 0.028225598856806755, -0.02596711553633213, 0.005740249063819647, 0.013636802323162556, -0.00955641083419323, -0.03...
0.835772
0.781132
0.05464