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 focus on the algorithm of this problem and provide code in ANSI C:
Given a **0-indexed** integer array `nums` of size `n` containing all numbers from `1` to `n`, return _the number of increasing quadruplets_.
A quadruplet `(i, j, k, l)` is increasing if:
* `0 <= i < j < k < l < n`, and
* `nums[i] < nums[k]... | dolphin | [
0.010469913482666016,
0.032811589539051056,
-0.0037389134522527456,
-0.011024280451238155,
0.023539049550890923,
-0.012615388259291649,
-0.03209264948964119,
0.08878611773252487,
0.019391585141420364,
-0.013385552912950516,
0.02098154090344906,
0.0007457920000888407,
-0.044063813984394073,
... | 0.841727 | 0.780814 | 0.060913 |
Please write the following solution using PHP:
You are given two integers `n` and `maxValue`, which are used to describe an **ideal** array.
A **0-indexed** integer array `arr` of length `n` is considered **ideal** if the following conditions hold:
* Every `arr[i]` is a value from `1` to `maxValue`, for `0 <= i < n... | dolphin | [
0.038351137191057205,
0.027515128254890442,
-0.028847351670265198,
-0.023194102570414543,
0.03832130879163742,
-0.038019582629203796,
-0.053327206522226334,
0.06064709648489952,
0.036583226174116135,
-0.01473439671099186,
0.03915007784962654,
0.027224497869610786,
-0.0516563281416893,
-0.0... | 0.844133 | 0.776719 | 0.067414 |
Please write the following solution using Perl:
Given a binary string `s`, return the number of non-empty substrings that have the same number of `0`'s and `1`'s, and all the `0`'s and all the `1`'s in these substrings are grouped consecutively.
Substrings that occur multiple times are counted the number of times they... | dolphin | [
0.005253979936242104,
0.015516462735831738,
-0.032572098076343536,
-0.03931400179862976,
0.04034831002354622,
-0.03348780795931816,
-0.022478297352790833,
0.06343945860862732,
0.01905972696840763,
-0.006146236322820187,
0.03419569507241249,
0.015605762600898743,
-0.03138783574104309,
-0.02... | 0.830475 | 0.77644 | 0.054035 |
Please explain the reasoning behind the following solution and provide code in c++:
You are given an integer array `nums`.
In one move, you can choose one element of `nums` and change it to **any value**.
Return _the minimum difference between the largest and smallest value of `nums` **after performing at most three ... | dolphin | [
0.01892182044684887,
0.022996103391051292,
-0.02192865125834942,
-0.029368646442890167,
0.04439953342080116,
-0.013591699302196503,
-0.035975564271211624,
0.09487414360046387,
0.03826335817575455,
-0.024234512820839882,
0.03787991404533386,
0.03953508660197258,
-0.03708209469914436,
-0.008... | 0.846605 | 0.787168 | 0.059437 |
Please write the following solution using Lisp:
Given an unsorted array of integers `nums`, return _the length of the longest consecutive elements sequence._
You must write an algorithm that runs in `O(n)` time.
**Example 1:**
**Input:** nums = \[100,4,200,1,3,2\]
**Output:** 4
**Explanation:** The longest consecuti... | dolphin | [
0.01740167662501335,
0.023820385336875916,
-0.023068970069289207,
-0.04230166971683502,
0.035736940801143646,
-0.027884600684046745,
-0.034552622586488724,
0.04918220266699791,
0.04588555544614792,
-0.017881270498037338,
0.033897995948791504,
0.029088543727993965,
-0.03237169608473778,
-0.... | 0.838037 | 0.78474 | 0.053297 |
Please explain the reasoning behind the following solution and provide code in c++:
Given a positive integer `n`, you can apply one of the following operations:
1. If `n` is even, replace `n` with `n / 2`.
2. If `n` is odd, replace `n` with either `n + 1` or `n - 1`.
Return _the minimum number of operations needed ... | dolphin | [
0.02452979050576687,
0.027247443795204163,
-0.017490101978182793,
-0.0418950617313385,
0.029174627736210823,
-0.011196629144251347,
-0.04620843380689621,
0.09092859923839569,
0.029542312026023865,
-0.009288988076150417,
0.016063731163740158,
0.020196497440338135,
-0.02048405259847641,
-0.0... | 0.840998 | 0.785788 | 0.05521 |
Please explain the following problem in detail and provide code in Fortran:
Given a 2D `grid` of `0`s and `1`s, return the number of elements in the largest **square** subgrid that has all `1`s on its **border**, or `0` if such a subgrid doesn't exist in the `grid`.
**Example 1:**
**Input:** grid = \[\[1,1,1\],\[1,0,... | dolphin | [
0.00797710195183754,
0.03224704787135124,
-0.012426831759512424,
-0.04159193113446236,
0.030978908762335777,
-0.02732776291668415,
-0.02353205904364586,
0.0539352148771286,
0.03120964579284191,
-0.0003809922782238573,
0.018122395500540733,
0.029209250584244728,
-0.033447325229644775,
-0.02... | 0.83604 | 0.780224 | 0.055816 |
Please write the following solution using Dart:
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 = 9
Result = 24 - 9 = 15
... | dolphin | [
0.02001034840941429,
0.015726527199149132,
-0.024038318544626236,
-0.04218120872974396,
0.05255648121237755,
-0.01951727271080017,
-0.04823486879467964,
0.05733414366841316,
0.043704356998205185,
0.005153166130185127,
0.008605721406638622,
0.03930509462952614,
-0.05850294232368469,
-0.0241... | 0.82969 | 0.774146 | 0.055544 |
Please explain the following problem in detail and provide code in C#:
Given `n` points on a 1-D plane, where the `ith` point (from `0` to `n-1`) is at `x = i`, find the number of ways we can draw **exactly** `k` **non-overlapping** line segments such that each segment covers two or more points. The endpoints of each s... | dolphin | [
0.012564476579427719,
0.03613000735640526,
-0.028208531439304352,
-0.03626740723848343,
0.020493172109127045,
-0.025129171088337898,
-0.01675775647163391,
0.07848961651325226,
0.04390852153301239,
-0.02212919481098652,
0.02981574274599552,
0.050173353403806686,
-0.023064985871315002,
-0.01... | 0.841092 | 0.787329 | 0.053764 |
Please write the following solution using java:
Given the root of a binary tree and two integers `p` and `q`, return _the **distance** between the nodes of value_ `p` _and value_ `q` _in the tree_.
The **distance** between two nodes is the number of edges on the path from one to the other.
**Example 1:**
**Input:** ... | dolphin | [
0.02719593234360218,
0.02159307524561882,
-0.034306641668081284,
-0.017552731558680534,
0.029416678473353386,
-0.045684974640607834,
-0.005775129422545433,
0.035517629235982895,
0.03613068163394928,
-0.02119964361190796,
0.04257670417428017,
0.012933746911585331,
-0.024220837280154228,
0.0... | 0.824061 | 0.768291 | 0.05577 |
Please explain the following problem in detail and provide code in Scheme:
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 ... | dolphin | [
0.012383615598082542,
0.030888566747307777,
-0.03477455675601959,
-0.03546179085969925,
0.04475945606827736,
-0.03207450360059738,
-0.01985749788582325,
0.045524660497903824,
0.021811533719301224,
-0.010700121521949768,
0.023769374936819077,
0.03508096933364868,
-0.036487895995378494,
-0.0... | 0.847737 | 0.78691 | 0.060826 |
Please explain the reasoning behind the following solution and provide code in Mojo:
You are given a **0-indexed** integer array `nums` of length `n`.
`nums` contains a **valid split** at index `i` if the following are true:
* The sum of the first `i + 1` elements is **greater than or equal to** the sum of the last... | dolphin | [
0.02115485817193985,
0.030164038762450218,
-0.022716810926795006,
-0.022102022543549538,
0.0443461574614048,
-0.011854632757604122,
-0.035096876323223114,
0.07116527855396271,
0.02743690088391304,
-0.00425552437081933,
0.019080135971307755,
0.016209784895181656,
-0.035317763686180115,
-0.0... | 0.851305 | 0.795801 | 0.055504 |
Please write the following solution using R:
Given an array of positive integers `nums`, remove the **smallest** subarray (possibly **empty**) such that the **sum** of the remaining elements is divisible by `p`. It is **not** allowed to remove the whole array.
Return _the length of the smallest subarray that you need ... | dolphin | [
0.005039559211581945,
0.0359642319381237,
-0.030234411358833313,
-0.026351284235715866,
0.04011347517371178,
-0.031613439321517944,
-0.020497603341937065,
0.05250680819153786,
0.05494435876607895,
0.002764478325843811,
0.017282135784626007,
0.020425930619239807,
-0.03394479677081108,
-0.01... | 0.832677 | 0.778217 | 0.05446 |
Please write the following solution using Rust:
There is an **undirected** graph with `n` nodes, numbered from `0` to `n - 1`.
You are given a **0-indexed** integer array `scores` of length `n` where `scores[i]` denotes the score of node `i`. You are also given a 2D integer array `edges` where `edges[i] = [ai, bi]` de... | dolphin | [
8.848434731589805e-7,
0.019360698759555817,
-0.00663756625726819,
-0.028234628960490227,
0.027585625648498535,
-0.031075121834874153,
-0.022263571619987488,
0.06063932552933693,
0.03466786816716194,
0.0010351106757298112,
0.016771452501416206,
0.02072034776210785,
-0.008004076778888702,
-0... | 0.849099 | 0.794658 | 0.054441 |
Please write the following solution using PHP:
The **width** of a sequence is the difference between the maximum and minimum elements in the sequence.
Given an array of integers `nums`, return _the sum of the **widths** of all the non-empty **subsequences** of_ `nums`. Since the answer may be very large, return it **m... | dolphin | [
0.004522327333688736,
0.02045547403395176,
-0.027435241267085075,
-0.019744733348488808,
0.05595724284648895,
-0.006363695487380028,
-0.05143928900361061,
0.05322527512907982,
0.03646502643823624,
-0.011956463567912579,
0.035780467092990875,
0.03736268728971481,
-0.047037892043590546,
-0.0... | 0.842288 | 0.77686 | 0.065428 |
Please focus on the efficiency of this problem and provide code in Object Pascal:
You are given an array `nums` consisting of **positive** integers.
We call a subarray of `nums` **nice** if the bitwise **AND** of every pair of elements that are in **different** positions in the subarray is equal to `0`.
Return _the l... | dolphin | [
0.006992224603891373,
0.016641106456518173,
-0.039215028285980225,
-0.007768832612782717,
0.03509233146905899,
-0.026397863402962685,
-0.036794185638427734,
0.046953555196523666,
0.036258768290281296,
-0.005367853678762913,
0.041730087250471115,
0.026763062924146652,
-0.02919629029929638,
... | 0.849953 | 0.789724 | 0.060229 |
Please explain the following problem in detail and provide code in PHP:
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.02118556573987007,
0.032428037375211716,
-0.0253127571195364,
-0.03906617313623428,
0.050107162445783615,
-0.02468203939497471,
-0.04252694174647331,
0.0667824000120163,
0.042425088584423065,
0.01379927434027195,
0.011706603690981865,
0.04170987755060196,
-0.06370808184146881,
-0.0223751... | 0.828921 | 0.772229 | 0.056692 |
Please focus on the efficiency of this problem and provide code in Scala:
You are given a **0-indexed** array of `n` integers `differences`, which describes the **differences** between each pair of **consecutive** integers of a **hidden** sequence of length `(n + 1)`. More formally, call the hidden sequence `hidden`, t... | dolphin | [
0.0197495948523283,
0.03651849180459976,
-0.016364077106118202,
-0.01875160075724125,
0.035894811153411865,
-0.01817864179611206,
-0.037230584770441055,
0.061725813895463943,
0.03383302316069603,
-0.015843352302908897,
0.027836870402097702,
0.03446001186966896,
-0.02446473389863968,
-0.009... | 0.849366 | 0.795782 | 0.053584 |
Please explain the following problem in detail and provide code in Scheme:
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 **un... | dolphin | [
0.023965025320649147,
0.0408640094101429,
-0.01050412468612194,
-0.018379900604486465,
0.031174063682556152,
-0.027214856818318367,
-0.03870471566915512,
0.07397553324699402,
0.038060951977968216,
-0.019793128594756126,
0.02247253805398941,
0.015455692075192928,
-0.02096676267683506,
-0.00... | 0.849629 | 0.791401 | 0.058228 |
Please write the following solution using Dart:
Given an array of integers `nums` and an integer `k`, return _the total number of subarrays whose sum equals to_ `k`.
A subarray is a contiguous **non-empty** sequence of elements within an array.
**Example 1:**
**Input:** nums = \[1,1,1\], k = 2
**Output:** 2
**Examp... | dolphin | [
0.009306320920586586,
0.027446335181593895,
-0.030169913545250893,
-0.027677208185195923,
0.04461517930030823,
0.005596543662250042,
-0.02638852968811989,
0.03335113450884819,
0.027686933055520058,
-0.0019196155481040478,
0.021247267723083496,
0.02678375318646431,
-0.04006164148449898,
-0.... | 0.831372 | 0.765378 | 0.065993 |
Please write the following solution using python:
You are given a positive integer `n` representing the number of nodes in an **undirected** graph. The nodes are labeled from `1` to `n`.
You are also given a 2D integer array `edges`, where `edges[i] = [ai, bi]` indicates that there is a **bidirectional** edge between ... | dolphin | [
0.02877870574593544,
0.029187370091676712,
-0.04776075854897499,
-0.029281102120876312,
0.050826530903577805,
-0.044517356902360916,
-0.021541869267821312,
0.05050443857908249,
0.0318685919046402,
-0.0027519711293280125,
0.02256121300160885,
0.010623502545058727,
-0.015448616817593575,
-0.... | 0.855664 | 0.79825 | 0.057415 |
Please write the following solution using Haskell:
Given the array `nums`, obtain a subsequence of the array whose sum of elements is **strictly greater** than the sum of the non included elements in such subsequence.
If there are multiple solutions, return the subsequence with **minimum size** and if there still exis... | dolphin | [
0.013270807452499866,
0.02407032437622547,
-0.01708926074206829,
-0.031006213277578354,
0.06119149923324585,
-0.016762301325798035,
-0.0067336102947592735,
0.03838559612631798,
0.04185257479548454,
-0.012624007649719715,
0.01870548725128174,
0.029960686340928078,
-0.041725993156433105,
-0.... | 0.83896 | 0.783101 | 0.055859 |
Please write the following solution using java:
You have an array `arr` of length `n` where `arr[i] = (2 * i) + 1` for all valid values of `i` (i.e., `0 <= i < n`).
In one operation, you can select two indices `x` and `y` where `0 <= x, y < n` and subtract `1` from `arr[x]` and add `1` to `arr[y]` (i.e., perform `arr[... | dolphin | [
0.03351793438196182,
0.019475921988487244,
-0.043868500739336014,
-0.04355626180768013,
0.029540490359067917,
-0.03478081151843071,
-0.024465758353471756,
0.05744253844022751,
0.02994544245302677,
-0.02736392244696617,
0.0231547299772501,
0.010697535239160061,
-0.02062489464879036,
-0.0194... | 0.849598 | 0.782537 | 0.067061 |
Please write the following solution using Object Pascal:
Given an array `arr` of integers, check if there exist two indices `i` and `j` such that :
* `i != j`
* `0 <= i, j < arr.length`
* `arr[i] == 2 * arr[j]`
**Example 1:**
**Input:** arr = \[10,2,5,3\]
**Output:** true
**Explanation:** For i = 0 and j = 2, ... | dolphin | [
0.015573804266750813,
0.027652248740196228,
-0.027620647102594376,
-0.03477691113948822,
0.045257724821567535,
-0.025979621335864067,
-0.011978300288319588,
0.07909387350082397,
0.0361306294798851,
-0.010524717159569263,
0.019388385117053986,
0.0010196776129305363,
-0.02669062837958336,
-0... | 0.838731 | 0.778229 | 0.060502 |
Please focus on the algorithm of this problem and provide code in python:
You are given `m` `arrays`, where each array is sorted in **ascending order**.
You can pick up two integers from two different arrays (each array picks one) and calculate the distance. We define the distance between two integers `a` and `b` to b... | dolphin | [
0.025959735736250877,
0.01950952410697937,
-0.02115441858768463,
-0.019442223012447357,
0.02089160867035389,
-0.032234981656074524,
-0.049831271171569824,
0.03204921633005142,
0.025101887062191963,
-0.02275802753865719,
0.01721886731684208,
0.023725103586912155,
-0.033015210181474686,
0.00... | 0.83739 | 0.779502 | 0.057888 |
Please explain the following problem in detail and provide code in Swift:
Given a binary array `nums` and an integer `goal`, return _the number of non-empty **subarrays** with a sum_ `goal`.
A **subarray** is a contiguous part of the array.
**Example 1:**
**Input:** nums = \[1,0,1,0,1\], goal = 2
**Output:** 4
**Exp... | dolphin | [
0.00004029617048217915,
0.031221307814121246,
-0.02534649521112442,
-0.02003595046699047,
0.050314683467149734,
-0.014541956596076488,
-0.04866637662053108,
0.04531712085008621,
0.031781647354364395,
-0.0018774314085021615,
0.030392013490200043,
0.01933886855840683,
-0.03531330078840256,
-... | 0.836613 | 0.779262 | 0.057351 |
Please write the following solution using Scala:
You are given an integer array `coins` of length `n` which represents the `n` coins that you own. The value of the `ith` coin is `coins[i]`. You can **make** some value `x` if you can choose some of your `n` coins such that their values sum up to `x`.
Return the _maximu... | dolphin | [
0.02423826977610588,
0.0339510552585125,
-0.014327647164463997,
-0.017622875049710274,
0.04014559090137482,
-0.02983270399272442,
-0.038812119513750076,
0.042862419039011,
0.02736484818160534,
-0.03171093016862869,
0.0358847975730896,
0.033375829458236694,
-0.026424838230013847,
-0.0220470... | 0.845959 | 0.78155 | 0.064409 |
Please write the following solution using Julia:
You are given a **0-indexed** 2D integer array of `events` where `events[i] = [startTimei, endTimei, valuei]`. The `ith` event starts at `startTimei` and ends at `endTimei`, and if you attend this event, you will receive a value of `valuei`. You can choose **at most** **... | dolphin | [
0.01134471409022808,
0.011623166501522064,
-0.03851907700300217,
-0.03149980679154396,
0.021384920924901962,
-0.01831689104437828,
-0.05418645218014717,
0.0633891299366951,
0.05987930670380592,
0.0011496940860524774,
0.03737257793545723,
0.032547254115343094,
-0.017750771716237068,
0.00087... | 0.841136 | 0.78705 | 0.054087 |
Please explain the reasoning behind the following solution and provide code in javascript:
Given an integer array `nums` of size `n`, return _the minimum number of moves required to make all array elements equal_.
In one move, you can increment or decrement an element of the array by `1`.
Test cases are designed so t... | dolphin | [
0.015260206535458565,
0.010220908559858799,
-0.03379369527101517,
-0.0356692299246788,
0.04896062985062599,
-0.027578463777899742,
-0.013783508911728859,
0.06190531700849533,
0.03193031623959541,
-0.03303724527359009,
0.041415464133024216,
0.010155713185667992,
-0.04228278249502182,
-0.008... | 0.849597 | 0.796004 | 0.053593 |
Please explain the following problem in detail and provide code in Kotlin:
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` and `bi` in t... | dolphin | [
0.005740446504205465,
0.025598809123039246,
-0.013820922002196312,
-0.04627687484025955,
0.035700421780347824,
-0.03139100596308708,
-0.011302923783659935,
0.05149175226688385,
0.027450699359178543,
0.005868865177035332,
0.03701965883374214,
0.024311279878020287,
-0.04083516076207161,
0.01... | 0.841929 | 0.784487 | 0.057442 |
Please write the following solution using python:
There are `n` children standing in a line. Each child is assigned a rating value given in the integer array `ratings`.
You are giving candies to these children subjected to the following requirements:
* Each child must have at least one candy.
* Children with a hi... | dolphin | [
0.0073904977180063725,
0.02358347550034523,
-0.020465707406401634,
-0.03342911973595619,
0.0361253060400486,
-0.03126607462763786,
-0.025320520624518394,
0.05048650875687599,
0.011359313502907753,
-0.013445678167045116,
0.022124797105789185,
0.021418403834104538,
-0.03941408544778824,
-0.0... | 0.844498 | 0.785476 | 0.059022 |
Please explain the reasoning behind the following solution and provide code in c++:
Given an integer array nums, return all the triplets `[nums[i], nums[j], nums[k]]` such that `i != j`, `i != k`, and `j != k`, and `nums[i] + nums[j] + nums[k] == 0`.
Notice that the solution set must not contain duplicate triplets.
*... | dolphin | [
0.02305031754076481,
0.01396335382014513,
-0.0168631412088871,
-0.029186410829424858,
0.05889573693275452,
-0.012639460153877735,
-0.01369894202798605,
0.09641164541244507,
0.03151658549904823,
-0.010203732177615166,
0.02125115506350994,
0.02571933902800083,
-0.032850947231054306,
-0.03422... | 0.838252 | 0.784154 | 0.054099 |
Please explain the reasoning behind the following solution and provide code in Object Pascal:
You are given a **0-indexed** integer array `nums`. You can apply the following operation any number of times:
* Pick any element from `nums` and put it at the end of `nums`.
The prefix sum array of `nums` is an array `pre... | dolphin | [
0.006491746287792921,
0.015418941155076027,
-0.013142194598913193,
-0.025230437517166138,
0.03277182951569557,
-0.022138210013508797,
-0.009694972075521946,
0.06238141655921936,
0.04650288447737694,
-0.002815058920532465,
0.01051956508308649,
0.031777624040842056,
-0.01934436708688736,
-0.... | 0.850162 | 0.791993 | 0.058169 |
Please write the following solution using Kotlin:
Given a string `s` which consists of lowercase or uppercase letters, return _the length of the **longest palindrome**_ that can be built with those letters.
Letters are **case sensitive**, for example, `"Aa "` is not considered a palindrome here.
**Example 1:**
**Inp... | dolphin | [
0.02704785019159317,
0.023939965292811394,
-0.0053129903972148895,
-0.03632138669490814,
0.03990284353494644,
-0.031994614750146866,
-0.014703971333801746,
0.04307585954666138,
0.0366223119199276,
-0.03057599999010563,
0.02711169607937336,
0.03481370583176613,
-0.022688264027237892,
-0.029... | 0.824383 | 0.769169 | 0.055213 |
Please write the following solution using Scheme:
You are given an integer `num`. You can swap two digits at most once to get the maximum valued number.
Return _the maximum valued number you can get_.
**Example 1:**
**Input:** num = 2736
**Output:** 7236
**Explanation:** Swap the number 2 and the number 7.
**Exampl... | dolphin | [
0.03430624306201935,
0.034096311777830124,
-0.006586301140487194,
-0.023330677300691605,
0.030635342001914978,
-0.021219272166490555,
-0.039269354194402695,
0.035604044795036316,
0.025371871888637543,
-0.02655346319079399,
0.03497466817498207,
0.04091537743806839,
-0.04027533531188965,
-0.... | 0.81542 | 0.761405 | 0.054015 |
Please write the following solution using Swift:
Given an integer array `nums`, return _the number of **subarrays** filled with_ `0`.
A **subarray** is a contiguous non-empty sequence of elements within an array.
**Example 1:**
**Input:** nums = \[1,3,0,0,2,0,0,4\]
**Output:** 6
**Explanation:**
There are 4 occurre... | dolphin | [
0.0053048329427838326,
0.02830401062965393,
-0.026533454656600952,
-0.012549239210784435,
0.04248140752315521,
-0.016963927075266838,
-0.03173919767141342,
0.05564383044838905,
0.038873299956321716,
-0.003936398774385452,
0.01980486512184143,
0.01645645685493946,
-0.03866935893893242,
-0.0... | 0.834794 | 0.781373 | 0.053421 |
Please write the following solution using Dart:
Given an integer `n`, return the count of all numbers with unique digits, `x`, where `0 <= x < 10n`.
**Example 1:**
**Input:** n = 2
**Output:** 91
**Explanation:** The answer should be the total numbers in the range of 0 <= x < 100, excluding 11,22,33,44,55,66,77,88,99... | dolphin | [
0.0014509106986224651,
0.008783831261098385,
-0.02870812825858593,
-0.030988022685050964,
0.03412685915827751,
-0.02204236388206482,
-0.022841759026050568,
0.03615744411945343,
0.027724571526050568,
-0.003999343607574701,
0.00848071463406086,
0.030777674168348312,
-0.040170818567276,
-0.02... | 0.820271 | 0.762245 | 0.058025 |
Please focus on the efficiency of this problem and provide code in Fortran:
A magical string `s` consists of only `'1'` and `'2'` and obeys the following rules:
* The string s is magical because concatenating the number of contiguous occurrences of characters `'1'` and `'2'` generates the string `s` itself.
The fir... | dolphin | [
0.03178045153617859,
0.036380279809236526,
-0.017423907294869423,
-0.046908311545848846,
0.03011840581893921,
-0.029276832938194275,
-0.026325268670916557,
0.07488121837377548,
0.021054519340395927,
-0.005158096551895142,
0.02014041505753994,
0.02992250956594944,
-0.02296224981546402,
-0.0... | 0.8445 | 0.790433 | 0.054067 |
Please write the following solution using javascript:
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 a... | dolphin | [
0.02370184101164341,
0.029457025229930878,
-0.029298726469278336,
-0.03238198161125183,
0.03435146063566208,
-0.008177574723958969,
-0.020957255735993385,
0.06696312874555588,
0.035562530159950256,
-0.003821717109531164,
0.02422870323061943,
0.017233489081263542,
-0.024563251063227654,
-0.... | 0.835003 | 0.776154 | 0.058849 |
Please focus on the algorithm of this problem and provide code in c++:
There is only one character `'A'` on the screen of a notepad. You can perform one of two operations on this notepad for each step:
* Copy All: You can copy all the characters present on the screen (a partial copy is not allowed).
* Paste: You c... | dolphin | [
0.026426242664456367,
0.012198484502732754,
0.0012386722955852747,
-0.019395288079977036,
0.034645672887563705,
-0.006031230557709932,
-0.013677069917321205,
0.10148998349905014,
0.021575061604380608,
-0.02194375917315483,
0.02714458853006363,
0.041841134428977966,
-0.01215593982487917,
-0... | 0.836912 | 0.782733 | 0.054178 |
Please explain the reasoning behind the following solution and provide code in Visual Basic .NET:
Given a **circular integer array** `nums` of length `n`, return _the maximum possible sum of a non-empty **subarray** of_ `nums`.
A **circular array** means the end of the array connects to the beginning of the array. For... | dolphin | [
0.009170182049274445,
0.031157003715634346,
-0.02799932472407818,
-0.025140123441815376,
0.03597336262464523,
-0.017580941319465637,
-0.018482739105820656,
0.05923081934452057,
0.0380588099360466,
-0.002894108649343252,
0.04097004234790802,
0.039702508598566055,
-0.037590425461530685,
-0.0... | 0.844539 | 0.786213 | 0.058326 |
Please focus on the efficiency of this problem and provide code in Dart:
There is an undirected graph consisting of `n` nodes numbered from `0` to `n - 1`. You are given a **0-indexed** integer array `vals` of length `n` where `vals[i]` denotes the value of the `ith` node.
You are also given a 2D integer array `edges`... | dolphin | [
0.002581619657576084,
0.036535561084747314,
-0.02010747417807579,
-0.0325019471347332,
0.02882126159965992,
-0.014569563791155815,
-0.03151850774884224,
0.05764761194586754,
0.03518303856253624,
-0.008772147819399834,
0.04129146412014961,
0.02802063524723053,
-0.007734701968729496,
-0.0087... | 0.84202 | 0.787041 | 0.054979 |
Please write the following solution using python:
You are given two **0-indexed** integer arrays `nums1` and `nums2` of equal length `n` and a positive integer `k`. You must choose a **subsequence** of indices from `nums1` of length `k`.
For chosen indices `i0`, `i1`, ..., `ik - 1`, your **score** is defined as:
* ... | dolphin | [
0.015504807233810425,
0.037714798003435135,
-0.028830276802182198,
-0.026937086135149002,
0.044515132904052734,
-0.025708457455039024,
-0.031891144812107086,
0.043664902448654175,
0.028145011514425278,
-0.006858165375888348,
0.023734232410788536,
0.02408858947455883,
-0.028035512194037437,
... | 0.850243 | 0.787006 | 0.063236 |
Please explain the following problem in detail and provide code in PHP:
You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once.
Return _the single element that appears only once_.
Your solution must run in `O(log n)` time a... | dolphin | [
0.012759160250425339,
0.03709716349840164,
-0.01947704516351223,
-0.015930231660604477,
0.02453996241092682,
-0.024092677980661392,
-0.033621896058321,
0.07504242658615112,
0.03281595930457115,
-0.003963200841099024,
0.024220751598477364,
0.00019358778081368655,
-0.02973964996635914,
-0.01... | 0.846993 | 0.790591 | 0.056402 |
Please explain the following problem in detail and provide code in c++:
There is a bag that consists of items, each item has a number `1`, `0`, or `-1` written on it.
You are given four **non-negative** integers `numOnes`, `numZeros`, `numNegOnes`, and `k`.
The bag initially contains:
* `numOnes` items with `1`s w... | dolphin | [
0.028007790446281433,
0.023627132177352905,
-0.02569965273141861,
-0.01879701390862465,
0.05378812924027443,
-0.011996963992714882,
-0.01864611729979515,
0.08359671384096146,
0.042388733476400375,
-0.004954620264470577,
0.031029682606458664,
0.049997929483652115,
-0.024679558351635933,
-0.... | 0.841184 | 0.779482 | 0.061702 |
Please write the following solution using ANSI C:
You are given the `root` of a binary tree with `n` nodes where each `node` in the tree has `node.val` coins. There are `n` coins in total throughout the whole tree.
In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be ... | dolphin | [
0.022098446264863014,
0.03592367470264435,
-0.022458285093307495,
-0.03367775306105614,
0.013172159902751446,
-0.024810342118144035,
-0.01746385544538498,
0.08257605880498886,
0.012393954209983349,
-0.027071796357631683,
0.044126883149147034,
0.013571648858487606,
-0.02869986928999424,
-0.... | 0.841167 | 0.775847 | 0.06532 |
Please write the following solution using PHP:
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 node `... | dolphin | [
0.010542298667132854,
0.02166321501135826,
-0.031034234911203384,
-0.02552914433181286,
0.029516108334064484,
-0.03524278849363327,
-0.028735438361763954,
0.0693792849779129,
0.03568705916404724,
-0.018671955913305283,
0.03292538970708847,
0.004482789430767298,
-0.025854799896478653,
-0.01... | 0.839734 | 0.785729 | 0.054005 |
Please write the following solution using Kotlin:
You are given an array `nums` that consists of positive integers.
The **GCD** of a sequence of numbers is defined as the greatest integer that divides **all** the numbers in the sequence evenly.
* For example, the GCD of the sequence `[4,6,16]` is `2`.
A **subseque... | dolphin | [
0.020422151312232018,
0.021288104355335236,
-0.009307872503995895,
-0.036228056997060776,
0.0350375659763813,
-0.025697652250528336,
-0.0300837904214859,
0.05454077944159508,
0.02776835486292839,
-0.019803402945399284,
0.01696702279150486,
0.021246539428830147,
-0.03761347383260727,
-0.010... | 0.84181 | 0.781091 | 0.06072 |
Please write the following solution using Objective-C:
Given an integer array `nums` of length `n`, return `true` if there is a triplet `(i, j, k)` which satisfies the following conditions:
* `0 < i, i + 1 < j, j + 1 < k < n - 1`
* The sum of subarrays `(0, i - 1)`, `(i + 1, j - 1)`, `(j + 1, k - 1)` and `(k + 1, ... | dolphin | [
0.012839872390031815,
0.02400016039609909,
-0.031218810006976128,
-0.03373987600207329,
0.05609375238418579,
-0.021344132721424103,
-0.014088905416429043,
0.07932688295841217,
0.00961344875395298,
-0.016093717887997627,
0.021133042871952057,
0.01816878281533718,
-0.03631825000047684,
-0.02... | 0.849851 | 0.791078 | 0.058773 |
Please write the following solution using Kotlin:
Given the `root` of a binary tree, return _the length of the longest consecutive path in the tree_.
A consecutive path is a path where the values of the consecutive nodes in the path differ by one. This path can be either increasing or decreasing.
* For example, `[1... | dolphin | [
0.03020230121910572,
0.028461262583732605,
-0.012095079757273197,
-0.042233798652887344,
0.025998931378126144,
-0.03570181503891945,
-0.02508554980158806,
0.05298278108239174,
0.04063477739691734,
-0.029301820322871208,
0.03851357102394104,
0.014552508480846882,
-0.028958050534129143,
0.00... | 0.834271 | 0.77598 | 0.058291 |
Please explain the following problem in detail and provide code in Scala:
You are given an integer array `nums`. You must perform **exactly one** operation where you can **replace** one element `nums[i]` with `nums[i] * nums[i]`.
Return _the **maximum** possible subarray sum after **exactly one** operation_. The subar... | dolphin | [
0.025118613615632057,
0.04456368088722229,
-0.011388389393687248,
-0.02513733133673668,
0.046822451055049896,
-0.0224755872040987,
-0.014752659946680069,
0.05639396235346794,
0.03234996274113655,
-0.010728755965828896,
0.026899496093392372,
0.029857076704502106,
-0.01863652467727661,
-0.01... | 0.845232 | 0.788381 | 0.056852 |
Please explain the following problem in detail and provide code in F#:
Given an integer array `nums`, partition it into two (contiguous) subarrays `left` and `right` so that:
* Every element in `left` is less than or equal to every element in `right`.
* `left` and `right` are non-empty.
* `left` has the smallest... | dolphin | [
0.022909974679350853,
0.025084055960178375,
-0.026431266218423843,
-0.026480019092559814,
0.03426877409219742,
-0.014179868623614311,
-0.014306862838566303,
0.06243276223540306,
0.038925349712371826,
-0.0012537383008748293,
0.021475080400705338,
0.029004758223891258,
-0.03755035623908043,
... | 0.845453 | 0.790536 | 0.054916 |
Please focus on the efficiency of this problem and provide code in Scheme:
Given an array `nums` of integers and integer `k`, return the maximum `sum` such that there exists `i < j` with `nums[i] + nums[j] = sum` and `sum < k`. If no `i`, `j` exist satisfying this equation, return `-1`.
**Example 1:**
**Input:** nums... | dolphin | [
0.01531958393752575,
0.029925720766186714,
-0.0369318425655365,
-0.02904014103114605,
0.04530154913663864,
-0.002944941632449627,
-0.030778072774410248,
0.054947514086961746,
0.029276400804519653,
-0.010285774245858192,
0.032945435494184494,
0.03920435905456543,
-0.031854260712862015,
0.00... | 0.841576 | 0.778151 | 0.063425 |
Please write the following solution using Elixir:
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 this operation **only once*... | dolphin | [
0.024257006123661995,
0.041834019124507904,
-0.01364776212722063,
-0.02165296860039234,
0.026235640048980713,
-0.026391709223389626,
-0.03033013641834259,
0.04590754956007004,
0.03788904473185539,
-0.007305874954909086,
0.02827463671565056,
0.0416378453373909,
-0.04270485043525696,
-0.0030... | 0.845187 | 0.778532 | 0.066655 |
Please explain the following problem in detail and provide code in C#:
You are given a 2D integer array `intervals` where `intervals[i] = [lefti, righti]` represents the **inclusive** interval `[lefti, righti]`.
You have to divide the intervals into one or more **groups** such that each interval is in **exactly** one ... | dolphin | [
0.036069534718990326,
0.024421634152531624,
-0.030470412224531174,
-0.018533067777752876,
0.03873378038406372,
-0.023605097085237503,
-0.031866852194070816,
0.07512278854846954,
0.026791887357831,
-0.017827952280640602,
0.018833469599485397,
0.007611677050590515,
-0.034926727414131165,
-0.... | 0.836731 | 0.782551 | 0.05418 |
Please write the following solution using ANSI C:
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 _the **number of non-empty subarrays*... | dolphin | [
-0.0028399587608873844,
0.03397281840443611,
-0.020818104967474937,
-0.02414782904088497,
0.047998469322919846,
-0.018023226410150528,
-0.04289799556136131,
0.06701967120170593,
0.01803375966846943,
0.0009744633571244776,
0.02506353333592415,
0.016159549355506897,
-0.048912085592746735,
-0... | 0.840741 | 0.77275 | 0.067991 |
Please write the following solution using Julia:
Alice and Bob take turns playing a game, with Alice starting first.
Initially, there are `n` stones in a pile. On each player's turn, that player makes a _move_ consisting of removing **any** non-zero **square number** of stones in the pile.
Also, if a player cannot ma... | dolphin | [
0.031323421746492386,
0.0375591441988945,
-0.0375138595700264,
-0.03789433091878891,
0.02168158069252968,
-0.035863492637872696,
-0.013558539561927319,
0.08196414262056351,
0.03841693326830864,
-0.011814174242317677,
0.023622943088412285,
0.02336304262280464,
-0.03355460241436958,
-0.04133... | 0.832586 | 0.774789 | 0.057797 |
Please explain the following problem in detail and provide code in Groovy:
You are given an integer array `coins` of length `n` which represents the `n` coins that you own. The value of the `ith` coin is `coins[i]`. You can **make** some value `x` if you can choose some of your `n` coins such that their values sum up t... | dolphin | [
0.018138296902179718,
0.028900543227791786,
-0.014589279890060425,
-0.02388230338692665,
0.03888522833585739,
-0.035217080265283585,
-0.037362147122621536,
0.03289090096950531,
0.035411491990089417,
-0.03223362937569618,
0.03937205672264099,
0.039880476891994476,
-0.03297711908817291,
-0.0... | 0.841371 | 0.785278 | 0.056093 |
Please focus on the algorithm of this problem and provide code in Dart:
Given an array `nums` of integers, return _the length of the longest arithmetic subsequence in_ `nums`.
**Note** that:
* A **subsequence** is an array that can be derived from another array by deleting some or no elements without changing the o... | dolphin | [
0.018522754311561584,
0.021816015243530273,
-0.013347746804356575,
-0.03518551215529442,
0.036385346204042435,
-0.013777576386928558,
-0.04778806492686272,
0.05936463549733162,
0.03938766196370125,
-0.014782941900193691,
0.012782358564436436,
0.030800344422459602,
-0.02915087342262268,
0.0... | 0.831861 | 0.778072 | 0.053789 |
Please focus on the functionality of this problem and provide code in PHP:
The **XOR sum** of a list is the bitwise `XOR` of all its elements. If the list only contains one element, then its **XOR sum** will be equal to this element.
* For example, the **XOR sum** of `[1,2,3,4]` is equal to `1 XOR 2 XOR 3 XOR 4 = 4`... | dolphin | [
0.008629491552710533,
0.03362072631716728,
-0.02877870388329029,
-0.029972592368721962,
0.0314449816942215,
-0.015144199132919312,
-0.029457567259669304,
0.06469576060771942,
0.04414600133895874,
-0.01050886232405901,
0.014105666428804398,
0.020013397559523582,
-0.03505479171872139,
-0.022... | 0.833532 | 0.778495 | 0.055037 |
Please explain the following problem in detail and provide code in javascript:
You are given an array `nums`. You can rotate it by a non-negative integer `k` so that the array becomes `[nums[k], nums[k + 1], ... nums[nums.length - 1], nums[0], nums[1], ..., nums[k-1]]`. Afterward, any entries that are less than or equa... | dolphin | [
0.00850876234471798,
0.03978052735328674,
-0.021510932594537735,
-0.010177831165492535,
0.023223834112286568,
-0.020465442910790443,
-0.02507787197828293,
0.041738301515579224,
0.027745405212044716,
-0.0013880337355658412,
0.020299196243286133,
0.021222542971372604,
-0.04279905557632446,
0... | 0.8422 | 0.782016 | 0.060184 |
translate this code to Scheme:
```c
#include <stdio.h>
#include <stdlib.h>
#define MAX_N 100005
typedef struct {
int min_set[MAX_N];
int mid_set[MAX_N];
int max_set[MAX_N];
int q[MAX_N];
int m, k;
long long sum;
} MKAverage;
void init(MKAverage* kv, int m, int k) {
kv->m = m;
kv->k = ... | dolphin | [
0.04327530041337013,
0.026276269927620888,
-0.018570834770798683,
-0.03687342256307602,
0.03143469989299774,
-0.03553357347846031,
-0.038976170122623444,
0.0672614723443985,
0.030941840261220932,
-0.023048432543873787,
0.02207818627357483,
0.023851633071899414,
-0.03868994861841202,
-0.014... | 0.843141 | 0.782962 | 0.060179 |
Please explain the reasoning behind the following solution and provide code in R:
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 ... | dolphin | [
0.026922712102532387,
0.03093576990067959,
-0.03133053332567215,
-0.033827412873506546,
0.030968064442276955,
-0.03397534787654877,
-0.05081864446401596,
0.0600164569914341,
0.04175115376710892,
-0.006269799545407295,
0.02670421078801155,
0.02901865541934967,
-0.03874244913458824,
-0.00090... | 0.839129 | 0.784101 | 0.055028 |
Please explain the following problem in detail and provide code in R:
You are given an integer array `nums`. A number `x` is **lonely** when it appears only **once**, and no **adjacent** numbers (i.e. `x + 1` and `x - 1)` appear in the array.
Return _**all** lonely numbers in_ `nums`. You may return the answer in **an... | dolphin | [
0.018420008942484856,
0.04376104846596718,
-0.017032107338309288,
-0.024479765444993973,
0.032488979399204254,
-0.016543926671147346,
-0.018503965809941292,
0.053936682641506195,
0.03684832900762558,
-0.0027401859406381845,
0.012636792846024036,
0.01159646362066269,
-0.03666061535477638,
-... | 0.833691 | 0.771855 | 0.061836 |
Please write the following solution using java:
Given a positive integer `n`, return the number of the integers in the range `[0, n]` whose binary representations **do not** contain consecutive ones.
**Example 1:**
**Input:** n = 5
**Output:** 5
**Explanation:**
Here are the non-negative integers <= 5 with their corr... | dolphin | [
0.010275959968566895,
0.013559429906308651,
-0.02592748962342739,
-0.0361129529774189,
0.03849979117512703,
-0.022415082901716232,
-0.046882208436727524,
0.04109736904501915,
0.03339767083525658,
-0.02336426079273224,
0.030239982530474663,
0.01871461048722267,
-0.037655722349882126,
-0.039... | 0.831629 | 0.76617 | 0.06546 |
Please write the following solution using Go:
Given an integer array `nums` and an integer `k`, return _the length of the shortest non-empty **subarray** of_ `nums` _with a sum of at least_ `k`. If there is no such **subarray**, return `-1`.
A **subarray** is a **contiguous** part of an array.
**Example 1:**
**Input... | dolphin | [
0.004635784775018692,
0.030810115858912468,
-0.023835141211748123,
-0.03478873521089554,
0.04791219159960747,
-0.009375613182783127,
-0.029995456337928772,
0.04496727138757706,
0.04450980946421623,
0.0001637608220335096,
0.028727978467941284,
0.0256941057741642,
-0.032641276717185974,
-0.0... | 0.841499 | 0.78309 | 0.058409 |
Please write the following solution using R:
Given the `root` of a binary tree, return _the length of the longest consecutive path in the tree_.
A consecutive path is a path where the values of the consecutive nodes in the path differ by one. This path can be either increasing or decreasing.
* For example, `[1,2,3,... | dolphin | [
0.03515852987766266,
0.035189785063266754,
-0.01867489144206047,
-0.04439523071050644,
0.027051592245697975,
-0.03520466387271881,
-0.03493790701031685,
0.061111632734537125,
0.043742116540670395,
-0.021158238872885704,
0.03366662189364433,
0.016155768185853958,
-0.03674570471048355,
-0.01... | 0.824426 | 0.764105 | 0.060321 |
Please explain the following problem in detail and provide code in C#:
You are given an integer array `nums` and an integer `x`. In one operation, you can either remove the leftmost or the rightmost element from the array `nums` and subtract its value from `x`. Note that this **modifies** the array for future operation... | dolphin | [
0.014693250879645348,
0.026722144335508347,
-0.04129284992814064,
-0.025968659669160843,
0.02589607425034046,
-0.03565746918320656,
-0.021451011300086975,
0.08960177004337311,
0.06556180864572525,
-0.007234448567032814,
0.015812227502465248,
0.01898258365690708,
-0.030576089397072792,
-0.0... | 0.842312 | 0.784862 | 0.05745 |
Please write the following solution using Scheme:
You are given `n` rectangles represented by a **0-indexed** 2D integer array `rectangles`, where `rectangles[i] = [widthi, heighti]` denotes the width and height of the `ith` rectangle.
Two rectangles `i` and `j` (`i < j`) are considered **interchangeable** if they hav... | dolphin | [
0.018078766763210297,
0.04358823224902153,
-0.041057929396629333,
-0.01768920198082924,
0.03399725630879402,
-0.010072489269077778,
-0.03419376164674759,
0.046006154268980026,
0.03476117551326752,
-0.028957420960068703,
0.012509709224104881,
0.021948805078864098,
-0.0294149462133646,
-0.01... | 0.841101 | 0.779738 | 0.061363 |
Please explain the following problem in detail and provide code in Kotlin:
A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits `s` and all we know is that all integers in the array were in the range `[1, k]` and there are no leadin... | dolphin | [
0.01795956864953041,
0.02790164202451706,
-0.015543730929493904,
-0.035929255187511444,
0.044330984354019165,
-0.04258820787072182,
-0.0219669658690691,
0.06048119068145752,
0.027951091527938843,
-0.014087341725826263,
0.024469982832670212,
0.03533877059817314,
-0.026385387405753136,
-0.02... | 0.851853 | 0.798552 | 0.053301 |
Please write the following solution using javascript:
Given an array of integers `arr` and an integer `k`. Find the _least number of unique integers_ after removing **exactly** `k` elements**.**
**Example 1:**
**Input:** arr = \[5,5,4\], k = 1
**Output:** 1
**Explanation**: Remove the single 4, only 5 is left.
**Exa... | dolphin | [
0.0299211572855711,
0.0454874262213707,
-0.028926247730851173,
-0.03683341667056084,
0.05063657462596893,
-0.031346265226602554,
-0.018506791442632675,
0.050990648567676544,
0.053997546434402466,
-0.016049711033701897,
0.022740283980965614,
-0.011037013493478298,
-0.009508874267339706,
-0.... | 0.845322 | 0.781407 | 0.063915 |
Please focus on the functionality of this problem and provide code in Objective-C:
A **self-dividing number** is a number that is divisible by every digit it contains.
* For example, `128` is **a self-dividing number** because `128 % 1 == 0`, `128 % 2 == 0`, and `128 % 8 == 0`.
A **self-dividing number** is not all... | dolphin | [
0.028950726613402367,
0.03414852172136307,
-0.023312708362936974,
-0.03881438076496124,
0.02853647619485855,
-0.027063028886914253,
-0.01624438539147377,
0.06588475406169891,
0.03003895841538906,
-0.01590544730424881,
0.03681870922446251,
0.01551225408911705,
-0.03536909446120262,
-0.01246... | 0.82929 | 0.775927 | 0.053363 |
Please focus on the efficiency of this problem and provide code in 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, while the number of stones is **more than one**, they will do the following:
1. Choose an integer `x > 1`, and... | dolphin | [
0.028617946431040764,
0.016228390857577324,
-0.04211723431944847,
-0.03165145963430405,
0.014809141866862774,
-0.022341014817357063,
-0.03703697770833969,
0.09682054072618484,
0.051641978323459625,
-0.022837018594145775,
0.03623485565185547,
0.031043628230690956,
-0.02707606367766857,
-0.0... | 0.836862 | 0.783059 | 0.053804 |
Please explain the following problem in detail and provide code in java:
Given a **1-indexed** array of integers `numbers` that is already **_sorted in non-decreasing order_**, find two numbers such that they add up to a specific `target` number. Let these two numbers be `numbers[index1]` and `numbers[index2]` where `1... | dolphin | [
0.02089151367545128,
0.028530603274703026,
-0.03025147132575512,
-0.02966197580099106,
0.05293189734220505,
-0.008602828718721867,
-0.014513474889099598,
0.0389682799577713,
0.01225755363702774,
-0.02067261002957821,
0.021892637014389038,
0.02638745866715908,
-0.04442991688847542,
-0.00377... | 0.842857 | 0.787457 | 0.055399 |
Please explain the reasoning behind the following solution and provide code in Kotlin:
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 `per... | dolphin | [
0.006375913042575121,
0.04188081994652748,
-0.016742492094635963,
-0.03143369033932686,
0.0463741309940815,
-0.026033524423837662,
-0.02086181752383709,
0.06625102460384369,
0.026129286736249924,
-0.017816608771681786,
0.016571082174777985,
0.011972371488809586,
-0.034629225730895996,
-0.0... | 0.841353 | 0.783849 | 0.057504 |
Please explain the reasoning behind the following solution and provide code in python:
A decimal number is called **deci-binary** if each of its digits is either `0` or `1` without any leading zeros. For example, `101` and `1100` are **deci-binary**, while `112` and `3001` are not.
Given a string `n` that represents a... | dolphin | [
-0.012297556735575199,
0.011385914869606495,
-0.038305915892124176,
-0.03894972801208496,
0.04613124579191208,
-0.047262683510780334,
-0.029087960720062256,
0.020901482552289963,
0.01874796859920025,
0.0027678334154188633,
0.017539726570248604,
0.02496686950325966,
-0.038083288818597794,
-... | 0.825927 | 0.768345 | 0.057582 |
Please explain the following problem in detail and provide code in Scheme:
Given a **0-indexed** integer array `nums` of length `n` and an integer `k`, return _the **number of pairs**_ `(i, j)` _such that:_
* `0 <= i < j <= n - 1` _and_
* `nums[i] * nums[j]` _is divisible by_ `k`.
**Example 1:**
**Input:** nums ... | dolphin | [
0.023673322051763535,
0.04451765492558479,
-0.042776163667440414,
-0.017940059304237366,
0.05966324359178543,
-0.021395079791545868,
-0.027882037684321404,
0.060783758759498596,
0.022080272436141968,
-0.0058931526727974415,
0.01692035049200058,
0.015868332237005234,
-0.023985814303159714,
... | 0.845083 | 0.7795 | 0.065582 |
Please write the following solution using ANSI C:
Given an integer array `instructions`, you are asked to create a sorted array from the elements in `instructions`. You start with an empty container `nums`. For each element from **left to right** in `instructions`, insert it into `nums`. The **cost** of each insertion ... | dolphin | [
0.020300453528761864,
0.028523724526166916,
-0.02952812798321247,
-0.01401810348033905,
0.03573238477110863,
-0.022381111979484558,
-0.03584481403231621,
0.07798995077610016,
0.043212514370679855,
-0.016612276434898376,
0.03218752518296242,
0.012915315106511116,
-0.032789088785648346,
-0.0... | 0.83877 | 0.779858 | 0.058912 |
Please explain the following problem in detail and provide code in F#:
You are given an integer array `nums`. A number `x` is **lonely** when it appears only **once**, and no **adjacent** numbers (i.e. `x + 1` and `x - 1)` appear in the array.
Return _**all** lonely numbers in_ `nums`. You may return the answer in **a... | dolphin | [
0.018271636217832565,
0.035592783242464066,
-0.008732588030397892,
-0.02952389232814312,
0.040377359837293625,
-0.02824832685291767,
-0.007230023387819529,
0.05841455236077309,
0.04299280792474747,
-0.007774513680487871,
0.020213549956679344,
0.009572258219122887,
-0.04504253715276718,
-0.... | 0.844321 | 0.786693 | 0.057628 |
Please write the following solution using Kotlin:
Given a **0-indexed** integer array `nums`, return _the **smallest** index_ `i` _of_ `nums` _such that_ `i mod 10 == nums[i]`_, or_ `-1` _if such index does not exist_.
`x mod y` denotes the **remainder** when `x` is divided by `y`.
**Example 1:**
**Input:** nums = \... | dolphin | [
0.018093416467308998,
0.03937223181128502,
-0.011992291547358036,
-0.021743034943938255,
0.04450094327330589,
-0.035231463611125946,
-0.022023402154445648,
0.05396261811256409,
0.025970352813601494,
-0.024168364703655243,
0.02101222239434719,
0.011699492111802101,
-0.03091926872730255,
-0.... | 0.845823 | 0.791815 | 0.054008 |
Please explain the reasoning behind the following solution and provide code in Scala:
You are given a 0-indexed integer array `nums`. You are allowed to permute `nums` into a new array `perm` of your choosing.
We define the **greatness** of `nums` be the number of indices `0 <= i < nums.length` for which `perm[i] > nu... | dolphin | [
0.01393030397593975,
0.035147666931152344,
0.0010556001216173172,
-0.027961870655417442,
0.027863822877407074,
-0.020265772938728333,
-0.03098478354513645,
0.048702843487262726,
0.017047347500920296,
-0.011902899481356144,
0.011834925040602684,
0.023977983742952347,
-0.03246411681175232,
0... | 0.840581 | 0.786842 | 0.053739 |
Please explain the reasoning behind the following solution and provide code in Scheme:
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... | dolphin | [
0.02862890623509884,
0.015405042096972466,
-0.035580866038799286,
-0.020680096000432968,
0.060545094311237335,
-0.0011394880712032318,
-0.03817049041390419,
0.031722839921712875,
0.02218426577746868,
-0.013172238133847713,
0.03331011161208153,
0.03336433321237564,
-0.04042933136224747,
-0.... | 0.843023 | 0.785007 | 0.058017 |
Please focus on the efficiency of this problem and provide code in PHP:
You are given a **0-indexed** integer array `nums`. An index `i` is part of a **hill** in `nums` if the closest non-equal neighbors of `i` are smaller than `nums[i]`. Similarly, an index `i` is part of a **valley** in `nums` if the closest non-equa... | dolphin | [
0.004433671943843365,
0.03850293904542923,
-0.03181416168808937,
-0.006299272179603577,
0.031374748796224594,
-0.019794076681137085,
-0.03222363814711571,
0.07834557443857193,
0.034485649317502975,
-0.024464264512062073,
0.026870930567383766,
0.021050557494163513,
-0.023278309032320976,
-0... | 0.850191 | 0.795113 | 0.055078 |
Please write the following solution using C#:
Given a positive integer `n`, find and return _the **longest distance** between any two **adjacent**_ `1`_'s in the binary representation of_ `n`_. If there are no two adjacent_ `1`_'s, return_ `0`_._
Two `1`'s are **adjacent** if there are only `0`'s separating them (poss... | dolphin | [
0.03551959991455078,
0.025446586310863495,
-0.025219112634658813,
-0.03230937570333481,
0.0256233848631382,
-0.0408116839826107,
-0.04092932119965553,
0.07657638937234879,
0.04140277951955795,
-0.016435129567980766,
0.03431358560919762,
0.021066341549158096,
-0.03983054682612419,
-0.010772... | 0.843416 | 0.778679 | 0.064737 |
Please explain the following problem in detail and provide code in Scheme:
You are given an integer array `nums` of `2 * n` integers. You need to partition `nums` into **two** arrays of length `n` to **minimize the absolute difference** of the **sums** of the arrays. To partition `nums`, put each element of `nums` into... | dolphin | [
0.02538725547492504,
0.020320460200309753,
-0.022030990570783615,
-0.016909854486584663,
0.02792484685778618,
-0.010683245025575161,
-0.02782139740884304,
0.034533772617578506,
0.04936022311449051,
-0.018902981653809547,
0.018304508179426193,
0.02135799080133438,
-0.04327339306473732,
0.00... | 0.840177 | 0.782854 | 0.057323 |
convert this code to java:
```julia
function can_win(nums::Vector{Int})
n = length(nums)
dp = [0 for i in 1:n, j in 1:n]
for i in 1:n
dp[i,i] = nums[i]
end
for len in 2:n
for i in 1:n-len+1
j = i+len-1
if nums[i] - dp[i+1,j] > nums[j] - dp[i,j-1]
... | dolphin | [
0.007742667105048895,
0.024668151512742043,
-0.026216546073555946,
-0.03326983004808426,
0.025915440171957016,
-0.030780043452978134,
-0.0192069411277771,
0.059788867831230164,
0.02913776785135269,
-0.01924869418144226,
0.028440894559025764,
0.03990274295210838,
-0.03751441836357117,
-0.01... | 0.847431 | 0.793919 | 0.053512 |
Please write the following solution using 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:**
The even elements are 0, 2... | dolphin | [
0.023364519700407982,
0.025379693135619164,
-0.021670812740921974,
-0.03297189995646477,
0.035561058670282364,
0.0007183122797869146,
-0.02863236702978611,
0.10234265774488449,
0.03828781843185425,
-0.006931541953235865,
0.025632070377469063,
0.02993103489279747,
-0.01870128884911537,
-0.0... | 0.833805 | 0.766614 | 0.067191 |
Please explain the following problem in detail and provide code in R:
A sequence of numbers is called **arithmetic** if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence `s` is arithmetic if and only if `s[i+1] - s[i] == s[1] - s[0]` f... | dolphin | [
0.0325971283018589,
0.026074739173054695,
-0.033325087279081345,
-0.036411184817552567,
0.02911355346441269,
-0.015513469465076923,
-0.016965927556157112,
0.08686269074678421,
0.047196660190820694,
-0.016328487545251846,
0.004102807492017746,
0.026960762217640877,
-0.021527912467718124,
-0... | 0.838185 | 0.784725 | 0.05346 |
Please focus on the algorithm of this problem and provide code in PHP:
You have an array `arr` of length `n` where `arr[i] = (2 * i) + 1` for all valid values of `i` (i.e., `0 <= i < n`).
In one operation, you can select two indices `x` and `y` where `0 <= x, y < n` and subtract `1` from `arr[x]` and add `1` to `arr[y... | dolphin | [
0.0213563684374094,
0.025214126333594322,
-0.026325739920139313,
-0.03719733655452728,
0.027487820014357567,
-0.033859238028526306,
-0.022575857117772102,
0.08750700205564499,
0.03171306475996971,
-0.02206086926162243,
0.023988110944628716,
0.01988981105387211,
-0.022644102573394775,
-0.01... | 0.844199 | 0.785006 | 0.059193 |
Please explain the reasoning behind the following solution and provide code in java:
Given an array of non-negative integers `arr`, you are initially positioned at `start` index of the array. When you are at index `i`, you can jump to `i + arr[i]` or `i - arr[i]`, check if you can reach to **any** index with value 0.
... | dolphin | [
0.017619958147406578,
0.024122215807437897,
-0.015718752518296242,
-0.018247202038764954,
0.046502735465765,
-0.02903793938457966,
-0.01319702249020338,
0.06849093735218048,
0.03587725758552551,
-0.027895387262105942,
0.01693921722471714,
0.011336526833474636,
-0.02216455526649952,
-0.0215... | 0.844135 | 0.787531 | 0.056604 |
Please explain the following problem in detail and provide code in Scala:
Given an integer array `arr` and an integer `k`, modify the array by repeating it `k` times.
For example, if `arr = [1, 2]` and `k = 3` then the modified array will be `[1, 2, 1, 2, 1, 2]`.
Return the maximum sub-array sum in the modified array... | dolphin | [
0.024519208818674088,
0.03826707974076271,
-0.011566667817533016,
-0.039295513182878494,
0.05277428776025772,
-0.035241130739450455,
-0.01885695941746235,
0.043978750705718994,
0.02241768129169941,
-0.022151678800582886,
0.03027910739183426,
0.02517786994576454,
-0.0291312113404274,
0.0135... | 0.839518 | 0.782684 | 0.056834 |
Please explain the following problem in detail and provide code in Swift:
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'`... | dolphin | [
0.0005492460913956165,
0.013088680803775787,
-0.025712531059980392,
-0.031776782125234604,
0.028677884489297867,
-0.04017075151205063,
-0.04169996455311775,
0.04758425056934357,
0.03573375567793846,
-0.012945367023348808,
0.024545816704630852,
0.028341880068182945,
-0.04388997703790665,
-0... | 0.834603 | 0.780919 | 0.053684 |
Please write the following solution using Julia:
Given an integer array `nums` and an integer `k`, return _the_ `k` _most frequent elements_. You may return the answer in **any order**.
**Example 1:**
**Input:** nums = \[1,1,1,2,2,3\], k = 2
**Output:** \[1,2\]
**Example 2:**
**Input:** nums = \[1\], k = 1
**Output... | dolphin | [
0.026063311845064163,
0.04294529929757118,
-0.03211452439427376,
-0.02030389942228794,
0.04548193886876106,
-0.021349988877773285,
-0.018986452370882034,
0.05501985177397728,
0.026815140619874,
-0.0009184731752611697,
0.03268268331885338,
0.007962181232869625,
-0.012556741945445538,
0.0012... | 0.832498 | 0.767427 | 0.065071 |
Please write the following solution using Scala:
Given a positive integer `n`, return the number of the integers in the range `[0, n]` whose binary representations **do not** contain consecutive ones.
**Example 1:**
**Input:** n = 5
**Output:** 5
**Explanation:**
Here are the non-negative integers <= 5 with their cor... | dolphin | [
0.008486575447022915,
0.013557967729866505,
-0.01717355288565159,
-0.03882487118244171,
0.04254195839166641,
-0.024846715852618217,
-0.04191984236240387,
0.04615706950426102,
0.03003331646323204,
-0.019281992688775063,
0.028279224410653114,
0.023019913583993912,
-0.030196132138371468,
-0.0... | 0.838056 | 0.777813 | 0.060243 |
Please write the following solution using c++:
You are given a **weighted** tree consisting of `n` nodes numbered from `0` to `n - 1`.
The tree is **rooted** at node `0` and represented with a **2D** array `edges` of size `n` where `edges[i] = [pari, weighti]` indicates that node `pari` is the **parent** of node `i`, ... | dolphin | [
0.01952792890369892,
0.011101742275059223,
-0.018001431599259377,
-0.031681280583143234,
0.03464500606060028,
-0.022132858633995056,
-0.009286001324653625,
0.08248815685510635,
0.017623571678996086,
-0.000018658542103366926,
0.039248157292604446,
0.024581389501690865,
-0.024462727829813957,
... | 0.843482 | 0.781611 | 0.061871 |
Please focus on the efficiency of this problem and provide code in Objective-C:
Given an integer array `nums` and an integer `k`, return _the number of **subarrays** of_ `nums` _where the least common multiple of the subarray's elements is_ `k`.
A **subarray** is a contiguous non-empty sequence of elements within an a... | dolphin | [
0.009605037048459053,
0.04731137305498123,
-0.04731446132063866,
-0.0203517097979784,
0.04878988862037659,
-0.019783785566687584,
-0.03874693438410759,
0.055260930210351944,
0.013784248381853104,
-0.02240542694926262,
0.03253757208585739,
0.014420622028410435,
-0.016559582203626633,
-0.008... | 0.838225 | 0.776797 | 0.061428 |
Please write the following solution using Kotlin:
Given a `m x n` matrix `grid` which is sorted in non-increasing order both row-wise and column-wise, return _the number of **negative** numbers in_ `grid`.
**Example 1:**
**Input:** grid = \[\[4,3,2,-1\],\[3,2,1,-1\],\[1,1,-1,-2\],\[-1,-1,-2,-3\]\]
**Output:** 8
**Exp... | dolphin | [
0.0016058874316513538,
-0.004354808479547501,
-0.023774150758981705,
-0.04662257060408592,
0.03857303783297539,
-0.0435473658144474,
-0.03027603216469288,
0.056158922612667084,
0.03451643884181976,
-0.00946804042905569,
-0.005462620873004198,
0.024447165429592133,
-0.04580129683017731,
-0.... | 0.839171 | 0.780881 | 0.058291 |
Please write the following solution using Lisp:
Given an integer array `nums` of size `n`, return _the minimum number of moves required to make all array elements equal_.
In one move, you can increment or decrement an element of the array by `1`.
Test cases are designed so that the answer will fit in a **32-bit** int... | dolphin | [
0.014983193017542362,
0.01964917965233326,
-0.03285451605916023,
-0.04634947329759598,
0.04122188314795494,
-0.03272295370697975,
-0.014537359587848186,
0.05443431809544563,
0.03393073007464409,
-0.030450204387307167,
0.04667976498603821,
0.018940577283501625,
-0.04080962389707565,
-0.0253... | 0.851955 | 0.798074 | 0.05388 |
Please explain the following problem in detail and provide code in Scheme:
Given an `m x n` binary matrix `mat`, return _the length of the longest line of consecutive one in the matrix_.
The line could be horizontal, vertical, diagonal, or anti-diagonal.
**Example 1:**
**Input:** mat = \[\[0,1,1,0\],\[0,1,1,0\],\[0,... | dolphin | [
0.020411057397723198,
0.012160477228462696,
-0.02102987840771675,
-0.05694960057735443,
0.0416334792971611,
-0.02799258753657341,
-0.053806617856025696,
0.06083160638809204,
0.04756651073694229,
-0.02212115190923214,
0.022436657920479774,
0.014800329692661762,
-0.01997070387005806,
-0.0177... | 0.833637 | 0.771988 | 0.06165 |
Please explain the following problem in detail and provide code in Scheme:
You are given an integer array `nums`. You want to maximize the number of points you get by performing the following operation any number of times:
* Pick any `nums[i]` and delete it to earn `nums[i]` points. Afterwards, you must delete **eve... | dolphin | [
0.024844545871019363,
0.018719254061579704,
-0.020468417555093765,
-0.02200629748404026,
0.02527056261897087,
-0.043417561799287796,
-0.033070921897888184,
0.03839615732431412,
0.04183417931199074,
-0.00692156283184886,
0.01657768525183201,
0.021249322220683098,
-0.03638265281915665,
-0.00... | 0.851212 | 0.786857 | 0.064355 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.