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 Mojo:
You are given a positive integer `n`. Each digit of `n` has a sign according to the following rules:
* The **most significant digit** is assigned a **positive** sign.
* Each other digit has an opposite sign to its adjacent digits.
Return _the sum of all digits with ... | dolphin | [
0.032212018966674805,
0.008348373696208,
-0.04681464284658432,
-0.039249952882528305,
0.038139622658491135,
-0.05131281167268753,
-0.031671490520238876,
0.04991072416305542,
0.0342935286462307,
0.002684123581275344,
0.020723916590213776,
0.05047592520713806,
-0.055393654853105545,
-0.03587... | 0.842906 | 0.78411 | 0.058796 |
Please focus on the algorithm of this problem and provide code in Kotlin:
You are given an integer array `nums` and an integer `k`. Find the **largest even sum** of any subsequence of `nums` that has a length of `k`.
Return _this sum, or_ `-1` _if such a sum does not exist_.
A **subsequence** is an array that can be ... | dolphin | [
0.012047069147229195,
0.022736042737960815,
-0.016801364719867706,
-0.040221281349658966,
0.030140012502670288,
-0.01652637869119644,
-0.02062371000647545,
0.06157921254634857,
0.02903974987566471,
-0.022554911673069,
0.01907411776483059,
0.03466811776161194,
-0.03062436729669571,
0.012956... | 0.833391 | 0.776604 | 0.056788 |
Please write the following solution using Swift:
You are given `n` balloons, indexed from `0` to `n - 1`. Each balloon is painted with a number on it represented by an array `nums`. You are asked to burst all the balloons.
If you burst the `ith` balloon, you will get `nums[i - 1] * nums[i] * nums[i + 1]` coins. If `i ... | dolphin | [
0.02258084900677204,
0.04675159975886345,
-0.016210108995437622,
-0.020303599536418915,
0.0388886034488678,
-0.019675610587000847,
-0.030131634324789047,
0.056677188724279404,
0.0366814099252224,
-0.01522686704993248,
0.033922016620635986,
0.035728227347135544,
-0.03707344830036163,
-0.019... | 0.83564 | 0.780296 | 0.055344 |
Please write the following solution using Lua:
You are given an integer array `arr` of length `n` that represents a permutation of the integers in the range `[0, n - 1]`.
We split `arr` into some number of **chunks** (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equa... | dolphin | [
0.04951347038149834,
0.031767796725034714,
-0.01264045387506485,
-0.023120446130633354,
0.035298727452754974,
-0.01665639318525791,
-0.038815706968307495,
0.03013017028570175,
0.01852891407907009,
-0.01883595623075962,
0.024480972439050674,
0.017796313390135765,
-0.03623218461871147,
-0.00... | 0.849111 | 0.78953 | 0.05958 |
Please explain the following problem in detail and provide code in ANSI C:
There are `n` **piles** of coins on a table. Each pile consists of a **positive number** of coins of assorted denominations.
In one move, you can choose any coin on **top** of any pile, remove it, and add it to your wallet.
Given a list `piles... | dolphin | [
0.02418835088610649,
0.027523787692189217,
-0.02443160116672516,
-0.025097681209445,
0.019272392615675926,
-0.044965486973524094,
-0.02826649881899357,
0.05775539204478264,
0.030956190079450607,
-0.02265370823442936,
0.041837505996227264,
0.04740377143025398,
-0.032019440084695816,
-0.0065... | 0.842675 | 0.786579 | 0.056096 |
port this code from python to c++:
```python
def sum_of_mins(arr):
mod = 10**9 + 7
n = len(arr)
left, right = [0] * n, [0] * n
st = []
for i in range(n):
while st and arr[st[-1]] > arr[i]:
st.pop()
left[i] = st[-1] if st else -1
st.append(i)
st.clear()
f... | dolphin | [
0.01996992528438568,
0.023338748142123222,
-0.01453616563230753,
-0.037675511091947556,
0.027745625004172325,
-0.0006552087143063545,
-0.02477176859974861,
0.08800846338272095,
0.04303871467709541,
-0.018830547109246254,
0.025172017514705658,
0.02494553104043007,
-0.013911916874349117,
-0.... | 0.84411 | 0.778885 | 0.065225 |
Please focus on the functionality of this problem and provide code in C#:
You are given a positive integer `n` representing `n` cities numbered from `1` to `n`. You are also given a **2D** array `roads` where `roads[i] = [ai, bi, distancei]` indicates that there is a **bidirectional** road between cities `ai` and `bi` ... | dolphin | [
0.004157047253102064,
0.01801358535885811,
-0.019701946526765823,
-0.020097659900784492,
0.029459204524755478,
-0.03398977220058441,
-0.03130190819501877,
0.06920590251684189,
0.039961013942956924,
-0.011005884036421776,
0.03171001374721527,
0.03230814263224602,
-0.013171277940273285,
-0.0... | 0.843588 | 0.790098 | 0.05349 |
Please write the following solution using Scala:
Given an array of integers `arr`, a **lucky integer** is an integer that has a frequency in the array equal to its value.
Return _the largest **lucky integer** in the array_. If there is no **lucky integer** return `-1`.
**Example 1:**
**Input:** arr = \[2,2,3,4\]
**O... | dolphin | [
0.03004925139248371,
0.04757355526089668,
-0.017046073451638222,
-0.03706173226237297,
0.028046421706676483,
-0.0013175399508327246,
-0.03468484804034233,
0.038311559706926346,
0.015283339656889439,
-0.027570540085434914,
0.025656206533312798,
0.030283814296126366,
-0.014159651473164558,
-... | 0.826987 | 0.769085 | 0.057902 |
Please explain the reasoning behind the following solution and provide code in Swift:
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 tha... | dolphin | [
0.0047974600456655025,
0.04156302288174629,
-0.0140839833766222,
-0.033500172197818756,
0.060797978192567825,
-0.013719025999307632,
-0.03833480551838875,
0.06383315473794937,
0.026055552065372467,
-0.019373062998056412,
0.030933087691664696,
0.0024255551397800446,
-0.02992345206439495,
-0... | 0.843019 | 0.789123 | 0.053896 |
Please write the following solution using Object Pascal:
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 = \[3,2,3\]
**Outp... | dolphin | [
0.016944382339715958,
0.026109926402568817,
-0.034558042883872986,
-0.017371192574501038,
0.039387259632349014,
-0.025607122108340263,
-0.02054383046925068,
0.0504479855298996,
0.03192579001188278,
0.0011058987583965063,
0.024642622098326683,
0.02353806607425213,
-0.018027551472187042,
-0.... | 0.842891 | 0.781368 | 0.061523 |
Please explain the following problem in detail and provide code in PHP:
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 pa... | dolphin | [
0.015518227592110634,
0.014183060266077518,
-0.03833954781293869,
-0.01596258021891117,
0.038517117500305176,
-0.018264450132846832,
-0.03760350123047829,
0.05211693048477173,
0.034643687307834625,
-0.011184138245880604,
0.013126935809850693,
0.02303638681769371,
-0.03397444635629654,
-0.0... | 0.840788 | 0.777007 | 0.063781 |
Please explain the reasoning behind the following solution and provide code in Visual Basic .NET:
You are given a **0-indexed** integer array `arr` and an integer `k`. The array `arr` is circular. In other words, the first element of the array is the next element of the last element, and the last element of the array i... | dolphin | [
0.009844349697232246,
0.03849681466817856,
-0.03434893116354942,
-0.03781168907880783,
0.04227495938539505,
-0.02474464476108551,
-0.031223220750689507,
0.08204571157693863,
0.0399634949862957,
-0.010480593889951706,
0.025074506178498268,
0.004803949501365423,
-0.031141959130764008,
-0.009... | 0.855437 | 0.79809 | 0.057347 |
Please explain the following problem in detail and provide code in Scheme:
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'`... | dolphin | [
0.013871921226382256,
0.01797543838620186,
-0.015447876416146755,
-0.028279786929488182,
0.029192354530096054,
-0.04198877885937691,
-0.03881238400936127,
0.04561322182416916,
0.01229487918317318,
-0.003391740843653679,
0.029244471341371536,
0.053377073258161545,
-0.032010406255722046,
-0.... | 0.85286 | 0.792114 | 0.060746 |
Please focus on the algorithm of this problem and provide code in ANSI C:
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.... | dolphin | [
0.012334814295172691,
0.02697678469121456,
-0.02539336122572422,
-0.02187996543943882,
0.05020470544695854,
-0.02559947967529297,
-0.03147456422448158,
0.05483883619308472,
0.028035178780555725,
-0.006875193677842617,
0.03129490837454796,
0.037639353424310684,
-0.03902868181467056,
-0.0302... | 0.838676 | 0.785219 | 0.053457 |
Please write the following solution using Julia:
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.018380317836999893,
0.039459045976400375,
-0.014832201413810253,
-0.018987474963068962,
0.0309572946280241,
-0.024509256705641747,
-0.036658454686403275,
0.07993918657302856,
0.0434957854449749,
-0.01955604739487171,
0.023554470390081406,
0.015977568924427032,
-0.019046923145651817,
-0.0... | 0.850553 | 0.797108 | 0.053444 |
Please write the following solution using c++:
The **distance of a pair** of integers `a` and `b` is defined as the absolute difference between `a` and `b`.
Given an integer array `nums` and an integer `k`, return _the_ `kth` _smallest **distance among all the pairs**_ `nums[i]` _and_ `nums[j]` _where_ `0 <= i < j < n... | dolphin | [
0.01688629761338234,
0.033008888363838196,
-0.02580977790057659,
-0.026989329606294632,
0.058485642075538635,
-0.010516381822526455,
-0.03072487935423851,
0.07750222086906433,
0.04742918908596039,
-0.02305368334054947,
0.026178423315286636,
0.02611822448670864,
-0.010827034711837769,
0.005... | 0.841424 | 0.772362 | 0.069062 |
Please explain the reasoning behind the following solution and provide code in Mojo:
You are given an integer array `nums`. In one move, you can pick an index `i` where `0 <= i < nums.length` and increment `nums[i]` by `1`.
Return _the minimum number of moves to make every value in_ `nums` _**unique**_.
The test case... | dolphin | [
0.010654233396053314,
0.03030875138938427,
-0.009328234940767288,
-0.022947251796722412,
0.04101688042283058,
-0.02585911564528942,
-0.03324611485004425,
0.06821825355291367,
0.03296832740306854,
-0.0250669214874506,
0.036315642297267914,
0.005056838039308786,
-0.03310393542051315,
-0.0150... | 0.84803 | 0.791707 | 0.056323 |
Please focus on the efficiency of this problem and provide code in Scheme:
You are given an integer array `arr`.
We split `arr` into some number of **chunks** (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.
Return _the largest number of chunks ... | dolphin | [
0.0568038672208786,
0.029751688241958618,
-0.01728358119726181,
-0.014373069629073143,
0.015521140769124031,
-0.009754898957908154,
-0.045363761484622955,
0.025219598785042763,
0.02151106484234333,
-0.019899141043424606,
0.019652947783470154,
0.016267454251646996,
-0.026846162974834442,
0.... | 0.840036 | 0.775135 | 0.064902 |
Please write the following solution using Fortran:
Given an array `nums` of **distinct** positive integers, return _the number of tuples_ `(a, b, c, d)` _such that_ `a * b = c * d` _where_ `a`_,_ `b`_,_ `c`_, and_ `d` _are elements of_ `nums`_, and_ `a != b != c != d`_._
**Example 1:**
**Input:** nums = \[2,3,4,6\]
*... | dolphin | [
0.03399892896413803,
0.033357568085193634,
-0.026286523789167404,
-0.027185434475541115,
0.05341775715351105,
-0.02778882533311844,
-0.011854398064315319,
0.07548698037862778,
0.03589072823524475,
-0.019088294357061386,
0.01094076968729496,
0.025052594020962715,
-0.03376508131623268,
-0.03... | 0.845428 | 0.790293 | 0.055135 |
Please explain the reasoning behind the following solution and provide code in PHP:
Given a positive integer `n`, find and return _the **longest distance** between any two **adjacent**_ `1`_'s in the binary representation of_ `n`_. If there are no two adjacent_ `1`_'s, return_ `0`_._
Two `1`'s are **adjacent** if ther... | dolphin | [
0.027915451675653458,
0.033630721271038055,
-0.02801896259188652,
-0.0239593293517828,
0.03144046291708946,
-0.039389777928590775,
-0.04508611187338829,
0.06506849080324173,
0.04020961746573448,
-0.011230300180613995,
0.037355199456214905,
0.026044484227895737,
-0.04099464416503906,
0.0037... | 0.844586 | 0.787893 | 0.056693 |
Please write the following solution using javascript:
You are given an integer array `nums` of **even** length `n` and an integer `limit`. In one move, you can replace any integer from `nums` with another integer between `1` and `limit`, inclusive.
The array `nums` is **complementary** if for all indices `i` (**0-inde... | dolphin | [
0.005448292940855026,
0.03959036245942116,
-0.02086506225168705,
-0.014892710372805595,
0.028413303196430206,
-0.01968432031571865,
-0.02423500269651413,
0.05865313857793808,
0.03552989289164543,
-0.03491569310426712,
0.012168563902378082,
0.012202139012515545,
-0.04638143256306648,
-0.014... | 0.853006 | 0.798046 | 0.05496 |
Please explain the following problem in detail and provide code in ANSI C:
You are given an `m x n` integer matrix `grid`.
A **rhombus sum** is the sum of the elements that form **the** **border** of a regular rhombus shape in `grid`. The rhombus must have the shape of a square rotated 45 degrees with each of th... | dolphin | [
0.001232279115356505,
0.03244461864233017,
-0.0269802063703537,
-0.05367258936166763,
0.032020214945077896,
-0.026250755414366722,
-0.03295505419373512,
0.06952954083681107,
0.0320441909134388,
-0.01420733891427517,
0.029541920870542526,
0.03898447006940842,
-0.05440403148531914,
-0.019668... | 0.830448 | 0.776236 | 0.054212 |
Please write the following solution using ANSI C:
You are given a binary array `nums` containing only the integers `0` and `1`. Return _the number of **subarrays** in nums that have **more**_ `1`'_s than_ `0`_'s. Since the answer may be very large, return it **modulo**_ `109 + 7`.
A **subarray** is a contiguous sequen... | dolphin | [
0.017633115872740746,
0.03440782055258751,
-0.022701609879732132,
-0.019827041774988174,
0.04319659247994423,
-0.024953801184892654,
-0.050551120191812515,
0.06341029703617096,
0.027989551424980164,
-0.011851250194013119,
0.02515716478228569,
0.01823277212679386,
-0.045179396867752075,
-0.... | 0.844426 | 0.776852 | 0.067574 |
Please explain the reasoning behind the following solution and provide code in Haskell:
You are given an integer array of unique positive integers `nums`. Consider the following graph:
* There are `nums.length` nodes, labeled `nums[0]` to `nums[nums.length - 1]`,
* There is an undirected edge between `nums[i]` and... | dolphin | [
0.026319170370697975,
0.03675619512796402,
-0.02354571409523487,
-0.03024124540388584,
0.03589404746890068,
-0.012790662236511707,
-0.02221224270761013,
0.047168999910354614,
0.032963261008262634,
-0.008341881446540356,
0.025301840156316757,
0.034183744341135025,
-0.019995514303445816,
-0.... | 0.843725 | 0.785783 | 0.057941 |
Please write the following solution using Julia:
You are given a **0-indexed** integer array `nums`. A pair of indices `(i, j)` is a **bad pair** if `i < j` and `j - i != nums[j] - nums[i]`.
Return _the total number of **bad pairs** in_ `nums`.
**Example 1:**
**Input:** nums = \[4,1,3,3\]
**Output:** 5
**Explanation... | dolphin | [
0.003433610312640667,
0.008109732531011105,
-0.03892149031162262,
-0.03347093239426613,
0.05749719589948654,
-0.0023537026718258858,
-0.03487514331936836,
0.048081714659929276,
0.01805875264108181,
-0.006755004171282053,
0.003104926086962223,
0.020543083548545837,
-0.03021911531686783,
-0.... | 0.836048 | 0.775411 | 0.060637 |
Please explain the following problem in detail and provide code in C#:
Given an integer array `nums`, return _the most frequent even element_.
If there is a tie, return the **smallest** one. If there is no such element, return `-1`.
**Example 1:**
**Input:** nums = \[0,1,2,2,4,4,1\]
**Output:** 2
**Explanation:**
Th... | dolphin | [
0.01951022446155548,
0.024259433150291443,
-0.02975562959909439,
-0.028285125270485878,
0.02925008349120617,
-0.0239267498254776,
-0.022214332595467567,
0.0958387553691864,
0.038377560675144196,
-0.002398505574092269,
0.024639103561639786,
0.02490297146141529,
-0.03348255157470703,
-0.0216... | 0.840257 | 0.78088 | 0.059376 |
Please write the following solution using Elixir:
You are given an array of integers `stones` where `stones[i]` is the weight of the `ith` stone.
We are playing a game with the stones. On each turn, we choose the **heaviest two stones** and smash them together. Suppose the heaviest two stones have weights `x` and `y` ... | dolphin | [
0.048113465309143066,
0.03765157610177994,
-0.031227394938468933,
-0.04398466646671295,
0.031212346628308296,
-0.02814825437963009,
-0.03319762274622917,
0.052737489342689514,
0.033785298466682434,
-0.02498389594256878,
0.038001686334609985,
0.022227153182029724,
-0.03156755492091179,
-0.0... | 0.856437 | 0.800308 | 0.056129 |
Please write the following solution using Kotlin:
Given an integer array `nums`, your goal is to make all elements in `nums` equal. To complete one operation, follow these steps:
1. Find the **largest** value in `nums`. Let its index be `i` (**0-indexed**) and its value be `largest`. If there are multiple elements wi... | dolphin | [
0.02586638182401657,
0.018613412976264954,
-0.028432095423340797,
-0.046007685363292694,
0.031004393473267555,
-0.02303687296807766,
-0.014827055856585503,
0.058326736092567444,
0.030838698148727417,
-0.036229025572538376,
0.032453443855047226,
0.0252672266215086,
-0.033224452286958694,
-0... | 0.842783 | 0.784267 | 0.058516 |
Please write the following solution using Julia:
You are given an integer array `nums` and an integer `k`. You want to find a **subsequence** of `nums` of length `k` that has the **largest** sum.
Return _**any** such subsequence as an integer array of length_ `k`.
A **subsequence** is an array that can be derived fro... | dolphin | [
0.023105435073375702,
0.044772930443286896,
-0.025310613214969635,
-0.04803678020834923,
0.04684361070394516,
0.00023849043645896018,
-0.017906853929162025,
0.043008945882320404,
0.031572628766298294,
-0.013344140723347664,
0.03213806450366974,
0.03828750178217888,
-0.044011373072862625,
0... | 0.835984 | 0.772237 | 0.063747 |
Please focus on the efficiency of this problem and provide code in Kotlin:
The **distance of a pair** of integers `a` and `b` is defined as the absolute difference between `a` and `b`.
Given an integer array `nums` and an integer `k`, return _the_ `kth` _smallest **distance among all the pairs**_ `nums[i]` _and_ `nums... | dolphin | [
0.012242878787219524,
0.034325968474149704,
-0.026492828503251076,
-0.027562474831938744,
0.04919945076107979,
-0.01946410909295082,
-0.03235941380262375,
0.040842700749635696,
0.043163102120161057,
-0.027988780289888382,
0.024615159258246422,
0.023603633046150208,
-0.011716801673173904,
0... | 0.843531 | 0.782995 | 0.060536 |
Please focus on the functionality of this problem and provide code in PHP:
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.009279806166887283,
0.03572944924235344,
-0.035546548664569855,
-0.011735957115888596,
0.03859439492225647,
-0.031061992049217224,
-0.028349818661808968,
0.06654658913612366,
0.03140949830412865,
-0.0012479767901822925,
0.021367628127336502,
0.02158251591026783,
-0.02000322751700878,
0.0... | 0.846491 | 0.788632 | 0.057859 |
Please explain the reasoning behind the following solution and provide code in Mojo:
You are given an integer array `nums` of size `n`.
Consider a **non-empty** subarray from `nums` that has the **maximum** possible **bitwise AND**.
* In other words, let `k` be the maximum value of the bitwise AND of **any** subarr... | dolphin | [
0.02007310651242733,
0.020757479593157768,
-0.023201817646622658,
-0.021634526550769806,
0.03453781455755234,
-0.03782489895820618,
-0.044172924011945724,
0.04912375658750534,
0.037918057292699814,
-0.013016697950661182,
0.03297504782676697,
0.040664248168468475,
-0.038825009018182755,
-0.... | 0.838751 | 0.785358 | 0.053393 |
Please write the following solution using Kotlin:
You are given an integer array `nums` and an integer `k`.
In one operation, you can choose any index `i` where `0 <= i < nums.length` and change `nums[i]` to `nums[i] + x` where `x` is an integer from the range `[-k, k]`. You can apply this operation **at most once** f... | dolphin | [
0.010242557153105736,
0.023679334670305252,
-0.013890697620809078,
-0.030142920091748238,
0.04621327295899391,
-0.02891187183558941,
-0.030800214037299156,
0.06161099672317505,
0.03890807554125786,
-0.011671566404402256,
0.014214965514838696,
0.029690952971577644,
-0.028503835201263428,
0.... | 0.84503 | 0.789446 | 0.055584 |
Please write the following solution using c++:
A dieter consumes `calories[i]` calories on the `i`\-th day.
Given an integer `k`, for **every** consecutive sequence of `k` days (`calories[i], calories[i+1], ..., calories[i+k-1]` for all `0 <= i <= n-k`), they look at _T_, the total calories consumed during that sequen... | dolphin | [
0.002218583133071661,
0.023976216092705727,
-0.03227655962109566,
-0.049165915697813034,
0.030168917030096054,
-0.028584323823451996,
-0.028703749179840088,
0.10787224024534225,
0.02681785076856613,
-0.01667415164411068,
0.017829788848757744,
0.027143914252519608,
-0.04029145836830139,
0.0... | 0.836166 | 0.782857 | 0.053309 |
Please write the following solution using Dart:
Given an integer array `nums` and an integer `k`, return _the_ `kth` _largest element in the array_.
Note that it is the `kth` largest element in the sorted order, not the `kth` distinct element.
You must solve it in `O(n)` time complexity.
**Example 1:**
**Input:** n... | dolphin | [
0.03947720304131508,
0.04796123877167702,
-0.0189682450145483,
-0.04403352737426758,
0.03921457380056381,
-0.019499655812978745,
-0.02701263315975666,
0.044584255665540695,
0.03685013949871063,
-0.01752125285565853,
0.030492546036839485,
0.02759440429508686,
-0.038202036172151566,
0.000886... | 0.830734 | 0.769391 | 0.061343 |
Please explain the reasoning behind the following solution and provide code in Scheme:
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**... | dolphin | [
0.034180618822574615,
0.027017178013920784,
-0.04082934558391571,
-0.025281701236963272,
0.03541235998272896,
-0.0351695753633976,
-0.02380538545548916,
0.03677067905664444,
0.029241692274808884,
-0.011111512780189514,
0.030347730964422226,
0.015046278946101665,
-0.03444249555468559,
0.011... | 0.84776 | 0.788308 | 0.059452 |
Please explain the following problem in detail and provide code in ANSI C:
You are given an integer `n`, which indicates that there are `n` courses labeled from `1` to `n`. You are also given an array `relations` where `relations[i] = [prevCoursei, nextCoursei]`, representing a prerequisite relationship between course ... | dolphin | [
0.005863254889845848,
0.0313299298286438,
-0.03426124155521393,
-0.03726876527070999,
0.022780941799283028,
-0.00940001755952835,
-0.03442831337451935,
0.0655059739947319,
0.01905819959938526,
-0.003014140296727419,
0.026712913066148758,
0.023499568924307823,
-0.021688219159841537,
-0.0068... | 0.846186 | 0.791496 | 0.05469 |
Please explain the following problem in detail and provide code in Julia:
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.004882970824837685,
0.024541398510336876,
-0.03893977776169777,
-0.01269176509231329,
0.02554338052868843,
-0.024229412898421288,
-0.0309531819075346,
0.056812580674886703,
0.04570673406124115,
-0.0031643451657146215,
0.030442286282777786,
0.03148946166038513,
-0.03006480075418949,
0.00... | 0.851571 | 0.792491 | 0.05908 |
Please explain the reasoning behind the following solution and provide code in Swift:
You are given an integer `n`. A **0-indexed** integer array `nums` of length `n + 1` is generated in the following way:
* `nums[0] = 0`
* `nums[1] = 1`
* `nums[2 * i] = nums[i]` when `2 <= 2 * i <= n`
* `nums[2 * i + 1] = num... | dolphin | [
0.03435324877500534,
0.028196776285767555,
-0.02166120335459709,
-0.030429765582084656,
0.05019315332174301,
-0.03480351343750954,
-0.043188709765672684,
0.06066567823290825,
0.024653444066643715,
-0.016946610063314438,
0.031031809747219086,
0.0339241661131382,
-0.03963308408856392,
-0.009... | 0.843662 | 0.78937 | 0.054292 |
Please explain the following problem in detail and provide code in Haskell:
You are given a **0-indexed** `m x n` integer matrix `grid` and an integer `k`. You are currently at position `(0, 0)` and you want to reach position `(m - 1, n - 1)` moving only **down** or **right**.
Return _the number of paths where the sum... | dolphin | [
0.011292080394923687,
0.020097238942980766,
-0.011165869422256947,
-0.04468812048435211,
0.04929177835583687,
-0.04845456779003143,
-0.007101731840521097,
0.05152631551027298,
0.03586524724960327,
-0.010745489038527012,
0.022699518129229546,
0.01489610318094492,
-0.01958015374839306,
-0.02... | 0.843248 | 0.789437 | 0.053812 |
Please explain the following problem in detail and provide code in java:
We define the string `base` to be the infinite wraparound string of `"abcdefghijklmnopqrstuvwxyz "`, so `base` will look like this:
* `"...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd.... "`.
Given a string `s`, return _the number... | dolphin | [
0.01984398625791073,
0.024087367579340935,
-0.029483506456017494,
-0.015210808254778385,
0.05174306407570839,
-0.04030494764447212,
0.003176803234964609,
0.0316261425614357,
0.022793080657720566,
-0.010918989777565002,
0.02445087395608425,
0.01569249853491783,
-0.029075942933559418,
-0.028... | 0.834886 | 0.781573 | 0.053313 |
Please write the following solution using c++:
You are given a non-negative integer array `nums`. In one operation, you must:
* Choose a positive integer `x` such that `x` is less than or equal to the **smallest non-zero** element in `nums`.
* Subtract `x` from every **positive** element in `nums`.
Return _the **... | dolphin | [
0.016693783923983574,
0.01688605174422264,
-0.022448431700468063,
-0.021429697051644325,
0.04316608980298042,
-0.018803365528583527,
-0.0292076263576746,
0.09142852574586868,
0.06387961655855179,
-0.022705812007188797,
0.012373195961117744,
0.015268181450664997,
-0.01615934818983078,
-0.01... | 0.840213 | 0.777553 | 0.06266 |
Please write the following solution using Fortran:
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 `nums[i]`, you can jump to any `nums[i... | dolphin | [
0.018920449540019035,
0.028067003935575485,
-0.011109266430139542,
-0.023113537579774857,
0.04955736920237541,
-0.019031433388590813,
-0.024760475382208824,
0.06342768669128418,
0.03465145453810692,
-0.009203788824379444,
0.014200716279447079,
0.03485357016324997,
-0.024999434128403664,
-0... | 0.847721 | 0.78815 | 0.059571 |
Please explain the reasoning behind the following solution and provide code in PHP:
Given a binary array `nums` and an integer `k`, return _the maximum number of consecutive_ `1`_'s in the array if you can flip at most_ `k` `0`'s.
**Example 1:**
**Input:** nums = \[1,1,1,0,0,0,1,1,1,1,0\], k = 2
**Output:** 6
**Expla... | dolphin | [
0.0016457580495625734,
0.05255689099431038,
-0.0054649775847792625,
-0.02800973691046238,
0.03780199959874153,
-0.02593054808676243,
-0.040903735905885696,
0.06041176617145538,
0.029964284971356392,
-0.020800422877073288,
0.02531149797141552,
0.022168627008795738,
-0.029269635677337646,
0.... | 0.847139 | 0.792219 | 0.05492 |
Please write the following solution using PHP:
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 different if there is some index... | dolphin | [
0.010314707644283772,
0.048385150730609894,
-0.02309841848909855,
-0.02706144005060196,
0.044820938259363174,
-0.019348304718732834,
-0.023738132789731026,
0.07191456109285355,
0.028480395674705505,
-0.013144087046384811,
0.0196568351238966,
0.007023247890174389,
-0.040444355458021164,
-0.... | 0.838989 | 0.778123 | 0.060866 |
Please write the following solution using java:
You are given a **0-indexed** integer array `nums` of length `n`.
The **average difference** of the index `i` is the **absolute** **difference** between the average of the **first** `i + 1` elements of `nums` and the average of the **last** `n - i - 1` elements. Both ave... | dolphin | [
0.009573285467922688,
0.03744661808013916,
-0.031977806240320206,
-0.028459051623940468,
0.043541498482227325,
-0.034800946712493896,
-0.05264633521437645,
0.03753181919455528,
0.03010607324540615,
-0.025231579318642616,
0.0356866791844368,
0.005839807912707329,
-0.03879418969154358,
0.008... | 0.827231 | 0.769835 | 0.057396 |
Please write the following solution using Julia:
You are given a **0-indexed** integer array `books` of length `n` where `books[i]` denotes the number of books on the `ith` shelf of a bookshelf.
You are going to take books from a **contiguous** section of the bookshelf spanning from `l` to `r` where `0 <= l <= r < n`.... | dolphin | [
0.03725749999284744,
0.021689683198928833,
-0.043529439717531204,
-0.03656900301575661,
0.03489962965250015,
-0.024138467386364937,
-0.034520771354436874,
0.04236060008406639,
0.03834996372461319,
-0.010786952450871468,
0.013417535461485386,
0.02556435950100422,
-0.052346136420965195,
-0.0... | 0.840777 | 0.78418 | 0.056596 |
Please write the following solution using Haskell:
You are given a **0-indexed** integer array `nums`. The array `nums` is **beautiful** if:
* `nums.length` is even.
* `nums[i] != nums[i + 1]` for all `i % 2 == 0`.
Note that an empty array is considered beautiful.
You can delete any number of elements from `nums... | dolphin | [
0.026683563366532326,
0.03438233211636543,
-0.021959694102406502,
-0.03564464673399925,
0.04242677241563797,
-0.02692832425236702,
-0.030871514230966568,
0.05884035676717758,
0.04786229133605957,
-0.019242750480771065,
0.02464132197201252,
0.027224257588386536,
-0.026125911623239517,
-0.03... | 0.851672 | 0.797526 | 0.054145 |
Please focus on the algorithm of this problem and provide code in c++:
Given a string `s` and an integer `k`, return _the length of the longest substring of_ `s` _such that the frequency of each character in this substring is greater than or equal to_ `k`.
**Example 1:**
**Input:** s = "aaabb ", k = 3
**Output:** 3
... | dolphin | [
0.014919644221663475,
0.018033787608146667,
-0.01948167197406292,
-0.03746860474348068,
0.033250682055950165,
-0.024963051080703735,
-0.017988158389925957,
0.08837837725877762,
0.01099297497421503,
-0.0130317946895957,
0.035824257880449295,
0.04019061103463173,
-0.019040072336792946,
0.010... | 0.830426 | 0.773728 | 0.056698 |
Please write the following solution using Swift:
You are given an integer array `coins` (**1-indexed**) of length `n` and an integer `maxJump`. You can jump to any index `i` of the array `coins` if `coins[i] != -1` and you have to pay `coins[i]` when you visit index `i`. In addition to that, if you are currently at ind... | dolphin | [
0.011440831236541271,
0.030887169763445854,
-0.016760703176259995,
-0.01864454336464405,
0.04275776818394661,
-0.024627482518553734,
-0.024162830784916878,
0.05436976999044418,
0.030011093243956566,
-0.01967744715511799,
0.04388097673654556,
0.023813653737306595,
-0.02352106012403965,
-0.0... | 0.848385 | 0.794174 | 0.054211 |
Please explain the following problem in detail and provide code in C#:
You are given a **0-indexed** integer array `nums`. A pair of indices `(i, j)` is a **bad pair** if `i < j` and `j - i != nums[j] - nums[i]`.
Return _the total number of **bad pairs** in_ `nums`.
**Example 1:**
**Input:** nums = \[4,1,3,3\]
**Out... | dolphin | [
0.0015925312181934714,
0.007957451045513153,
-0.03667852282524109,
-0.028062092140316963,
0.050403203815221786,
-0.013420113362371922,
-0.030386416241526604,
0.08059516549110413,
0.023555921390652657,
-0.004726352635771036,
0.008260566741228104,
0.021016055718064308,
-0.036678045988082886,
... | 0.840211 | 0.781358 | 0.058854 |
Please focus on the functionality of this problem and provide code in javascript:
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:... | dolphin | [
0.014947982504963875,
0.029229212552309036,
-0.04683057218790054,
-0.012648588977754116,
0.043628815561532974,
-0.0025405744090676308,
-0.020555615425109863,
0.0385315977036953,
0.034019991755485535,
-0.008123291656374931,
0.017158495262265205,
0.03190820664167404,
-0.03417117893695831,
-0... | 0.838773 | 0.7793 | 0.059473 |
Please explain the following problem in detail and provide code in ANSI C:
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... | dolphin | [
0.00956152193248272,
0.016354268416762352,
-0.014185996726155281,
-0.034012604504823685,
0.023731663823127747,
-0.026165511459112167,
-0.034601178020238876,
0.06703963130712509,
0.018725581467151642,
0.0019460085313767195,
0.012917691841721535,
0.02744244411587715,
-0.04423756152391434,
-0... | 0.830148 | 0.77067 | 0.059478 |
Please write the following solution using Dart:
Given an array of `digits` which is sorted in **non-decreasing** order. You can write numbers using each `digits[i]` as many times as we want. For example, if `digits = ['1','3','5']`, we may write numbers such as `'13'`, `'551'`, and `'1351315'`.
Return _the number of p... | dolphin | [
-0.002247666707262397,
0.009897168725728989,
-0.016870960593223572,
-0.033684734255075455,
0.021526668220758438,
-0.03430996835231781,
-0.043176621198654175,
0.04805666580796242,
0.039475951343774796,
-0.01619567535817623,
0.022026991471648216,
0.036390796303749084,
-0.03790046647191048,
-... | 0.837099 | 0.783261 | 0.053838 |
Please focus on the functionality of this problem and provide code in ANSI C:
Given a 2D `grid` consists of `0s` (land) and `1s` (water). An _island_ is a maximal 4-directionally connected group of `0s` and a _closed island_ is an island **totally** (all left, top, right, bottom) surrounded by `1s.`
Return the number ... | dolphin | [
0.017659315839409828,
0.04195568338036537,
-0.025970173999667168,
-0.03972611203789711,
0.04559857025742531,
-0.045821789652109146,
-0.04542155563831329,
0.06209840625524521,
0.026260225102305412,
-0.01304010208696127,
0.020187679678201675,
0.01509864442050457,
-0.040868524461984634,
-0.01... | 0.84445 | 0.788986 | 0.055464 |
Please write the following solution using PHP:
You are given an integer array `nums` and an integer `k`.
In one operation, you can choose any index `i` where `0 <= i < nums.length` and change `nums[i]` to `nums[i] + x` where `x` is an integer from the range `[-k, k]`. You can apply this operation **at most once** for ... | dolphin | [
0.009063673205673695,
0.030526913702487946,
-0.017056552693247795,
-0.02161499485373497,
0.04568956419825554,
-0.03067047894001007,
-0.03349269926548004,
0.07194557785987854,
0.046030521392822266,
-0.003173390869051218,
0.018576160073280334,
0.02449561096727848,
-0.032984085381031036,
0.00... | 0.845765 | 0.79169 | 0.054076 |
Please explain the following problem in detail and provide code in ANSI C:
You are given an **even** integer `n`. You initially have a permutation `perm` of size `n` where `perm[i] == i` **(0-indexed)**.
In one operation, you will create a new array `arr`, and for each `i`:
* If `i % 2 == 0`, then `arr... | dolphin | [
0.021952833980321884,
0.03227582946419716,
-0.02031106874346733,
-0.031254954636096954,
0.015512026846408844,
-0.02814328297972679,
-0.041240621358156204,
0.08794872462749481,
0.02288207598030567,
-0.020198605954647064,
0.02760988287627697,
0.00778108648955822,
-0.0253362488001585,
-0.0250... | 0.852869 | 0.788303 | 0.064566 |
Please focus on the algorithm of this problem and provide code in java:
You are given a binary array `nums` containing only the integers `0` and `1`. Return _the number of **subarrays** in nums that have **more**_ `1`'_s than_ `0`_'s. Since the answer may be very large, return it **modulo**_ `109 + 7`.
A **subarray** ... | dolphin | [
0.010653126053512096,
0.026442648842930794,
-0.03393712639808655,
-0.003444167785346508,
0.041456907987594604,
-0.025773752480745316,
-0.042010221630334854,
0.046909984201192856,
0.01947738789021969,
-0.014259310439229012,
0.025174841284751892,
0.02087949402630329,
-0.03245944902300835,
-0... | 0.845735 | 0.779384 | 0.066351 |
Please explain the following problem in detail and provide code in Fortran:
Given a positive integer `n`, find and return _the **longest distance** between any two **adjacent**_ `1`_'s in the binary representation of_ `n`_. If there are no two adjacent_ `1`_'s, return_ `0`_._
Two `1`'s are **adjacent** if there are on... | dolphin | [
0.032240353524684906,
0.028367508202791214,
-0.024711886420845985,
-0.03717430680990219,
0.03040146641433239,
-0.03218655288219452,
-0.03199848532676697,
0.059493180364370346,
0.03884458541870117,
-0.007245134562253952,
0.033550918102264404,
0.028525952249765396,
-0.03476499766111374,
0.00... | 0.842422 | 0.785115 | 0.057306 |
Please explain the following problem in detail and provide code in Mojo:
You are given an array `nums` consisting of positive integers.
Starting with `score = 0`, apply the following algorithm:
* Choose the smallest integer of the array that is not marked. If there is a tie, choose the one with the smallest index.
... | dolphin | [
0.025997338816523552,
0.040959909558296204,
-0.024906205013394356,
-0.03323562815785408,
0.04289717972278595,
-0.017385130748152733,
-0.02602171152830124,
0.05902387574315071,
0.03150766342878342,
-0.0025899563916027546,
0.024321021512150764,
0.017609940841794014,
-0.02471773698925972,
-0.... | 0.857009 | 0.796912 | 0.060097 |
Please write the following solution using PHP:
The **frequency** of an element is the number of times it occurs in an array.
You are given an integer array `nums` and an integer `k`. In one operation, you can choose an index of `nums` and increment the element at that index by `1`.
Return _the **maximum possible freq... | dolphin | [
0.017173737287521362,
0.04467948153614998,
-0.02038058079779148,
-0.024765031412243843,
0.04084591567516327,
-0.012558928690850735,
-0.025597119703888893,
0.07984676212072372,
0.023147454485297203,
0.006987241096794605,
0.02844366244971752,
0.015287509188055992,
-0.039058931171894073,
-0.0... | 0.840041 | 0.78635 | 0.053691 |
Please focus on the functionality of this problem and provide code in Julia:
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*... | dolphin | [
0.003488396294414997,
0.024036284536123276,
-0.042662039399147034,
-0.03208024054765701,
0.04146302491426468,
-0.025109505280852318,
-0.02617679350078106,
0.0766260027885437,
0.04672938212752342,
-0.015935087576508522,
0.022371506318449974,
0.02450225129723549,
-0.03201804310083389,
-0.004... | 0.852983 | 0.797559 | 0.055424 |
Please focus on the functionality of this problem and provide code in c++:
Given the `root` of a binary tree, return _the number of **uni-value**_ _subtrees_.
A **uni-value subtree** means all nodes of the subtree have the same value.
**Example 1:**
**Input:** root = \[5,1,5,5,5,null,5\]
**Output:** 4
**Example 2:*... | dolphin | [
0.005593286361545324,
0.027629870921373367,
-0.045876260846853256,
-0.016422629356384277,
0.03458177298307419,
-0.029018301516771317,
0.005317167844623327,
0.09475378692150116,
0.02505510114133358,
-0.012166325002908707,
0.034491702914237976,
0.02112119272351265,
-0.02334478497505188,
-0.0... | 0.836532 | 0.781858 | 0.054674 |
Please write the following solution using Elixir:
You are given an `n x n` `grid` representing a field of cherries, each cell is one of three possible integers.
* `0` means the cell is empty, so you can pass through,
* `1` means the cell contains a cherry that you can pick up and pass through, or
* `-1` means th... | dolphin | [
0.020215025171637535,
0.025839390233159065,
-0.01642572693526745,
-0.043423887342214584,
0.015368985943496227,
-0.030022477731108665,
-0.025399506092071533,
0.04926014691591263,
0.016027040779590607,
-0.024196887388825417,
0.01838008500635624,
0.03369052708148956,
-0.02326793223619461,
-0.... | 0.846752 | 0.792949 | 0.053802 |
Please explain the following problem in detail and provide code in Mojo:
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 i... | dolphin | [
0.020141050219535828,
0.027493465691804886,
-0.014056938700377941,
-0.03316693380475044,
0.025389239192008972,
-0.02646268531680107,
-0.03736375272274017,
0.0645281970500946,
0.04149353876709938,
-0.02142884023487568,
0.016918856650590897,
0.017291352152824402,
-0.0410844162106514,
-0.0141... | 0.840438 | 0.780497 | 0.059941 |
Please explain the reasoning behind the following solution and provide code in c++:
An array `A` is larger than some array `B` if for the first index `i` where `A[i] != B[i]`, `A[i] > B[i]`.
For example, consider `0`\-indexing:
* `[1,3,2,4] > [1,2,2,4]`, since at index `1`, `3 > 2`.
* `[1,4,4,4] < [2,1,1,1]`, sin... | dolphin | [
0.027917280793190002,
0.043822627514600754,
-0.020947111770510674,
-0.02699435129761696,
0.033061571419239044,
-0.004555414896458387,
-0.036245595663785934,
0.09203898906707764,
0.039797428995370865,
-0.015174565836787224,
0.03163497895002365,
0.02376575395464897,
-0.03494451195001602,
0.0... | 0.83886 | 0.777841 | 0.061019 |
Please explain the reasoning behind the following solution and provide code in PHP:
The **score** of an array is defined as the **product** of its sum and its length.
* For example, the score of `[1, 2, 3, 4, 5]` is `(1 + 2 + 3 + 4 + 5) * 5 = 75`.
Given a positive integer array `nums` and an integer `k`, return _th... | dolphin | [
-0.010865653865039349,
0.03478027880191803,
-0.02062392048537731,
-0.014565786346793175,
0.05079410970211029,
-0.02391495741903782,
-0.042531173676252365,
0.060898307710886,
0.022394780069589615,
0.00736993970349431,
0.024344317615032196,
0.021921787410974503,
-0.04352613538503647,
0.00630... | 0.838601 | 0.785077 | 0.053524 |
Please explain the reasoning behind the following solution and provide code in ANSI C:
You are given an integer `n` indicating there are `n` specialty retail stores. There are `m` product types of varying amounts, which are given as a **0-indexed** integer array `quantities`, where `quantities[i]` represents the number... | dolphin | [
0.025392673909664154,
0.021594807505607605,
-0.02639981545507908,
-0.031208520755171776,
0.03392915800213814,
-0.021236436441540718,
-0.05113086849451065,
0.08052000403404236,
0.0244097039103508,
-0.019565096125006676,
0.04037955775856972,
0.046020932495594025,
-0.050253305584192276,
-0.02... | 0.838202 | 0.784192 | 0.05401 |
Please write the following solution using java:
The **appeal** of a string is the number of **distinct** characters found in the string.
* For example, the appeal of `"abbca "` is `3` because it has `3` distinct characters: `'a'`, `'b'`, and `'c'`.
Given a string `s`, return _the **total appeal of all of its **subs... | dolphin | [
0.004391278140246868,
0.017979111522436142,
-0.026696957647800446,
-0.028360363095998764,
0.03502646088600159,
-0.06299515813589096,
-0.015748681500554085,
0.021120110526680946,
0.007601117715239525,
-0.0037664256524294615,
0.03331398963928223,
0.019846169278025627,
-0.04559247940778732,
-... | 0.831057 | 0.77736 | 0.053698 |
Please explain the following problem in detail and provide code in ANSI C:
You are given a **0-indexed** integer array `nums` of length `n`.
You can perform the following operation as many times as you want:
* Pick an index `i` that you haven't picked before, and pick a prime `p` **strictly less than** `nums[i]`, t... | dolphin | [
0.01604844070971012,
0.04234170541167259,
-0.006735038012266159,
-0.024333812296390533,
0.017094360664486885,
-0.047098953276872635,
-0.009068343788385391,
0.09702057391405106,
0.03179752454161644,
-0.016255559399724007,
0.015327071771025658,
-0.005011080764234066,
-0.04479548707604408,
-0... | 0.840812 | 0.784993 | 0.055818 |
Please focus on the efficiency of this problem and provide code in Groovy:
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
**Expla... | dolphin | [
0.019502632319927216,
0.012819057330489159,
-0.01040517259389162,
-0.03386626020073891,
0.027931425720453262,
-0.02952406369149685,
-0.04968702420592308,
0.04325886443257332,
0.05337343364953995,
-0.012389483861625195,
0.03571812063455582,
0.04350470378994942,
-0.041148047894239426,
-0.028... | 0.835199 | 0.779791 | 0.055408 |
Please write the following solution using java:
A `k x k` **magic square** is a `k x k` grid filled with integers such that every row sum, every column sum, and both diagonal sums are **all equal**. The integers in the magic square **do not have to be distinct**. Every `1 x 1` grid is trivially a **magic square**.
Giv... | dolphin | [
0.01687757298350334,
0.03670429810881615,
-0.038395948708057404,
-0.07348594069480896,
0.04479498788714409,
-0.03519649803638458,
-0.03478524088859558,
0.026543842628598213,
0.02796405740082264,
-0.027137048542499542,
0.0384250245988369,
0.036312248557806015,
-0.03693661093711853,
-0.00904... | 0.827829 | 0.771627 | 0.056202 |
Please explain the following problem in detail and provide code in ANSI C:
You are given a **binary** string `s` and a positive integer `k`.
You can apply the following operation on the string **any** number of times:
* Choose any substring of size `k` from `s` and **flip** all its characters, that is, turn all `1`... | dolphin | [
0.008395851589739323,
0.04609505087137222,
-0.006665355525910854,
-0.027450477704405785,
0.032218240201473236,
-0.05106734111905098,
-0.020998209714889526,
0.07084441930055618,
0.029038693755865097,
-0.0075796376913785934,
0.03289734199643135,
0.014087109826505184,
-0.037722598761320114,
-... | 0.841805 | 0.782411 | 0.059394 |
Please focus on the efficiency of this problem and provide code in Clojure:
You are given an integer array `nums` and an integer `k`. You may partition `nums` into one or more **subsequences** such that each element in `nums` appears in **exactly** one of the subsequences.
Return _the **minimum** number of subsequence... | dolphin | [
0.0221682321280241,
0.0292679350823164,
-0.03311562538146973,
-0.013320298865437508,
0.026244543492794037,
-0.013851060532033443,
-0.027968410402536392,
0.04770061373710632,
0.03547026962041855,
-0.008774164132773876,
0.03871087729930878,
0.028528530150651932,
-0.020375775173306465,
-0.004... | 0.844576 | 0.788795 | 0.055781 |
Please write the following solution using ANSI C:
Given an integer array `nums` and an integer `k`, return _the maximum length of a_ _subarray_ _that sums to_ `k`. If there is not one, return `0` instead.
**Example 1:**
**Input:** nums = \[1,-1,5,-2,3\], k = 3
**Output:** 4
**Explanation:** The subarray \[1, -1, 5, -... | dolphin | [
0.018871568143367767,
0.036314740777015686,
-0.01810777373611927,
-0.037442103028297424,
0.041422054171562195,
-0.01594792678952217,
-0.027327245101332664,
0.051856473088264465,
0.03083697520196438,
-0.009353355504572392,
0.028795327991247177,
0.03556307405233383,
-0.03641527518630028,
0.0... | 0.837127 | 0.7668 | 0.070327 |
Please write the following solution using Clojure:
Given a non-empty array of non-negative integers `nums`, the **degree** of this array is defined as the maximum frequency of any one of its elements.
Your task is to find the smallest possible length of a (contiguous) subarray of `nums`, that has the same degree as `n... | dolphin | [
-0.0007197313825599849,
0.02818337455391884,
-0.03654085472226143,
-0.027891622856259346,
0.028401020914316177,
-0.021792691200971603,
-0.036166660487651825,
0.03851841762661934,
0.03846517577767372,
-0.013688449747860432,
0.038867268711328506,
0.019114598631858826,
-0.01862046867609024,
-... | 0.841707 | 0.787684 | 0.054023 |
Please explain the following problem in detail and provide code in R:
Given an integer `n`, return **any** array containing `n` **unique** integers such that they add up to `0`.
**Example 1:**
**Input:** n = 5
**Output:** \[-7,-1,1,3,4\]
**Explanation:** These arrays also are accepted \[-5,-1,1,2,3\] , \[-3,-1,2,-2,4... | dolphin | [
0.01369528193026781,
0.035913173109292984,
-0.022533640265464783,
-0.03500717505812645,
0.03866107016801834,
-0.028374450281262398,
-0.020825952291488647,
0.04912535846233368,
0.04153498262166977,
0.002186030615121126,
0.010912242345511913,
0.02794542722404003,
-0.03084375336766243,
-0.021... | 0.829783 | 0.771711 | 0.058072 |
Please focus on the efficiency of this problem and provide code in 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... | dolphin | [
0.01775364764034748,
0.01655849814414978,
-0.037718940526247025,
-0.040109921246767044,
0.028310904279351234,
-0.03913591429591179,
-0.0184760931879282,
0.07396642118692398,
0.04083464294672012,
-0.006965015083551407,
0.03689010813832283,
0.023677747696638107,
-0.022854862734675407,
-0.004... | 0.855731 | 0.798958 | 0.056773 |
Please write the following solution using Elixir:
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.03808144852519035,
0.03691816329956055,
-0.01994011551141739,
-0.053937092423439026,
0.01694943569600582,
-0.039839472621679306,
-0.043037425726652145,
0.04678863659501076,
0.03624443709850311,
-0.020975489169359207,
0.02423977293074131,
0.01583123579621315,
-0.029016120359301567,
-0.014... | 0.854109 | 0.792412 | 0.061696 |
Please write the following solution using Scheme:
You are given two positive integer arrays `nums` and `target`, of the same length.
In one operation, you can choose any two **distinct** indices `i` and `j` where `0 <= i, j < nums.length` and:
* set `nums[i] = nums[i] + 2` and
* set `nums[j] = nums[j] - 2`.
Two ... | dolphin | [
0.029450444504618645,
0.027462009340524673,
-0.02922249399125576,
-0.021791543811559677,
0.05429251864552498,
-0.01258459035307169,
-0.0355476550757885,
0.06842515617609024,
0.0364566445350647,
-0.015622060745954514,
0.010013357736170292,
0.0054014092311263084,
-0.030884047970175743,
-0.01... | 0.854648 | 0.790154 | 0.064494 |
Please focus on the algorithm of this problem and provide code in PHP:
An integer array is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For example, `[1,3,5,7,9]`, `[7,7,7,7]`, and `[3,-1,-5,-9]` are arithmetic sequences.
G... | dolphin | [
0.024680515751242638,
0.02022344060242176,
-0.032589420676231384,
-0.007703032344579697,
0.04207612946629524,
-0.003929289523512125,
-0.03438954800367355,
0.07534924894571304,
0.03451158106327057,
-0.00493554025888443,
0.021582582965493202,
0.018580740317702293,
-0.03317508473992348,
-0.02... | 0.837202 | 0.776517 | 0.060685 |
Please focus on the efficiency of this problem and provide code in Fortran:
Given an integer array `nums`, return _the value of the bitwise_ **OR** _of the sum of all possible **subsequences** in the array_.
A **subsequence** is a sequence that can be derived from another sequence by removing zero or more elements wit... | dolphin | [
0.0004910606076009572,
0.023291543126106262,
-0.022866113111376762,
-0.01248435489833355,
0.031393248587846756,
-0.02033645659685135,
-0.025248248130083084,
0.06482605636119843,
0.04656829312443733,
-0.0005708826938644052,
0.018497038632631302,
0.03006424754858017,
-0.037272434681653976,
-... | 0.841677 | 0.783648 | 0.058029 |
Please write the following solution using java:
There is a regular convex polygon with `n` vertices. The vertices are labeled from `0` to `n - 1` in a clockwise direction, and each vertex has **exactly one monkey**. The following figure shows a convex polygon of `6` vertices.
Each monkey moves simultaneously to a neig... | dolphin | [
0.009094617329537868,
0.036842551082372665,
-0.016110042110085487,
-0.01073223352432251,
0.027271609753370285,
-0.009230665862560272,
-0.043624863028526306,
0.04798831045627594,
0.03776555135846138,
-0.01068044826388359,
0.03084559552371502,
0.02885214053094387,
-0.022903265431523323,
-0.0... | 0.839594 | 0.778784 | 0.06081 |
Please write the following solution using Haskell:
A **wiggle sequence** is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal... | dolphin | [
0.011879464611411095,
0.00340677029453218,
-0.01405748538672924,
-0.031074339523911476,
0.04105987772345543,
-0.03119300678372383,
-0.034964561462402344,
0.05061272531747818,
0.034155234694480896,
-0.02015320211648941,
0.016414141282439232,
0.030721740797162056,
-0.027894483879208565,
-0.0... | 0.841769 | 0.785382 | 0.056388 |
Please write the following solution using PHP:
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, start = 0
**Output:** 8
**Explanatio... | dolphin | [
0.025369830429553986,
0.036136411130428314,
-0.038929715752601624,
-0.015009110793471336,
0.024824991822242737,
-0.03576352074742317,
-0.022546891123056412,
0.08420495688915253,
0.04440551996231079,
-0.011532450094819069,
0.02504761330783367,
0.023276690393686295,
-0.05758931487798691,
-0.... | 0.838145 | 0.782089 | 0.056056 |
Please write the following solution using c++:
A **path** in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence **at most once**. Note that the path does not need to pass through the root.
The **path sum** of a path... | dolphin | [
0.01791529916226864,
0.014813101850450039,
-0.034449972212314606,
-0.02072712406516075,
0.03285177797079086,
-0.023191260173916817,
-0.0015773334307596087,
0.07214555889368057,
0.040753331035375595,
-0.021441632881760597,
0.040242284536361694,
0.039047498255968094,
-0.016315259039402008,
-... | 0.831388 | 0.766905 | 0.064483 |
Please explain the reasoning behind the following solution and provide code in ANSI C:
You are given a **0-indexed** integer array `nums`. In one operation, select **any** non-negative integer `x` and an index `i`, then **update** `nums[i]` to be equal to `nums[i] AND (nums[i] XOR x)`.
Note that `AND` is the bitwise A... | dolphin | [
0.03448500484228134,
0.03211446478962898,
-0.01635117270052433,
-0.009402736090123653,
0.018105801194906235,
-0.041191451251506805,
-0.03259534761309624,
0.07151979953050613,
0.037290818989276886,
-0.02313697151839733,
0.025894714519381523,
0.02946317382156849,
-0.043335799127817154,
-0.02... | 0.836772 | 0.780271 | 0.0565 |
Please focus on the efficiency of this problem and provide code in TypeScript:
Given a binary array `nums`, return _the maximum length of a contiguous subarray with an equal number of_ `0` _and_ `1`.
**Example 1:**
**Input:** nums = \[0,1\]
**Output:** 2
**Explanation:** \[0, 1\] is the longest contiguous subarray wi... | dolphin | [
0.021729733794927597,
0.02360844984650612,
-0.021307233721017838,
-0.02763870358467102,
0.025231966748833656,
-0.019560420885682106,
-0.04215359315276146,
0.06330258399248123,
0.04493335261940956,
-0.008609404787421227,
0.0237417072057724,
0.026168083772063255,
-0.025483915582299232,
-0.00... | 0.844532 | 0.790369 | 0.054162 |
Please focus on the efficiency of this problem and provide code in Haskell:
You are given an integer array `nums`. The _value_ of this array is defined as the sum of `|nums[i] - nums[i + 1]|` for all `0 <= i < nums.length - 1`.
You are allowed to select any subarray of the given array and reverse it. You can perform t... | dolphin | [
0.02250693179666996,
0.038546498864889145,
-0.013439381495118141,
-0.018024975433945656,
0.029249142855405807,
-0.020680218935012817,
-0.026794670149683952,
0.05076253414154053,
0.04269557446241379,
-0.006962175946682692,
0.025880491361021996,
0.04039895161986351,
-0.03641479089856148,
-0.... | 0.843951 | 0.787049 | 0.056902 |
Please explain the following problem in detail and provide code in Swift:
A **square triple** `(a,b,c)` is a triple where `a`, `b`, and `c` are **integers** and `a2 + b2 = c2`.
Given an integer `n`, return _the number of **square triples** such that_ `1 <= a, b, c <= n`.
**Example 1:**
**Input:** n = 5
**Output:** 2... | dolphin | [
0.014651310630142689,
0.0342639796435833,
-0.03335100784897804,
-0.03985121473670006,
0.04631827026605606,
-0.008377735503017902,
-0.026516560465097427,
0.05527197942137718,
0.013858004473149776,
0.010259613394737244,
0.0211635734885931,
0.025159724056720734,
-0.055237092077732086,
-0.0320... | 0.828275 | 0.775012 | 0.053263 |
Please explain the following problem in detail and provide code in Elixir:
Given an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_.
**Example 1:**
**Input:** n = 20
**Output:** 1
**Explanation:** The only positive number (<= 20) with at least 1 ... | dolphin | [
0.018979044631123543,
0.008880599401891232,
-0.014957009814679623,
-0.06100378930568695,
0.019694671034812927,
-0.038188546895980835,
-0.026670226827263832,
0.03163215145468712,
0.009769540280103683,
-0.000009209861673298292,
0.03597532957792282,
0.03555004298686981,
-0.04795510321855545,
... | 0.832775 | 0.775856 | 0.056919 |
Please write the following solution using c++:
Given an integer `n`, your task is to count how many strings of length `n` can be formed under the following rules:
* Each character is a lower case vowel (`'a'`, `'e'`, `'i'`, `'o'`, `'u'`)
* Each vowel `'a'` may only be followed by an `'e'`.
* Each vowel `'e'` may... | dolphin | [
0.022390179336071014,
0.018461178988218307,
-0.0001724595931591466,
-0.03098289482295513,
0.03573451563715935,
-0.020990408957004547,
-0.024039534851908684,
0.10388866811990738,
0.028802042827010155,
-0.013639835640788078,
0.02769683487713337,
0.03633613511919975,
-0.02381707727909088,
-0.... | 0.840584 | 0.77714 | 0.063444 |
Please write the following solution using Kotlin:
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 `... | dolphin | [
0.007448237389326096,
0.020247839391231537,
-0.0029968079179525375,
-0.03150155767798424,
0.019175028428435326,
-0.031177666038274765,
-0.030220389366149902,
0.027813252061605453,
0.024855460971593857,
-0.013231768272817135,
0.0053359875455498695,
0.02549547143280506,
-0.03470868989825249,
... | 0.837192 | 0.78375 | 0.053443 |
Please focus on the efficiency of this problem and provide code in Kotlin:
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\]
**Outpu... | dolphin | [
0.0004222085699439049,
0.027678294107317924,
-0.018456878140568733,
-0.02864214964210987,
0.049290794879198074,
-0.016042187809944153,
-0.018888475373387337,
0.046811338514089584,
0.03703237324953079,
-0.006359730381518602,
0.01824807934463024,
0.012266450561583042,
-0.027488548308610916,
... | 0.829704 | 0.766578 | 0.063125 |
Please explain the reasoning behind the following solution and provide code in c++:
You are given an integer array `nums` and two integers `limit` and `goal`. The array `nums` has an interesting property that `abs(nums[i]) <= limit`.
Return _the minimum number of elements you need to add to make the sum of the array e... | dolphin | [
0.00848742201924324,
0.015264236368238926,
-0.015251190401613712,
-0.030927618965506554,
0.05427974835038185,
-0.010581685230135918,
-0.03095974773168564,
0.08149094134569168,
0.04372281953692436,
-0.020327435806393623,
0.0060742925852537155,
0.035202864557504654,
-0.03801422938704491,
-0.... | 0.840127 | 0.783828 | 0.056299 |
Please explain the following problem in detail and provide code in javascript:
Given an integer array `nums` and an integer `k`, return _the_ `kth` _largest element in the array_.
Note that it is the `kth` largest element in the sorted order, not the `kth` distinct element.
You must solve it in `O(n)` time complexity... | dolphin | [
0.0455513671040535,
0.05322656035423279,
-0.028914455324411392,
-0.03828822821378708,
0.035274915397167206,
-0.023205313831567764,
-0.01841953955590725,
0.047480057924985886,
0.035708148032426834,
-0.015960106626152992,
0.032900385558605194,
0.027414465323090553,
-0.04577447101473808,
0.00... | 0.832951 | 0.772257 | 0.060694 |
Please write the following solution using java:
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(nu... | dolphin | [
0.012917041778564453,
0.03921162337064743,
-0.02609635889530182,
-0.02616543509066105,
0.03532073274254799,
-0.032750219106674194,
-0.03377334028482437,
0.05467034876346588,
0.018432676792144775,
-0.009944422170519829,
0.027325741946697235,
0.010499397292733192,
-0.041077420115470886,
0.00... | 0.847929 | 0.789305 | 0.058625 |
Please write the following solution using C#:
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 tree ... | dolphin | [
0.0024198892060667276,
0.019025960937142372,
-0.033326275646686554,
-0.017544396221637726,
0.01600032113492489,
-0.03458845615386963,
-0.0044985320419073105,
0.080417200922966,
0.029662350192666054,
-0.002569769276306033,
0.04461774230003357,
0.018052835017442703,
-0.029789356514811516,
-0... | 0.845689 | 0.784229 | 0.06146 |
Please explain the following problem in detail and provide code in Scala:
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` _h... | dolphin | [
0.005161513574421406,
0.045027319341897964,
-0.007816299796104431,
-0.030439261347055435,
0.05307075381278992,
-0.018666628748178482,
-0.027723927050828934,
0.0546737015247345,
0.017514435574412346,
-0.017724081873893738,
0.028894906863570213,
0.011322303675115108,
-0.022871986031532288,
-... | 0.844317 | 0.786919 | 0.057398 |
Please explain the following problem in detail and provide code in ANSI C:
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.04112236201763153,
0.05311860889196396,
-0.0212814100086689,
-0.036174625158309937,
0.04178566858172417,
-0.036680757999420166,
-0.01748526655137539,
0.06145092472434044,
0.033257316797971725,
0.005054092966020107,
0.049688804894685745,
0.03594604507088661,
-0.0430716834962368,
-0.000958... | 0.825535 | 0.76326 | 0.062275 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.