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 python:
There exists an undirected and unrooted tree with `n` nodes indexed from `0` to `n - 1`. You are given an integer `n` and a 2D integer array edges of length `n - 1`, where `edges[i] = [ai, bi]` indicates that there is an edge between nodes `ai` and `bi` in the tree. You... | dolphin | [
0.014175919815897942,
0.03137413412332535,
-0.024128518998622894,
-0.028328079730272293,
0.009281830862164497,
-0.01948113739490509,
-0.013759695924818516,
0.04960602894425392,
0.009687312878668308,
-0.0009698080830276012,
0.03203076869249344,
0.015912408009171486,
-0.014685820788145065,
-... | 0.856173 | 0.790758 | 0.065415 |
Please write the following solution using Dart:
You are given an integer array `arr`.
In one move, you can select a **palindromic** subarray `arr[i], arr[i + 1], ..., arr[j]` where `i <= j`, and remove that subarray from the given array. Note that after removing a subarray, the elements on the left and on the right of... | dolphin | [
0.020752955228090286,
0.028285643085837364,
-0.029144996777176857,
-0.03656326234340668,
0.03891965374350548,
-0.020069358870387077,
-0.02973894588649273,
0.05029603838920593,
0.05397559702396393,
-0.008049078285694122,
0.018220797181129456,
0.010469072498381138,
-0.021215252578258514,
-0.... | 0.847053 | 0.786003 | 0.06105 |
Please write the following solution using Scheme:
You are given a positive integer array `grades` which represents the grades of students in a university. You would like to enter **all** these students into a competition in **ordered** non-empty groups, such that the ordering meets the following conditions:
* The su... | dolphin | [
0.018108289688825607,
0.021615687757730484,
-0.03823097422719002,
-0.045219793915748596,
0.04834962263703346,
-0.02768946997821331,
-0.045454058796167374,
0.047307707369327545,
0.013762332499027252,
-0.004876932594925165,
0.004910482093691826,
0.029316529631614685,
-0.04952361062169075,
-0... | 0.832368 | 0.772609 | 0.059759 |
Please explain the following problem in detail and provide code in Visual Basic .NET:
Given an array of integers arr, find the sum of `min(b)`, where `b` ranges over every (contiguous) subarray of `arr`. Since the answer may be large, return the answer **modulo** `109 + 7`.
**Example 1:**
**Input:** arr = \[3,1,2,4\]... | dolphin | [
0.017650902271270752,
0.01869831793010235,
-0.02544984221458435,
-0.043526604771614075,
0.048168670386075974,
-0.028963997960090637,
-0.03554600477218628,
0.05382707715034485,
0.056060079485177994,
-0.007556801196187735,
0.03305312246084213,
0.02521347627043724,
-0.04078201577067375,
-0.01... | 0.847506 | 0.783967 | 0.063539 |
Please explain the following problem in detail and provide code in c++:
Given an array `nums` of integers, a _move_ consists of choosing any element and **decreasing it by 1**.
An array `A` is a _zigzag array_ if either:
* Every even-indexed element is greater than adjacent elements, ie. `A[0] > A[1] < A[2] > A[3] ... | dolphin | [
0.02054070122539997,
0.02469092793762684,
-0.018073702231049538,
-0.023957809433341026,
0.04454071819782257,
-0.0038041595835238695,
-0.04985123500227928,
0.0785391628742218,
0.024509403854608536,
-0.00007356340938713402,
0.019361738115549088,
0.020444152876734734,
-0.040157418698072433,
-... | 0.841877 | 0.772977 | 0.0689 |
Please write the following solution using R:
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[i] = perm[i / 2]`.
* If `i ... | dolphin | [
0.023801276460289955,
0.029388906434178352,
-0.024281393736600876,
-0.03215048834681511,
0.02151424065232277,
-0.02258131094276905,
-0.039140474051237106,
0.07449045777320862,
0.028068125247955322,
-0.012480547651648521,
0.010650981217622757,
0.012045610696077347,
-0.019820386543869972,
-0... | 0.849141 | 0.790709 | 0.058432 |
Please explain the following problem in detail and provide code in C#:
You are given an integer `n` representing the length of an unknown array that you are trying to recover. You are also given an array `sums` containing the values of all `2n` **subset sums** of the unknown array (in no particular order).
Return _the... | dolphin | [
0.007864847779273987,
0.026785923168063164,
-0.03342887759208679,
-0.0330333486199379,
0.03878745064139366,
-0.03915519639849663,
-0.0135964909568429,
0.07374121248722076,
0.022767607122659683,
-0.007955171167850494,
0.020481055602431297,
0.035312470048666,
-0.03916154056787491,
-0.0224307... | 0.842624 | 0.782858 | 0.059766 |
Please write the following solution using ANSI C:
You are given a **directed** graph of `n` nodes numbered from `0` to `n - 1`, where each node has **at most one** outgoing edge.
The graph is represented with a given **0-indexed** array `edges` of size `n`, indicating that there is a directed edge from node `i` to nod... | dolphin | [
0.02099388837814331,
0.019854001700878143,
-0.025589359924197197,
-0.033784519881010056,
0.021944139152765274,
-0.03179655596613884,
-0.03317612409591675,
0.07661526650190353,
0.0288357175886631,
-0.023758938536047935,
0.03531377390027046,
0.00302914809435606,
-0.03166602551937103,
-0.0236... | 0.836777 | 0.772057 | 0.06472 |
Please focus on the efficiency of this problem and provide code in Kotlin:
Given a positive integer `num`, split it into two non-negative integers `num1` and `num2` such that:
* The concatenation of `num1` and `num2` is a permutation of `num`.
* In other words, the sum of the number of occurrences of each digi... | dolphin | [
-0.006454003509134054,
0.024439657106995583,
-0.013468587771058083,
-0.027136554941534996,
0.038991983979940414,
-0.014461413025856018,
-0.020977478474378586,
0.056550342589616776,
0.030394045636057854,
-0.017513036727905273,
0.014211365953087807,
0.03558233007788658,
-0.023958846926689148,
... | 0.843919 | 0.783957 | 0.059963 |
Please explain the reasoning behind the following solution and provide code in PHP:
You are given an integer array `nums` of length `n`, and an integer array `queries` of length `m`.
Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the **maximum** size of a **subsequence** that you can take from_ `nu... | dolphin | [
0.011862742714583874,
0.022000014781951904,
-0.030944379046559334,
-0.02558104880154133,
0.044871509075164795,
-0.006956964731216431,
-0.021081075072288513,
0.07448813319206238,
0.03148297220468521,
-0.011129318736493587,
0.02201683633029461,
0.02999655157327652,
-0.03670675307512283,
0.00... | 0.850404 | 0.792522 | 0.057882 |
Please explain the following problem in detail and provide code in ANSI C:
The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers `0` and `1` respectively. All students stand in a queue. Each student either prefers square or circular sandwiches.
The number of sandwiches in th... | dolphin | [
0.020046763122081757,
0.013161148875951767,
-0.016191892325878143,
-0.03355904668569565,
0.013600889593362808,
-0.028720030561089516,
-0.04078984260559082,
0.095674067735672,
0.02787470445036888,
-0.011102255433797836,
0.03971729427576065,
0.0198470801115036,
-0.037853170186281204,
-0.0268... | 0.841931 | 0.788552 | 0.053379 |
Please explain the reasoning behind the following solution and provide code in Groovy:
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 us... | dolphin | [
0.01319663692265749,
0.019143765792250633,
-0.021610543131828308,
-0.027952145785093307,
0.03894882649183273,
-0.016222216188907623,
-0.03876354545354843,
0.057632219046354294,
0.034986719489097595,
-0.024879930540919304,
0.032520078122615814,
0.03917817771434784,
-0.028738366439938545,
0.... | 0.844604 | 0.788203 | 0.056402 |
Please explain the following problem in detail and provide code in Elixir:
Given an array of integers `nums` and an integer `k`. A continuous subarray is called **nice** if there are `k` odd numbers on it.
Return _the number of **nice** sub-arrays_.
**Example 1:**
**Input:** nums = \[1,1,2,1,1\], k = 3
**Output:** 2... | dolphin | [
0.01192843820899725,
0.0377037338912487,
-0.029328688979148865,
-0.028829485177993774,
0.03573848679661751,
-0.019941486418247223,
-0.027918165549635887,
0.03270910307765007,
0.036943234503269196,
0.0017383263912051916,
0.0367329902946949,
0.008855652064085007,
-0.03234328329563141,
-0.013... | 0.841269 | 0.785574 | 0.055695 |
Please write the following solution using python:
Given an array of integers `nums` and an integer `limit`, return the size of the longest **non-empty** subarray such that the absolute difference between any two elements of this subarray is less than or equal to `limit`_._
**Example 1:**
**Input:** nums = \[8,2,4,7\]... | dolphin | [
0.020834937691688538,
0.027910083532333374,
-0.03157296031713486,
-0.025047695264220238,
0.021082686260342598,
-0.02802419289946556,
-0.055759649723768234,
0.03918981924653053,
0.04173178970813751,
-0.028666794300079346,
0.017071664333343506,
0.02675008960068226,
-0.030245883390307426,
0.0... | 0.840788 | 0.782254 | 0.058534 |
Please explain the following problem in detail and provide code in Julia:
You are given a **0-indexed** array `nums` consisting of **positive** integers. You can choose two indices `i` and `j`, such that `i != j`, and the sum of digits of the number `nums[i]` is equal to that of `nums[j]`.
Return _the **maximum** valu... | dolphin | [
0.0011059364769607782,
0.016743507236242294,
-0.04572894424200058,
-0.030702663585543633,
0.04972372204065323,
-0.014683128334581852,
-0.023917045444250107,
0.050299353897571564,
0.037808824330568314,
-0.003031986067071557,
0.02878785878419876,
0.03555508702993393,
-0.03803487867116928,
-0... | 0.84314 | 0.787079 | 0.056061 |
Please explain the reasoning behind the following solution and provide code in R:
You are given a positive integer **0-indexed** array `nums`.
A subset of the array `nums` is **square-free** if the product of its elements is a **square-free integer**.
A **square-free integer** is an integer that is divisible by no sq... | dolphin | [
0.02469840832054615,
0.04527962580323219,
-0.03598416596651077,
-0.03627459704875946,
0.056592606008052826,
-0.021426409482955933,
-0.031548064202070236,
0.06899555027484894,
0.048795513808727264,
-0.010234512388706207,
0.01773429848253727,
0.013986042700707912,
-0.04546312615275383,
-0.03... | 0.839976 | 0.785768 | 0.054208 |
Please explain the reasoning behind the following solution and provide code in Julia:
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 sma... | dolphin | [
0.013200195506215096,
0.04192894697189331,
-0.027279770001769066,
-0.03155345469713211,
0.04426449537277222,
-0.012124408036470413,
-0.02260381169617176,
0.06593924760818481,
0.031889766454696655,
0.002085004933178425,
0.021237902343273163,
0.025661244988441467,
-0.015547002665698528,
-0.0... | 0.854735 | 0.800028 | 0.054707 |
Please explain the reasoning behind the following solution and provide code in Object Pascal:
Given an integer array `nums` and an integer `k`, return _the number of pairs_ `(i, j)` _where_ `i < j` _such that_ `|nums[i] - nums[j]| == k`.
The value of `|x|` is defined as:
* `x` if `x >= 0`.
* `-x` if `x < 0`.
**E... | dolphin | [
0.012249551713466644,
0.031015364453196526,
-0.033387690782547,
-0.016202926635742188,
0.04066932946443558,
-0.016718676313757896,
-0.020364224910736084,
0.05644693970680237,
0.05043387785553932,
-0.013183988630771637,
0.02991955541074276,
0.022197691723704338,
-0.031907666474580765,
-0.00... | 0.851208 | 0.793995 | 0.057213 |
Please focus on the algorithm of this problem and provide code in Scheme:
You are given two integer arrays of the same length `nums1` and `nums2`. In one operation, you are allowed to swap `nums1[i]` with `nums2[i]`.
* For example, if `nums1 = [1,2,3,8]`, and `nums2 = [5,6,7,4]`, you can swap the element at `i = 3` ... | dolphin | [
0.008970986120402813,
0.03491318225860596,
-0.006610454060137272,
-0.02026493474841118,
0.02556065283715725,
-0.02135176584124565,
-0.038982946425676346,
0.07311126589775085,
0.01866910234093666,
-0.03694355487823486,
0.009633472189307213,
-0.010697388090193272,
-0.03182642534375191,
-0.00... | 0.847693 | 0.792851 | 0.054842 |
Please explain the reasoning behind the following solution and provide code in PHP:
Given an array of unique integers, `arr`, where each integer `arr[i]` is strictly greater than `1`.
We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be e... | dolphin | [
0.024150099605321884,
0.04248865321278572,
-0.022330308333039284,
-0.010827189311385155,
0.043668270111083984,
-0.04778703302145004,
-0.021809328347444534,
0.07647231221199036,
0.04023148864507675,
-0.024749713018536568,
0.02983243577182293,
0.00948081724345684,
-0.04046919196844101,
-0.01... | 0.838749 | 0.783143 | 0.055606 |
Please write the following solution using Rust:
Given an integer array `nums`, return _the number of all the **arithmetic subsequences** of_ `nums`.
A sequence of numbers is called arithmetic if it consists of **at least three elements** and if the difference between any two consecutive elements is the same.
* For ... | dolphin | [
0.031094036996364594,
0.024269962683320045,
-0.01582525297999382,
-0.03370577469468117,
0.038112491369247437,
-0.006216359790414572,
-0.022377140820026398,
0.06182277575135231,
0.05055628716945648,
-0.00516788475215435,
0.022626617923378944,
0.024114111438393593,
-0.035808488726615906,
-0.... | 0.841575 | 0.782382 | 0.059193 |
Please write the following solution using C#:
Given an array of `n` integers `nums` and an integer `target`, find the number of index triplets `i`, `j`, `k` with `0 <= i < j < k < n` that satisfy the condition `nums[i] + nums[j] + nums[k] < target`.
**Example 1:**
**Input:** nums = \[-2,0,1,3\], target = 2
**Output:*... | dolphin | [
0.01148550771176815,
0.007381190545856953,
-0.028197811916470528,
-0.023234402760863304,
0.04770425707101822,
-0.013711776584386826,
-0.03417612612247467,
0.06290144473314285,
0.02768777683377266,
0.004054337274283171,
0.014626809395849705,
0.029213421046733856,
-0.05311454087495804,
-0.04... | 0.845826 | 0.784326 | 0.0615 |
Please explain the reasoning behind the following solution and provide code in PHP:
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 condi... | dolphin | [
0.017392076551914215,
0.03116222470998764,
-0.03106694109737873,
-0.02410185895860195,
0.04608561843633652,
-0.00542043149471283,
-0.034228745847940445,
0.07095911353826523,
0.03711003065109253,
-0.00816346425563097,
0.029799308627843857,
0.03846735507249832,
-0.04758524149656296,
0.028366... | 0.842158 | 0.782371 | 0.059786 |
Please write the following solution using Objective-C:
Given an integer array `nums` and two integers `k` and `p`, return _the number of **distinct subarrays** which have **at most**_ `k` _elements divisible by_ `p`.
Two arrays `nums1` and `nums2` are said to be **distinct** if:
* They are of **different** lengths,... | dolphin | [
0.02252820134162903,
0.031142983585596085,
-0.032283395528793335,
-0.021944809705018997,
0.03780412673950195,
-0.03371284902095795,
-0.02790486440062523,
0.05999670550227165,
0.031706955283880234,
0.0011371199507266283,
0.04436221718788147,
0.018598636612296104,
-0.03580163046717644,
0.004... | 0.83894 | 0.779338 | 0.059602 |
Please write the following solution using c++:
A company is planning to interview `2n` people. Given the array `costs` where `costs[i] = [aCosti, bCosti]`, the cost of flying the `ith` person to city `a` is `aCosti`, and the cost of flying the `ith` person to city `b` is `bCosti`.
Return _the minimum cost to fly every... | dolphin | [
0.016302496194839478,
0.028459543362259865,
-0.03200055658817291,
-0.01840248331427574,
0.04289088025689125,
0.00010521564399823546,
-0.02196008712053299,
0.06304673105478287,
0.04872094839811325,
-0.015361383557319641,
0.025525063276290894,
0.04554015398025513,
-0.0063333697617053986,
-0.... | 0.841078 | 0.787314 | 0.053764 |
Please explain the following problem in detail and provide code in Elixir:
The **bitwise AND** of an array `nums` is the bitwise AND of all integers in `nums`.
* For example, for `nums = [1, 5, 3]`, the bitwise AND is equal to `1 & 5 & 3 = 1`.
* Also, for `nums = [7]`, the bitwise AND is `7`.
You are given an arr... | dolphin | [
0.015950117260217667,
0.03309506177902222,
-0.017306864261627197,
-0.028430350124835968,
0.030303174629807472,
-0.018183797597885132,
-0.02681734599173069,
0.03887828812003136,
0.02737029455602169,
-0.008767415769398212,
0.038741011172533035,
0.044291626662015915,
-0.027375802397727966,
-0... | 0.843661 | 0.788753 | 0.054908 |
Please explain the following problem in detail and provide code in ANSI C:
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 righ... | dolphin | [
0.010202012956142426,
0.030988290905952454,
-0.012042384594678879,
-0.030036775395274162,
0.023722410202026367,
-0.02015700563788414,
-0.03763190284371376,
0.07365405559539795,
0.03722772374749184,
-0.014748581685125828,
0.02531176246702671,
0.04578793793916702,
-0.0323139987885952,
-0.042... | 0.84414 | 0.781237 | 0.062902 |
Please write the following solution using C#:
Given a **0-indexed** integer array `nums` of size `n`, find the **maximum difference** between `nums[i]` and `nums[j]` (i.e., `nums[j] - nums[i]`), such that `0 <= i < j < n` and `nums[i] < nums[j]`.
Return _the **maximum difference**._ If no such `i` and `j` exists, retu... | dolphin | [
0.028577448800206184,
0.021822946146130562,
-0.025526562705636024,
-0.019336141645908356,
0.03998450189828873,
-0.03235862776637077,
-0.039361823350191116,
0.0814254954457283,
0.045110754668712616,
-0.02271365188062191,
0.032044775784015656,
0.027020230889320374,
-0.046821072697639465,
-0.... | 0.843967 | 0.781501 | 0.062466 |
Please explain the reasoning behind the following solution and provide code in python:
There is an undirected connected tree with `n` nodes labeled from `0` to `n - 1` and `n - 1` edges.
You are given the integer `n` and the array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between nodes `ai` a... | dolphin | [
0.013577098958194256,
0.02983926422894001,
-0.02861541323363781,
-0.03886750340461731,
0.03654336929321289,
-0.037156615406274796,
-0.01939176581799984,
0.04259258136153221,
0.025473682209849358,
0.015593328513205051,
0.038329463452100754,
0.02221856452524662,
-0.03969213739037514,
0.01057... | 0.842507 | 0.787872 | 0.054634 |
Please write the following solution using Scheme:
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:**... | dolphin | [
0.05381627380847931,
0.048075415194034576,
-0.024228781461715698,
-0.038543105125427246,
0.039192862808704376,
-0.026204219087958336,
-0.025249546393752098,
0.04207846149802208,
0.03567452356219292,
-0.016883816570043564,
0.034504011273384094,
0.027145884931087494,
-0.04182552918791771,
-0... | 0.827273 | 0.758135 | 0.069138 |
Please write the following solution using Swift:
Given an integer array `nums`, return _the **maximum possible sum** of elements of the array such that it is divisible by three_.
**Example 1:**
**Input:** nums = \[3,6,5,1,8\]
**Output:** 18
**Explanation:** Pick numbers 3, 6, 1 and 8 their sum is 18 (maximum sum divi... | dolphin | [
0.021716823801398277,
0.022504786029458046,
-0.02744283527135849,
-0.032085783779621124,
0.06281476467847824,
-0.030609600245952606,
-0.02884465456008911,
0.04031532257795334,
0.02485121227800846,
0.002593672601506114,
0.0362236388027668,
0.03483884036540985,
-0.04316231235861778,
-0.03010... | 0.824488 | 0.766298 | 0.058191 |
Please explain the following problem in detail and provide code in Clojure:
You are given two integers `n` and `maxValue`, which are used to describe an **ideal** array.
A **0-indexed** integer array `arr` of length `n` is considered **ideal** if the following conditions hold:
* Every `arr[i]` is a value from `1` t... | dolphin | [
0.030934657901525497,
0.03107883408665657,
-0.030506763607263565,
-0.03323902562260628,
0.03527447581291199,
-0.04271238297224045,
-0.041386160999536514,
0.032398324459791183,
0.03188372030854225,
-0.021986253559589386,
0.038858719170093536,
0.030084211379289627,
-0.03685930371284485,
-0.0... | 0.839501 | 0.784753 | 0.054748 |
Please explain the following problem in detail and provide code in C#:
Given a string s, return _the number of different non-empty palindromic subsequences in_ `s`. Since the answer may be very large, return it **modulo** `109 + 7`.
A subsequence of a string is obtained by deleting zero or more characters from the str... | dolphin | [
0.003572892863303423,
0.0011408500140532851,
-0.02341398224234581,
-0.026264699175953865,
0.027605704963207245,
-0.04570458084344864,
-0.006886808201670647,
0.08244002610445023,
0.03802963346242905,
-0.011917523108422756,
0.026722397655248642,
0.019561661407351494,
-0.04126521944999695,
-0... | 0.835784 | 0.779014 | 0.05677 |
Please write the following solution using c++:
You are given a string `s` consisting only of lowercase English letters.
In one **move**, you can select any two **adjacent** characters of `s` and swap them.
Return _the **minimum number of moves** needed to make_ `s` _a palindrome_.
**Note** that the input will be gen... | dolphin | [
0.017160024493932724,
0.020823467522859573,
-0.010317865759134293,
-0.025441819801926613,
0.035054586827754974,
-0.009454022161662579,
-0.017811862751841545,
0.08017180114984512,
0.03583879768848419,
-0.021708784624934196,
0.029749738052487373,
0.02652830444276333,
-0.029198260977864265,
-... | 0.835054 | 0.780955 | 0.054098 |
Please write the following solution using Ruby:
Given an integer array `nums`, return _the value of the bitwise_ **OR** _of the sum of all possible **subsequences** in the array_.
A **subsequence** is a sequence that can be derived from another sequence by removing zero or more elements without changing the order of t... | dolphin | [
0.0020029630977660418,
0.02903841622173786,
-0.030159804970026016,
-0.020796148106455803,
0.04275351017713547,
-0.025547010824084282,
-0.025365998968482018,
0.05192881077528,
0.04823452606797218,
-0.016788972541689873,
0.022092225030064583,
0.020101582631468773,
-0.03653443977236748,
-0.02... | 0.833667 | 0.77554 | 0.058127 |
Please focus on the efficiency of this problem and provide code in java:
Given 2 integers `n` and `start`. Your task is return **any** permutation `p` of `(0,1,2.....,2^n -1)` such that :
* `p[0] = start`
* `p[i]` and `p[i+1]` differ by only one bit in their binary representation.
* `p[0]` and `p[2^n -1]` must a... | dolphin | [
0.0295536108314991,
0.034953661262989044,
-0.01904030330479145,
-0.027400102466344833,
0.02697410248219967,
-0.033577535301446915,
-0.03644604608416557,
0.06980183720588684,
0.03315360099077225,
-0.030124099925160408,
0.04233071953058243,
0.01763954386115074,
-0.028661958873271942,
-0.0160... | 0.842231 | 0.780546 | 0.061685 |
Please write the following solution using python:
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.030182719230651855,
0.02646816149353981,
-0.025333797559142113,
-0.02773529477417469,
0.028100036084651947,
-0.017870811745524406,
-0.04926837980747223,
0.05468389391899109,
0.03803854435682297,
-0.015786712989211082,
0.025500163435935974,
0.0248203556984663,
-0.028915949165821075,
0.000... | 0.834495 | 0.767974 | 0.066521 |
Please write the following solution using java:
You are given an undirected graph (the **"original graph "**) with `n` nodes labeled from `0` to `n - 1`. You decide to **subdivide** each edge in the graph into a chain of nodes, with the number of new nodes varying between each edge.
The graph is given as a 2D array of... | dolphin | [
0.006258666981011629,
0.02391579933464527,
-0.018665334209799767,
-0.00875676516443491,
0.0375700406730175,
-0.02691512554883957,
-0.015341660007834435,
0.04374878108501434,
0.02486753836274147,
-0.013024182990193367,
0.04231828451156616,
0.014840393327176571,
-0.023965613916516304,
-0.010... | 0.842057 | 0.786539 | 0.055517 |
Please write the following solution using java:
You are given a **0-indexed** integer array `players`, where `players[i]` represents the **ability** of the `ith` player. You are also given a **0-indexed** integer array `trainers`, where `trainers[j]` represents the **training capacity** of the `jth` trainer.
The `ith`... | dolphin | [
0.040015481412410736,
0.024027880281209946,
-0.05355842411518097,
-0.02276795171201229,
0.04478545859456062,
-0.012098447419703007,
-0.023432577028870583,
0.02834371104836464,
0.03593401983380318,
-0.044503822922706604,
0.009236423298716545,
0.020537620410323143,
-0.015402321703732014,
-0.... | 0.835688 | 0.780669 | 0.055019 |
Please explain the following problem in detail and provide code in ANSI C:
Given two arrays of **unique** digits `nums1` and `nums2`, return _the **smallest** number that contains **at least** one digit from each array_.
**Example 1:**
**Input:** nums1 = \[4,1,3\], nums2 = \[5,7\]
**Output:** 15
**Explanation:** The ... | dolphin | [
-0.000795167637988925,
0.04154146835207939,
-0.01881249062716961,
-0.03679467737674713,
0.03972584009170532,
-0.023532584309577942,
-0.03375731036067009,
0.06584493070840836,
0.030679311603307724,
-0.02102980948984623,
0.02880970947444439,
0.015141499228775501,
-0.02275937609374523,
-0.019... | 0.832548 | 0.77145 | 0.061098 |
Please write the following solution using c++:
Given a string `s` and a character `c` that occurs in `s`, return _an array of integers_ `answer` _where_ `answer.length == s.length` _and_ `answer[i]` _is the **distance** from index_ `i` _to the **closest** occurrence of character_ `c` _in_ `s`.
The **distance** between... | dolphin | [
0.02844574674963951,
0.015515771694481373,
-0.021602366119623184,
-0.03073882684111595,
0.048640795052051544,
-0.03865697607398033,
-0.03126481920480728,
0.07756246626377106,
0.04181600362062454,
-0.020600276067852974,
0.035112831741571426,
0.03277638927102089,
-0.02695419266819954,
-0.013... | 0.835191 | 0.780321 | 0.05487 |
Please explain the reasoning behind the following solution and provide code in ANSI C:
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.029746320098638535,
0.029280569404363632,
-0.03606818616390228,
-0.028653448447585106,
0.02979201264679432,
-0.037284210324287415,
-0.027378374710679054,
0.061219047755002975,
0.029824651777744293,
-0.013800853863358498,
0.03208740055561066,
0.01537071168422699,
-0.04103192687034607,
0.0... | 0.847831 | 0.787646 | 0.060186 |
Please explain the reasoning behind the following solution and provide code in javascript:
For an integer array `nums`, an **inverse pair** is a pair of integers `[i, j]` where `0 <= i < j < nums.length` and `nums[i] > nums[j]`.
Given two integers n and k, return the number of different arrays consist of numbers from ... | dolphin | [
0.028619542717933655,
0.039814624935388565,
-0.030474746599793434,
-0.02336704544723034,
0.05116353556513786,
-0.022516489028930664,
-0.01041490864008665,
0.05426688864827156,
0.030121762305498123,
-0.00951763242483139,
0.024200981482863426,
0.019620677456259727,
-0.03223222866654396,
-0.0... | 0.842308 | 0.778117 | 0.06419 |
Please explain the following problem in detail and provide code in Objective-C:
Given an integer array `nums` and an integer `k`, return _the number of **subarrays** of_ `nums` _where the greatest common divisor of the subarray's elements is_ `k`.
A **subarray** is a contiguous non-empty sequence of elements within an... | dolphin | [
0.024861931800842285,
0.044331807643175125,
-0.04126980900764465,
-0.02640334889292717,
0.03995835408568382,
-0.018954496830701828,
-0.03532568737864494,
0.05371643975377083,
0.020442474633455276,
-0.019861919805407524,
0.04225316643714905,
0.02019626647233963,
-0.027800610288977623,
0.002... | 0.832295 | 0.773157 | 0.059137 |
Please explain the following problem in detail and provide code in Mojo:
Given a single-digit integer `d` and two integers `low` and `high`, return _the number of times that_ `d` _occurs as a digit in all integers in the inclusive range_ `[low, high]`.
**Example 1:**
**Input:** d = 1, low = 1, high = 13
**Output:** 6... | dolphin | [
0.004358954261988401,
0.014272614382207394,
-0.027243798598647118,
-0.03464749827980995,
0.031985651701688766,
-0.02377495728433132,
-0.030903605744242668,
0.059712234884500504,
0.021160969510674477,
0.0015530915698036551,
0.015610362403094769,
0.02434934675693512,
-0.0342453233897686,
-0.... | 0.839491 | 0.784599 | 0.054892 |
Please focus on the algorithm of this problem and provide code in java:
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`'s ... | dolphin | [
-0.0004398841701913625,
0.03890392929315567,
-0.010519066825509071,
-0.01354098878800869,
0.03675491362810135,
-0.055441271513700485,
-0.014201008714735508,
0.04636259377002716,
0.021324224770069122,
-0.012818142771720886,
0.030180081725120544,
0.012089116498827934,
-0.028040943667292595,
... | 0.843179 | 0.786613 | 0.056567 |
Please focus on the algorithm of this problem and provide code in c++:
A tree is an undirected graph in which any two vertices are connected by _exactly_ one path. In other words, any connected graph without simple cycles is a tree.
Given a tree of `n` nodes labelled from `0` to `n - 1`, and an array of `n - 1` `edges... | dolphin | [
0.025626666843891144,
0.013575049117207527,
-0.015510180033743382,
-0.02586444467306137,
0.036258045583963394,
-0.04606373608112335,
-0.0004478087357711047,
0.08329533040523529,
0.02533283270895481,
-0.019403839483857155,
0.03146990388631821,
0.01721631921827793,
-0.01799033209681511,
-0.0... | 0.835993 | 0.782049 | 0.053943 |
Please focus on the functionality of this problem and provide code in Object Pascal:
You are given a positive integer **0-indexed** array `nums`.
A subset of the array `nums` is **square-free** if the product of its elements is a **square-free integer**.
A **square-free integer** is an integer that is divisible by no... | dolphin | [
0.024769097566604614,
0.0443645641207695,
-0.03524376451969147,
-0.031137488782405853,
0.056450970470905304,
-0.02531898207962513,
-0.010442336089909077,
0.062301650643348694,
0.049829889088869095,
-0.005567425396293402,
0.030019909143447876,
0.01558577548712492,
-0.03918012976646423,
-0.0... | 0.84676 | 0.790835 | 0.055925 |
Please explain the following problem in detail and provide code in java:
You are given a **0-indexed** integer array `order` of length `n`, a **permutation** of integers from `1` to `n` representing the **order** of insertion into a **binary search tree**.
A binary search tree is defined as follows:
* The left subt... | dolphin | [
0.01839696802198887,
0.0268387608230114,
-0.03662634640932083,
-0.02356291376054287,
0.019070446491241455,
-0.038040243089199066,
-0.012249904684722424,
0.035820119082927704,
0.018115870654582977,
-0.008888177573680878,
0.03074011020362377,
0.005536475218832493,
-0.027434855699539185,
0.01... | 0.832594 | 0.775447 | 0.057147 |
translate this code to python:
```java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
public class Solution {
static final int MOD = 1000000007;
public static ArrayList<Integer> productWays(int[][] queries) {
ArrayList<Intege... | dolphin | [
0.035828690975904465,
0.03456466645002365,
-0.022880764678120613,
-0.03495396301150322,
0.02628405950963497,
-0.02088005654513836,
-0.023411903530359268,
0.05108262971043587,
0.0354163683950901,
-0.016174543648958206,
0.010535837151110172,
0.023035656660795212,
-0.013308892026543617,
-0.02... | 0.840356 | 0.782659 | 0.057697 |
Please write the following solution using Perl:
You are given an integer array `nums` and an integer `k`.
Find the longest subsequence of `nums` that meets the following requirements:
* The subsequence is **strictly increasing** and
* The difference between adjacent elements in the subsequence is **at most** `k`.... | dolphin | [
0.02589302882552147,
0.03677593544125557,
-0.02043616771697998,
-0.039459530264139175,
0.03941858187317848,
-0.019277507439255714,
-0.03905634582042694,
0.07000312209129333,
0.042120400816202164,
-0.011082137934863567,
0.033858951181173325,
0.0270801093429327,
-0.03118964470922947,
0.02281... | 0.842318 | 0.783173 | 0.059145 |
Please explain the reasoning behind the following solution and provide code in python:
You are given four integers `minLength`, `maxLength`, `oneGroup` and `zeroGroup`.
A binary string is **good** if it satisfies the following conditions:
* The length of the string is in the range `[minLength, maxLength]`.
* The ... | dolphin | [
0.015096393413841724,
0.025095736607909203,
-0.033792003989219666,
-0.041584279388189316,
0.061561837792396545,
-0.046369459480047226,
-0.047949764877557755,
0.04750628396868706,
0.020842619240283966,
-0.019460147246718407,
0.004434869159013033,
0.0175430029630661,
-0.03002661094069481,
-0... | 0.855506 | 0.79914 | 0.056366 |
Please focus on the algorithm of this problem and provide code in Dart:
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 ... | dolphin | [
0.002099464414641261,
0.022717678919434547,
-0.013576172292232513,
-0.035060301423072815,
0.03784938529133797,
-0.015331869944930077,
-0.030910847708582878,
0.045962318778038025,
0.03001750260591507,
-0.00905682984739542,
0.02402958832681179,
0.038098886609077454,
-0.027702877297997475,
0.... | 0.841202 | 0.787311 | 0.05389 |
Please focus on the functionality of this problem and provide code in ANSI C:
Alice and Bob take turns playing a game, with **Alice starting first**.
There are `n` stones arranged in a row. On each player's turn, they can **remove** either the leftmost stone or the rightmost stone from the row and receive points equal... | dolphin | [
0.03151833638548851,
0.02270578406751156,
-0.0400831513106823,
-0.0332527793943882,
0.009536712430417538,
-0.045532576739788055,
-0.030719978734850883,
0.0732751339673996,
0.053005337715148926,
-0.02875441126525402,
0.03515293076634407,
0.021313181146979332,
-0.037256013602018356,
-0.01519... | 0.844239 | 0.790524 | 0.053714 |
Please focus on the functionality of this problem and provide code in Kotlin:
Given an array of integers `arr`, and three integers `a`, `b` and `c`. You need to find the number of good triplets.
A triplet `(arr[i], arr[j], arr[k])` is **good** if the following conditions are true:
* `0 <= i < j < k < arr.length`
* ... | dolphin | [
0.022893406450748444,
0.02269294299185276,
-0.03505044803023338,
-0.028602443635463715,
0.03917960450053215,
-0.024482641369104385,
-0.03516516089439392,
0.03730582445859909,
0.01708957925438881,
-0.019846217706799507,
0.001194947399199009,
0.0247503574937582,
-0.02285381592810154,
-0.0284... | 0.837658 | 0.781615 | 0.056043 |
Please explain the reasoning behind the following solution and provide code in ANSI C:
You are given an integer array `nums`. You can choose **exactly one** index (**0-indexed**) and remove the element. Notice that the index of the elements may change after the removal.
For example, if `nums = [6,1,7,4,1]`:
* Choos... | dolphin | [
0.01712329499423504,
0.04577122628688812,
-0.017173681408166885,
-0.03592930734157562,
0.03237500786781311,
-0.04240548610687256,
-0.033021945506334305,
0.08353693783283234,
0.05282461643218994,
-0.02672271430492401,
0.01879509538412094,
0.01390306930989027,
-0.039899565279483795,
-0.03309... | 0.842478 | 0.78682 | 0.055659 |
Please write the following solution using Visual Basic .NET:
You are given the `root` of a binary tree and a positive integer `k`.
The **level sum** in the tree is the sum of the values of the nodes that are on the **same** level.
Return _the_ `kth` _**largest** level sum in the tree (not necessarily distinct)_. If t... | dolphin | [
0.03426208719611168,
0.04428661987185478,
-0.035868871957063675,
-0.05921647697687149,
0.048278775066137314,
-0.039383791387081146,
0.013168996199965477,
0.0644538402557373,
0.027110889554023743,
-0.018255814909934998,
0.047094423323869705,
0.021350901573896408,
-0.057084497064352036,
0.00... | 0.828047 | 0.77252 | 0.055526 |
Please write the following solution using c++:
Given an array of integers, return the maximum sum for a **non-empty** subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete one element from it so that there is still at least one element left... | dolphin | [
0.030065327882766724,
0.015411336906254292,
-0.024692827835679054,
-0.03501957282423973,
0.044438254088163376,
-0.010181354358792305,
-0.03206370025873184,
0.07904531806707382,
0.042500175535678864,
-0.020105181261897087,
0.02082640677690506,
0.026447409763932228,
-0.021564457565546036,
0.... | 0.833323 | 0.768092 | 0.065231 |
Please write the following solution using Visual Basic .NET:
Given a positive integer `n`, find _the smallest integer which has exactly the same digits existing in the integer_ `n` _and is greater in value than_ `n`. If no such positive integer exists, return `-1`.
**Note** that the returned integer should fit in **32... | dolphin | [
0.014546236023306847,
0.025564750656485558,
-0.027927905321121216,
-0.039770714938640594,
0.038126613944768906,
-0.029776621609926224,
-0.005588178988546133,
0.07408750802278519,
0.03419354930520058,
-0.0163040142506361,
0.03782504051923752,
0.03488437086343765,
-0.05222095921635628,
-0.02... | 0.838656 | 0.785064 | 0.053592 |
Please explain the following problem in detail and provide code in Object Pascal:
You are given a **0-indexed** integer array `nums` of length `n`. You are initially standing at index `0`. You can jump from index `i` to index `j` where `i < j` if:
* `nums[i] <= nums[j]` and `nums[k] < nums[i]` for all indexes `k` in... | dolphin | [
0.009625323116779327,
0.03341270983219147,
-0.016115741804242134,
-0.011784607544541359,
0.03947906941175461,
-0.01397896558046341,
-0.015945611521601677,
0.05525719374418259,
0.0425301268696785,
0.007809742353856564,
0.030121471732854843,
0.031207984313368797,
-0.02642507292330265,
-0.018... | 0.851675 | 0.796058 | 0.055617 |
Please explain the reasoning behind the following solution and provide code in Kotlin:
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`.
... | dolphin | [
0.012103687971830368,
0.027723530307412148,
-0.020130936056375504,
-0.017868785187602043,
0.049241915345191956,
-0.022325804457068443,
-0.04122806340456009,
0.05379748344421387,
0.030173063278198242,
-0.011244774796068668,
0.017911404371261597,
0.02541312947869301,
-0.03468923270702362,
-0... | 0.845296 | 0.786836 | 0.05846 |
Please explain the reasoning behind the following solution and provide code in java:
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... | dolphin | [
0.01998167857527733,
0.026585334911942482,
-0.02643069624900818,
-0.02561636082828045,
0.028352990746498108,
-0.02403848059475422,
-0.03370710834860802,
0.05549577996134758,
0.032568007707595825,
-0.030215365812182426,
0.017922690138220787,
0.0222305990755558,
-0.03650161623954773,
-0.0074... | 0.837763 | 0.772052 | 0.065711 |
Please focus on the algorithm of this problem and provide code in ANSI C:
The **k-beauty** of an integer `num` is defined as the number of **substrings** of `num` when it is read as a string that meet the following conditions:
* It has a length of `k`.
* It is a divisor of `num`.
Given integers `num` and `k`, ret... | dolphin | [
0.021133342757821083,
0.04248983785510063,
-0.02204982377588749,
-0.032755330204963684,
0.03088182397186756,
-0.030340421944856644,
-0.02360408753156662,
0.06475464254617691,
0.02711309865117073,
0.0005512777715921402,
0.0348798930644989,
0.03432980924844742,
-0.03146512806415558,
0.012559... | 0.835123 | 0.781355 | 0.053768 |
Please write the following solution using Fortran:
Given an array of integers `nums`, sort the array in ascending order and return it.
You must solve the problem **without using any built-in** functions in `O(nlog(n))` time complexity and with the smallest space complexity possible.
**Example 1:**
**Input:** nums = ... | dolphin | [
0.025143055245280266,
0.03504226729273796,
-0.004306113813072443,
-0.02168395183980465,
0.034798286855220795,
-0.025788739323616028,
-0.015529022552073002,
0.054483603686094284,
0.028185075148940086,
-0.01595063880085945,
0.020694753155112267,
0.01493382640182972,
-0.03990694507956505,
-0.... | 0.825651 | 0.772344 | 0.053308 |
Please write the following solution using Scheme:
There are `n` oranges in the kitchen and you decided to eat some of these oranges every day as follows:
* Eat one orange.
* If the number of remaining oranges `n` is divisible by `2` then you can eat `n / 2` oranges.
* If the number of remaining oranges `n` is di... | dolphin | [
0.010745964013040066,
0.02937868796288967,
-0.028720814734697342,
-0.032303616404533386,
0.029224896803498268,
-0.04805121570825577,
-0.027916042134165764,
0.07280281186103821,
0.024198463186621666,
-0.008242002688348293,
0.013925078324973583,
0.026574354618787766,
-0.029587488621473312,
-... | 0.834643 | 0.77823 | 0.056413 |
Please explain the reasoning behind the following solution and provide code in Scheme:
You are given a **0-indexed** 2D integer array `peaks` where `peaks[i] = [xi, yi]` states that mountain `i` has a peak at coordinates `(xi, yi)`. A mountain can be described as a right-angled isosceles triangle, with its base along t... | dolphin | [
0.02776871994137764,
0.03474065288901329,
-0.02666616067290306,
-0.027206603437662125,
0.02840041182935238,
-0.02524705044925213,
-0.03451512008905411,
0.06595304608345032,
0.03914660960435867,
-0.009484874084591866,
0.01686949096620083,
0.014451452530920506,
-0.01868809200823307,
-0.02245... | 0.843388 | 0.79004 | 0.053348 |
Please explain the reasoning behind the following solution and provide code in java:
Given a sorted integer array `nums` and an integer `n`, add/patch elements to the array such that any number in the range `[1, n]` inclusive can be formed by the sum of some elements in the array.
Return _the minimum number of patches... | dolphin | [
0.012473280541598797,
0.03152696415781975,
-0.02298158034682274,
-0.015470449812710285,
0.04669305309653282,
-0.031708911061286926,
-0.019968586042523384,
0.052635036408901215,
0.025798136368393898,
-0.004146318882703781,
0.004746216349303722,
0.0334663949906826,
-0.039297040551900864,
-0.... | 0.85081 | 0.793231 | 0.057579 |
Please explain the following problem in detail and provide code in Kotlin:
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 righ... | dolphin | [
0.004848463926464319,
0.023205922916531563,
-0.007827767170965672,
-0.030304627493023872,
0.02795776166021824,
-0.019870957359671593,
-0.02904067374765873,
0.05409664288163185,
0.034102048724889755,
-0.014451303519308567,
0.018681880086660385,
0.046956390142440796,
-0.022030970081686974,
-... | 0.845652 | 0.789309 | 0.056343 |
Please write the following solution using Object Pascal:
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 `... | dolphin | [
0.01712637022137642,
0.02923637069761753,
-0.01090353261679411,
-0.01931048184633255,
0.05010414496064186,
-0.01975124701857567,
-0.019670378416776657,
0.05708638206124306,
0.04162777587771416,
-0.00024874345399439335,
0.01645788550376892,
0.03375598415732384,
-0.024370679631829262,
-0.018... | 0.846141 | 0.784971 | 0.06117 |
Please write the following solution using Fortran:
Given an `m x n` matrix `mat` where every row is sorted in **strictly** **increasing** order, return _the **smallest common element** in all rows_.
If there is no common element, return `-1`.
**Example 1:**
**Input:** mat = \[\[1,2,3,4,5\],\[2,4,5,8,10\],\[3,5,7,9,1... | dolphin | [
0.029207328334450722,
0.02901817485690117,
-0.026689695194363594,
-0.05814426392316818,
0.04989953339099884,
-0.02465984784066677,
-0.025777243077754974,
0.06545832753181458,
0.0330687053501606,
-0.017986994236707687,
0.012491438537836075,
0.00018175310106016695,
-0.034628916531801224,
-0.... | 0.833432 | 0.778976 | 0.054456 |
Please focus on the algorithm of this problem and provide code in c++:
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 - i <... | dolphin | [
0.017880097031593323,
0.01619337871670723,
-0.023799369111657143,
-0.025373609736561775,
0.040819793939590454,
0.008241078816354275,
-0.03298337385058403,
0.1030554324388504,
0.03303273767232895,
-0.016364676877856255,
0.03304526209831238,
0.048272520303726196,
-0.037757743149995804,
0.026... | 0.837084 | 0.769167 | 0.067917 |
Please write the following solution using Fortran:
You are given an integer array `nums`. We call a subset of `nums` **good** if its product can be represented as a product of one or more **distinct prime** numbers.
* For example, if `nums = [1, 2, 3, 4]`:
* `[2, 3]`, `[1, 2, 3]`, and `[1, 3]` are **good** sub... | dolphin | [
0.03534629940986633,
0.015672650188207626,
-0.02774360403418541,
-0.03457864373922348,
0.03850280120968819,
-0.033925674855709076,
-0.027373427525162697,
0.0573318712413311,
0.04448065906763077,
-0.008732031099498272,
0.028498288244009018,
0.026516880840063095,
-0.03058139607310295,
-0.022... | 0.842358 | 0.787986 | 0.054372 |
Please focus on the functionality of this problem and provide code in Kotlin:
You are given a **0-indexed** integer array `nums`, where `nums[i]` represents the score of the `ith` student. You are also given an integer `k`.
Pick the scores of any `k` students from the array so that the **difference** between the **hig... | dolphin | [
0.001995914848521352,
0.013571443036198616,
-0.019497133791446686,
-0.0310364942997694,
0.04577329754829407,
-0.03348628431558609,
-0.02577824518084526,
0.04752287268638611,
0.03803453594446182,
-0.0140813197940588,
0.038619622588157654,
0.03784514218568802,
-0.018888844177126884,
0.021480... | 0.84537 | 0.792101 | 0.053269 |
Please write the following solution using ANSI C:
There are `m` boys and `n` girls in a class attending an upcoming party.
You are given an `m x n` integer matrix `grid`, where `grid[i][j]` equals `0` or `1`. If `grid[i][j] == 1`, then that means the `ith` boy can invite the `jth` girl to the party. A boy can invite a... | dolphin | [
-0.00024649492115713656,
0.02816537208855152,
-0.015886126086115837,
-0.04646517336368561,
0.03633221983909607,
-0.049881741404533386,
-0.03420040383934975,
0.06065412983298302,
0.03744969144463539,
-0.015619638375937939,
0.02832137793302536,
0.03813156113028526,
-0.0324065200984478,
-0.02... | 0.847064 | 0.783927 | 0.063136 |
Please focus on the algorithm of this problem and provide code in java:
There is an undirected connected tree with `n` nodes labeled from `0` to `n - 1` and `n - 1` edges.
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 in... | dolphin | [
-0.0005761392530985177,
0.022664135321974754,
-0.02879384160041809,
-0.026647355407476425,
0.025811349973082542,
-0.03890911862254143,
-0.013213892467319965,
0.05821987986564636,
0.032618261873722076,
-0.0021884606685489416,
0.03170021250844002,
0.015959471464157104,
-0.028888197615742683,
... | 0.839142 | 0.784512 | 0.05463 |
Please explain the following problem in detail and provide code in Mojo:
Numbers can be regarded as the product of their factors.
* For example, `8 = 2 x 2 x 2 = 2 x 4`.
Given an integer `n`, return _all possible combinations of its factors_. You may return the answer in **any order**.
**Note** that the factors sh... | dolphin | [
0.05143972858786583,
0.049095869064331055,
-0.0038256878033280373,
-0.029951810836791992,
0.029954537749290466,
-0.024688826873898506,
-0.03264825791120529,
0.05035394802689552,
0.04594065994024277,
-0.005365652032196522,
0.01976257748901844,
0.0360993929207325,
-0.05678515508770943,
-0.04... | 0.836514 | 0.780343 | 0.056172 |
Please write the following solution using Kotlin:
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:**
The even elements are 0... | dolphin | [
0.02113788016140461,
0.02655964344739914,
-0.019464129582047462,
-0.03708893433213234,
0.035103995352983475,
-0.01032253261655569,
-0.023578103631734848,
0.06662461906671524,
0.03354805335402489,
-0.006152010057121515,
0.021026523783802986,
0.024933213368058205,
-0.018472466617822647,
-0.0... | 0.835427 | 0.773915 | 0.061512 |
Please write the following solution using Scheme:
We have an array of integers, `nums`, and an array of `requests` where `requests[i] = [starti, endi]`. The `ith` request asks for the sum of `nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]`. Both `starti` and `endi` are _0-indexed_.
Return _the max... | dolphin | [
0.029888421297073364,
0.03368298336863518,
-0.023008931428194046,
-0.0317852608859539,
0.04109451547265053,
-0.029262511059641838,
-0.04471482336521149,
0.034864552319049835,
0.024791570380330086,
-0.012786197476089,
0.030063016340136528,
0.02786187268793583,
-0.04503210633993149,
-0.00205... | 0.847247 | 0.788749 | 0.058499 |
Please explain the following problem in detail and provide code in Dart:
The **bitwise AND** of an array `nums` is the bitwise AND of all integers in `nums`.
* For example, for `nums = [1, 5, 3]`, the bitwise AND is equal to `1 & 5 & 3 = 1`.
* Also, for `nums = [7]`, the bitwise AND is `7`.
You are given an array... | dolphin | [
0.010446972213685513,
0.031004222109913826,
-0.015624351799488068,
-0.01965230703353882,
0.036102160811424255,
-0.011013766750693321,
-0.03258640691637993,
0.049631550908088684,
0.03216860443353653,
-0.00858649518340826,
0.03339970111846924,
0.04450342804193497,
-0.02913055755198002,
-0.01... | 0.841929 | 0.785243 | 0.056686 |
Please write the following solution using Scala:
Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous part of the array.
**Example 1:**
*... | dolphin | [
0.018366791307926178,
0.029233328998088837,
-0.03604299947619438,
-0.025868233293294907,
0.04784813150763512,
-0.007990136742591858,
-0.016687460243701935,
0.041119080036878586,
0.03415233641862869,
-0.010456121526658535,
0.040327657014131546,
0.0333792082965374,
-0.025618791580200195,
0.0... | 0.835396 | 0.774742 | 0.060654 |
Please explain the following problem in detail and provide code in c++:
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 + 4 = ... | dolphin | [
0.023678481578826904,
0.022524910047650337,
-0.020491234958171844,
-0.04523947089910507,
0.04989292100071907,
-0.009701264090836048,
-0.043211616575717926,
0.09716399759054184,
0.043433334678411484,
0.009087299928069115,
0.012674390338361263,
0.04924895241856575,
-0.05586065351963043,
-0.0... | 0.831955 | 0.77276 | 0.059195 |
Please focus on the efficiency of this problem and provide code in Perl:
Given an array `nums` and an integer `target`, return _the maximum number of **non-empty** **non-overlapping** subarrays such that the sum of values in each subarray is equal to_ `target`.
**Example 1:**
**Input:** nums = \[1,1,1,1,1\], target =... | dolphin | [
0.019539037719368935,
0.01533732283860445,
-0.0395665317773819,
-0.025365421548485756,
0.04888234660029411,
0.006150372326374054,
-0.0277011189609766,
0.037653230130672455,
0.024350138381123543,
-0.01629365235567093,
0.038720808923244476,
0.04726722091436386,
-0.03330212086439133,
-0.02755... | 0.845111 | 0.790658 | 0.054453 |
Please write the following solution using Clojure:
You are given an integer array `nums`. In one move, you can pick an index `i` where `0 <= i < nums.length` and increment `nums[i]` by `1`.
Return _the minimum number of moves to make every value in_ `nums` _**unique**_.
The test cases are generated so that the answer... | dolphin | [
0.00856399443000555,
0.03832051903009415,
-0.012020966038107872,
-0.022401684895157814,
0.038138531148433685,
-0.023278968408703804,
-0.024775058031082153,
0.05396765470504761,
0.033128052949905396,
-0.028031613677740097,
0.03599196672439575,
0.01062886044383049,
-0.024157783016562462,
-0.... | 0.846621 | 0.789375 | 0.057246 |
Please write the following solution using Kotlin:
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'`: Presen... | dolphin | [
0.007854348979890347,
0.015484264120459557,
-0.010259361006319523,
-0.029345571994781494,
0.027147088199853897,
-0.03744201362133026,
-0.03587668016552925,
0.049309778958559036,
0.017772236838936806,
-0.0094407694414258,
0.0220461655408144,
0.05014187470078468,
-0.026736686006188393,
-0.01... | 0.855197 | 0.798629 | 0.056568 |
Please explain the following problem in detail and provide code in C#:
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:** ... | dolphin | [
0.02957254648208618,
0.030958285555243492,
-0.02616036683320999,
-0.021918635815382004,
0.04144999384880066,
-0.035893797874450684,
-0.01267141941934824,
0.09538227319717407,
0.0376419872045517,
-0.012171614915132523,
0.010647584684193134,
0.01928769052028656,
-0.038612160831689835,
-0.035... | 0.845102 | 0.787285 | 0.057817 |
Please focus on the algorithm of this problem and provide code in ANSI C:
Given an integer n, return _the smallest **prime palindrome** greater than or equal to_ `n`.
An integer is **prime** if it has exactly two divisors: `1` and itself. Note that `1` is not a prime number.
* For example, `2`, `3`, `5`, `7`, `11`,... | dolphin | [
0.026746226474642754,
0.032665446400642395,
0.0015669047133997083,
-0.035572417080402374,
0.018185701221227646,
-0.03614496439695358,
-0.020574133843183517,
0.08974883705377579,
0.032260000705718994,
-0.01787717454135418,
0.04167758673429489,
0.025625888258218765,
-0.036522362381219864,
-0... | 0.825531 | 0.764901 | 0.06063 |
Please explain the following problem in detail and provide code in R:
Given two integers `num` and `k`, consider a set of positive integers with the following properties:
* The units digit of each integer is `k`.
* The sum of the integers is `num`.
Return _the **minimum** possible size of such a set, or_ `-1` _if... | dolphin | [
0.01358029991388321,
0.03487282618880272,
-0.02934914268553257,
-0.0382813923060894,
0.03823907673358917,
-0.019746530801057816,
-0.01766398549079895,
0.05070319399237633,
0.041115060448646545,
-0.003328661434352398,
0.02195601724088192,
0.04004814848303795,
-0.028774186968803406,
-0.02255... | 0.838273 | 0.776705 | 0.061569 |
Please explain the reasoning behind the following solution and provide code in PHP:
Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is **minimized**.
Return _the minimized largest sum of the split_.
A **subarray** is a contiguous pa... | dolphin | [
0.016965661197900772,
0.03766454756259918,
-0.03636089712381363,
-0.022005422040820122,
0.04779810830950737,
-0.009089796803891659,
-0.02631491795182228,
0.061064716428518295,
0.04250013828277588,
-0.005932531785219908,
0.03534191474318504,
0.030890250578522682,
-0.03820943459868431,
0.017... | 0.839065 | 0.784997 | 0.054068 |
Please explain the following problem in detail and provide code in ANSI C:
Given an integer `n`, return `true` _if_ `n` _has **exactly three positive divisors**. Otherwise, return_ `false`.
An integer `m` is a **divisor** of `n` if there exists an integer `k` such that `n = k * m`.
**Example 1:**
**Input:** n = 2
**... | dolphin | [
0.025904018431901932,
0.02828584425151348,
-0.013129509054124355,
-0.03437782824039459,
0.03582357242703438,
-0.031160233542323112,
-0.017770739272236824,
0.08596846461296082,
0.014927702024579048,
-0.009543808177113533,
0.022203201428055763,
0.03391481190919876,
-0.03537827357649803,
-0.0... | 0.820334 | 0.766847 | 0.053486 |
Please explain the following problem in detail and provide code in python:
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 adja... | dolphin | [
0.013313909992575645,
0.02740326151251793,
-0.03927537798881531,
-0.03299250826239586,
0.03357865661382675,
-0.0031554216984659433,
-0.039889924228191376,
0.05612301081418991,
-0.003526056418195367,
-0.0013511396246030927,
0.02318522520363331,
0.02942422404885292,
-0.016486486420035362,
-0... | 0.845915 | 0.791483 | 0.054432 |
Please write the following solution using C#:
A **permutation** of an array of integers is an arrangement of its members into a sequence or linear order.
* For example, for `arr = [1,2,3]`, the following are all the permutations of `arr`: `[1,2,3], [1,3,2], [2, 1, 3], [2, 3, 1], [3,1,2], [3,2,1]`.
The **next permut... | dolphin | [
0.015419616363942623,
0.035447292029857635,
-0.006782079115509987,
-0.026606623083353043,
0.02400744892656803,
-0.03457885608077049,
-0.032418616116046906,
0.088327556848526,
0.028924988582730293,
-0.03223324567079544,
0.009544038213789463,
0.015645528212189674,
-0.042990848422050476,
-0.0... | 0.846932 | 0.792499 | 0.054433 |
Please explain the following problem in detail and provide code in c++:
Given an integer `n`, return _the least number of perfect square numbers that sum to_ `n`.
A **perfect square** is an integer that is the square of an integer; in other words, it is the product of some integer with itself. For example, `1`, `4`, `... | dolphin | [
0.016476348042488098,
0.040200889110565186,
-0.02089829370379448,
-0.0515335388481617,
0.04831385612487793,
-0.012999597936868668,
-0.02760777622461319,
0.07635469734668732,
0.042479414492845535,
0.00449379812926054,
0.02881723642349243,
0.04441389441490173,
-0.04153568670153618,
-0.030641... | 0.828337 | 0.765799 | 0.062538 |
Please explain the following problem in detail and provide code in Haskell:
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.03078901767730713,
0.02132401615381241,
-0.01616339199244976,
-0.03430783003568649,
0.034182265400886536,
-0.03794029727578163,
-0.03153219074010849,
0.044150836765766144,
0.04284880682826042,
-0.015853818506002426,
0.03152446448802948,
0.028384627774357796,
-0.02982216700911522,
-0.0098... | 0.843169 | 0.78638 | 0.05679 |
Please write the following solution using ANSI C:
You are given a string `num` representing a large integer. An integer is **good** if it meets the following conditions:
* It is a **substring** of `num` with length `3`.
* It consists of only one unique digit.
Return _the **maximum good** integer as a **string** o... | dolphin | [
0.00823177769780159,
0.026109496131539345,
-0.019735706970095634,
-0.049793634563684464,
0.020309891551733017,
-0.03475013002753258,
-0.02479669079184532,
0.06535040587186813,
0.02358539029955864,
-0.005355071276426315,
0.03600795194506645,
0.03629589453339577,
-0.037070512771606445,
-0.02... | 0.827254 | 0.774008 | 0.053246 |
Please explain the following problem in detail and provide code in c++:
Given an integer array `nums` of `2n` integers, group these integers into `n` pairs `(a1, b1), (a2, b2), ..., (an, bn)` such that the sum of `min(ai, bi)` for all `i` is **maximized**. Return _the maximized sum_.
**Example 1:**
**Input:** nums = ... | dolphin | [
0.015096377581357956,
0.022418798878788948,
-0.03706453740596771,
-0.018485764041543007,
0.04639633372426033,
0.005171345081180334,
-0.02705654315650463,
0.07745432108640671,
0.036360181868076324,
-0.004726354032754898,
0.016499217599630356,
0.04524725675582886,
-0.027848992496728897,
-0.0... | 0.837861 | 0.772197 | 0.065664 |
Please write the following solution using Swift:
You have a set of integers `s`, which originally contains all the numbers from `1` to `n`. Unfortunately, due to some error, one of the numbers in `s` got duplicated to another number in the set, which results in **repetition of one** number and **loss of another** numbe... | dolphin | [
0.020348038524389267,
0.022662006318569183,
-0.022310782223939896,
-0.027400270104408264,
0.04794755205512047,
-0.01730966940522194,
-0.03580953925848007,
0.06539979577064514,
0.03040578030049801,
-0.016382601112127304,
0.035073552280664444,
0.0021093047689646482,
-0.024060668423771858,
-0... | 0.847099 | 0.792839 | 0.05426 |
Please write the following solution using C#:
You are given an array of positive integers `arr`. Perform some operations (possibly none) on `arr` so that it satisfies these conditions:
* The value of the **first** element in `arr` must be `1`.
* The absolute difference between any 2 adjacent elements must be **les... | dolphin | [
0.03266427293419838,
0.03395431488752365,
-0.028364235535264015,
-0.019691873341798782,
0.025562414899468422,
-0.03182365745306015,
-0.04238368943333626,
0.08714202046394348,
0.05978645384311676,
-0.013619218952953815,
0.018962889909744263,
0.007787959184497595,
-0.03997601941227913,
-0.01... | 0.846096 | 0.785998 | 0.060098 |
Please focus on the algorithm of this problem and provide code in Scala:
Given an integer array `arr`, and an integer `target`, return the number of tuples `i, j, k` such that `i < j < k` and `arr[i] + arr[j] + arr[k] == target`.
As the answer can be very large, return it **modulo** `109 + 7`.
**Example 1:**
**Input... | dolphin | [
0.01860187202692032,
0.025104651227593422,
-0.024077367037534714,
-0.02376510761678219,
0.0456673800945282,
-0.018255416303873062,
-0.030371220782399178,
0.05718667805194855,
0.014604311436414719,
-0.012071983888745308,
0.026881171390414238,
0.026680829003453255,
-0.029229847714304924,
-0.... | 0.847889 | 0.793801 | 0.054088 |
Please focus on the algorithm of this problem and provide code in ANSI C:
You are given a binary string `s` and a positive integer `k`.
Return _the length of the **longest** subsequence of_ `s` _that makes up a **binary** number less than or equal to_ `k`.
Note:
* The subsequence can contain **leading zeroes**.
* ... | dolphin | [
0.006677310913801193,
0.031101353466510773,
-0.01573600433766842,
-0.03626067563891411,
0.039611153304576874,
-0.04539931192994118,
-0.027975168079137802,
0.0784749686717987,
0.043149735778570175,
-0.011648138053715229,
0.035842906683683395,
0.022598017007112503,
-0.032239217311143875,
-0.... | 0.832463 | 0.772433 | 0.06003 |
Please focus on the efficiency of this problem and provide code in python:
You are given an array `points` containing the coordinates of points on a 2D plane, sorted by the x-values, where `points[i] = [xi, yi]` such that `xi < xj` for all `1 <= i < j <= points.length`. You are also given an integer `k`.
Return _the m... | dolphin | [
0.0210074745118618,
0.031167704612016678,
-0.049461521208286285,
-0.03291688114404678,
0.022516002878546715,
-0.018745260313153267,
-0.03661949560046196,
0.05484715849161148,
0.03817624971270561,
-0.004298487678170204,
0.01902082934975624,
0.04142110049724579,
-0.030441638082265854,
0.0100... | 0.849374 | 0.795668 | 0.053706 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.