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 efficiency of this problem and provide code in python:
A **ramp** in an integer array `nums` is a pair `(i, j)` for which `i < j` and `nums[i] <= nums[j]`. The **width** of such a ramp is `j - i`.
Given an integer array `nums`, return _the maximum width of a **ramp** in_ `nums`. If there is no **ra... | dolphin | [
0.02546778880059719,
0.03317945823073387,
-0.030206669121980667,
-0.010148826986551285,
0.03740217164158821,
-0.013023867271840572,
-0.05157884210348129,
0.06310659646987915,
0.024909131228923798,
-0.02756756916642189,
0.024361515417695045,
0.02594899758696556,
-0.024746671319007874,
-0.00... | 0.842983 | 0.77883 | 0.064153 |
Please focus on the functionality of this problem and provide code in Visual Basic .NET:
The [Hamming distance](https://en.wikipedia.org/wiki/Hamming_distance) between two integers is the number of positions at which the corresponding bits are different.
Given an integer array `nums`, return _the sum of **Hamming dist... | dolphin | [
0.01397072896361351,
0.021259253844618797,
-0.02175699919462204,
-0.014902854338288307,
0.04954783618450165,
-0.030733607709407806,
-0.02667497843503952,
0.05786596238613129,
0.04336938261985779,
-0.017223838716745377,
0.026953572407364845,
0.03349652886390686,
-0.02658741921186447,
-0.026... | 0.832741 | 0.778749 | 0.053992 |
Please write the following solution using Objective-C:
Given an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_.
**Example 1:**
**Input:** n = 20
**Output:** 1
**Explanation:** The only positive number (<= 20) with at least 1 repeated digit is 11... | dolphin | [
0.019465189427137375,
0.013023363426327705,
-0.02653765119612217,
-0.04953886941075325,
0.029517902061343193,
-0.03739184886217117,
-0.03368299454450607,
0.04815002530813217,
0.010872464627027512,
-0.009893372654914856,
0.03479359671473503,
0.026278093457221985,
-0.05150047689676285,
-0.01... | 0.822565 | 0.759707 | 0.062858 |
Please write the following solution using java:
Suppose an array of length `n` sorted in ascending order is **rotated** between `1` and `n` times. For example, the array `nums = [0,1,2,4,5,6,7]` might become:
* `[4,5,6,7,0,1,2]` if it was rotated `4` times.
* `[0,1,2,4,5,6,7]` if it was rotated `7` times.
Notice ... | dolphin | [
0.007318888325244188,
0.03612957522273064,
-0.022422684356570244,
-0.014357090927660465,
0.039476510137319565,
-0.02529715932905674,
-0.03115854598581791,
0.0461822971701622,
0.015957916155457497,
-0.013796028681099415,
0.027888283133506775,
0.0030937574338167906,
-0.03018534742295742,
-0.... | 0.840452 | 0.777986 | 0.062466 |
Please write the following solution using java:
You are given an integer `n`. There is a **complete binary tree** with `2n - 1` nodes. The root of that tree is the node with the value `1`, and every node with a value `val` in the range `[1, 2n - 1 - 1]` has two children where:
* The left node has the value `2 * val`... | dolphin | [
0.02170063927769661,
0.01680665649473667,
-0.04348386079072952,
-0.03252655640244484,
0.02317182347178459,
-0.04012206196784973,
-0.014519104734063148,
0.05966468155384064,
0.027233079075813293,
-0.01819792576134205,
0.0469825454056263,
0.00833347998559475,
-0.031277041882276535,
-0.011655... | 0.845925 | 0.785949 | 0.059976 |
Please explain the following problem in detail and provide code in c++:
You are given a **0-indexed** integer array `nums`. You can rearrange the elements of `nums` to **any order** (including the given order).
Let `prefix` be the array containing the prefix sums of `nums` after rearranging it. In other words, `prefix... | dolphin | [
0.009461158886551857,
0.01662507839500904,
-0.005105342250317335,
-0.0258741807192564,
0.02730368636548519,
-0.001225264510139823,
-0.033172447234392166,
0.07369772344827652,
0.034963659942150116,
0.0032145166769623756,
0.013366371393203735,
0.026080293580889702,
-0.036593079566955566,
-0.... | 0.842184 | 0.778669 | 0.063516 |
Please explain the reasoning behind the following solution and provide code in c++:
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`... | dolphin | [
0.017822396010160446,
0.03035852499306202,
-0.02128269150853157,
-0.03074086643755436,
0.043773774057626724,
-0.016945211216807365,
-0.039187949150800705,
0.08082940429449081,
0.03038879483938217,
-0.01508481614291668,
0.031258728355169296,
0.03641846776008606,
-0.04062972590327263,
0.0017... | 0.847143 | 0.791051 | 0.056092 |
Please explain the following problem in detail and provide code in javascript:
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 si... | dolphin | [
0.012753237038850784,
0.02685556747019291,
-0.02825726382434368,
-0.023029621690511703,
0.05160867050290108,
-0.012796108610928059,
-0.011753681115806103,
0.04979858919978142,
0.03790430724620819,
-0.012607844546437263,
0.023575982078909874,
0.0219010878354311,
-0.049002811312675476,
-0.00... | 0.84248 | 0.784689 | 0.057791 |
Please write the following solution using Visual Basic .NET:
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.
**Exa... | dolphin | [
0.019057687371969223,
0.0322190523147583,
-0.03972924128174782,
-0.02724909409880638,
0.047921545803546906,
-0.007464490830898285,
-0.013567301444709301,
0.06753426790237427,
0.04813385009765625,
-0.011345612816512585,
0.03770838677883148,
0.03223346173763275,
-0.0409964919090271,
-0.00256... | 0.836779 | 0.77601 | 0.060769 |
Please explain the following problem in detail and provide code in java:
Given a digit string `s`, return _the number of **unique substrings** of_ `s` _where every digit appears the same number of times._
**Example 1:**
**Input:** s = "1212 "
**Output:** 5
**Explanation:** The substrings that meet the requirements a... | dolphin | [
0.00481129577383399,
0.009467567317187786,
-0.04310973361134529,
-0.02355656400322914,
0.03165311738848686,
-0.042000286281108856,
-0.014589370228350163,
0.03775788098573685,
0.009199636988341808,
0.008198448456823826,
0.02536238729953766,
0.016305075958371162,
-0.033384162932634354,
0.006... | 0.832438 | 0.772038 | 0.060401 |
Please explain the following problem in detail and provide code in Haskell:
You are given an array of integers `nums` and an integer `target`.
Return _the number of **non-empty** subsequences of_ `nums` _such that the sum of the minimum and maximum element on it is less or equal to_ `target`. Since the answer may be t... | dolphin | [
0.012189295142889023,
0.0032267863862216473,
-0.0200901348143816,
-0.03397433087229729,
0.06166441738605499,
-0.006576915271580219,
-0.025977738201618195,
0.03982190042734146,
0.02704232931137085,
-0.00679716095328331,
0.018245253711938858,
0.04127485677599907,
-0.037831421941518784,
-0.02... | 0.846757 | 0.790563 | 0.056194 |
Please focus on the algorithm of this problem and provide code in Mojo:
Given an integer array `nums`, find the subarray with the largest sum, and return _its sum_.
**Example 1:**
**Input:** nums = \[-2,1,-3,4,-1,2,1,-5,4\]
**Output:** 6
**Explanation:** The subarray \[4,-1,2,1\] has the largest sum 6.
**Example 2:*... | dolphin | [
0.019558504223823547,
0.028430147096514702,
-0.021876664832234383,
-0.031198443844914436,
0.032852038741111755,
-0.02083609439432621,
-0.03185120224952698,
0.039544131606817245,
0.029125366359949112,
-0.008863872848451138,
0.029674161225557327,
0.03171837329864502,
-0.043623365461826324,
-... | 0.835813 | 0.77948 | 0.056333 |
Please write the following solution using Objective-C:
You are given an array `arr` which consists of only zeros and ones, divide the array into **three non-empty parts** such that all of these parts represent the same binary value.
If it is possible, return any `[i, j]` with `i + 1 < j`, such that:
* `arr[0], arr[... | dolphin | [
0.030247783288359642,
0.04455798119306564,
-0.020176148042082787,
-0.03818430379033089,
0.0492255724966526,
-0.034246914088726044,
-0.032834697514772415,
0.0736301839351654,
0.024757128208875656,
-0.019889242947101593,
0.035423483699560165,
-0.003393298014998436,
-0.04246458411216736,
-0.0... | 0.847099 | 0.790712 | 0.056386 |
Please write the following solution using c++:
You have `n` dice, and each die has `k` faces numbered from `1` to `k`.
Given three integers `n`, `k`, and `target`, return _the number of possible ways (out of the_ `kn` _total ways)_ _to roll the dice, so the sum of the face-up numbers equals_ `target`. Since the answer... | dolphin | [
0.03125721588730812,
0.03274524211883545,
-0.028227323666214943,
-0.0316111259162426,
0.049402978271245956,
0.0032492659520357847,
-0.019547080621123314,
0.06953737884759903,
0.03454343229532242,
-0.011716948822140694,
0.036545176059007645,
0.04860634356737137,
-0.031872913241386414,
-0.00... | 0.832774 | 0.775709 | 0.057066 |
Please focus on the efficiency of this problem and provide code in Scala:
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 s... | dolphin | [
0.04587969183921814,
0.05104765295982361,
-0.006253421772271395,
-0.017750028520822525,
0.02874576486647129,
-0.019729549065232277,
-0.026683222502470016,
0.04411964863538742,
0.03533429279923439,
-0.0062998258508741856,
0.01620906963944435,
0.040247842669487,
-0.03724086284637451,
-0.0361... | 0.834045 | 0.778569 | 0.055476 |
Please focus on the functionality of this problem and provide code in Haskell:
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 a... | dolphin | [
0.009592807851731777,
0.02604869194328785,
-0.023282472044229507,
-0.028158463537693024,
0.04827611893415451,
-0.010400901548564434,
-0.022203458473086357,
0.03711656481027603,
0.04072396829724312,
-0.007742602843791246,
0.027959810569882393,
0.026512259617447853,
-0.024662911891937256,
-0... | 0.845914 | 0.789431 | 0.056483 |
Please write the following solution using PHP:
Given an integer `n`, return _the number of structurally unique **BST'**s (binary search trees) which has exactly_ `n` _nodes of unique values from_ `1` _to_ `n`.
**Example 1:**
**Input:** n = 3
**Output:** 5
**Example 2:**
**Input:** n = 1
**Output:** 1
**Constraints... | dolphin | [
0.017517469823360443,
0.029158519580960274,
-0.048989225178956985,
-0.02469746395945549,
0.03606247156858444,
-0.03427063673734665,
-0.012834643945097923,
0.04700522497296333,
0.043291062116622925,
-0.006952034775167704,
0.024943523108959198,
0.029587237164378166,
-0.0390600711107254,
-0.0... | 0.835249 | 0.777348 | 0.057902 |
Please write the following solution using Visual Basic .NET:
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 define... | dolphin | [
0.008924974128603935,
0.0323176272213459,
-0.025128867477178574,
-0.025669092312455177,
0.043812114745378494,
-0.029955660924315453,
-0.022007491439580917,
0.07189230620861053,
0.04427352920174599,
-0.013770466670393944,
0.028581783175468445,
0.028681112453341484,
-0.03754142299294472,
-0.... | 0.851756 | 0.789736 | 0.062021 |
Please focus on the functionality of this problem and provide code in Objective-C:
Given an `n x n` integer matrix `grid`, return _the minimum sum of a **falling path with non-zero shifts**_.
A **falling path with non-zero shifts** is a choice of exactly one element from each row of `grid` such that no two elements ch... | dolphin | [
-0.012353905476629734,
0.019988378509879112,
-0.028669271618127823,
-0.035328034311532974,
0.05272435024380684,
-0.030131278559565544,
-0.026430638507008553,
0.05629119277000427,
0.03500732034444809,
-0.019107984378933907,
0.03136206045746803,
-0.0002633736585266888,
-0.039556462317705154,
... | 0.845385 | 0.79097 | 0.054415 |
Please focus on the algorithm of this problem and provide code in java:
Given a 2D integer array `nums` where `nums[i]` is a non-empty array of **distinct** positive integers, return _the list of integers that are present in **each array** of_ `nums` _sorted in **ascending order**_.
**Example 1:**
**Input:** nums = \... | dolphin | [
0.010343579575419426,
0.02801242657005787,
-0.02206149324774742,
-0.00428636372089386,
0.03708002343773842,
-0.031332410871982574,
-0.021656330674886703,
0.04361625760793686,
0.025157496333122253,
-0.018950825557112694,
0.029297364875674248,
0.013490799814462662,
-0.03076508454978466,
-0.0... | 0.841289 | 0.781214 | 0.060075 |
Please explain the following problem in detail and provide code in java:
A delivery company wants to build a new service center in a new city. The company knows the positions of all the customers in this city on a 2D-Map and wants to build the new center in a position such that **the sum of the euclidean distances to a... | dolphin | [
0.0016532100271433592,
0.032324377447366714,
-0.03474866598844528,
-0.03758508712053299,
0.052403777837753296,
-0.026511231437325478,
-0.033267393708229065,
0.004461401607841253,
0.0455256886780262,
-0.01569100096821785,
0.03873654082417488,
0.01940828375518322,
-0.01874203234910965,
-0.01... | 0.834543 | 0.779565 | 0.054978 |
Please write the following solution using Fortran:
You are given an array `nums` consisting of **positive** integers.
Return _the number of **subarrays** of_ `nums` _that are in **strictly increasing** order._
A **subarray** is a **contiguous** part of an array.
**Example 1:**
**Input:** nums = \[1,3,5,4,4,6\]
**Ou... | dolphin | [
0.019057685509324074,
0.040124304592609406,
-0.014242933131754398,
-0.02280876599252224,
0.037322599440813065,
-0.004870840348303318,
-0.03849238529801369,
0.06488578766584396,
0.026017874479293823,
-0.01342835370451212,
0.01751144416630268,
0.015222311019897461,
-0.05840853229165077,
-0.0... | 0.841238 | 0.785405 | 0.055832 |
Please focus on the algorithm of this problem and provide code in c++:
There are `n` cities numbered from `1` to `n`. You are given an array `edges` of size `n-1`, where `edges[i] = [ui, vi]` represents a bidirectional edge between cities `ui` and `vi`. There exists a unique path between each pair of cities. In other w... | dolphin | [
0.0026247166097164154,
0.013596848584711552,
-0.019036466255784035,
-0.01724381186068058,
0.017546022310853004,
-0.007555691059678793,
-0.02275773510336876,
0.07877635955810547,
0.035381630063056946,
-0.010285450145602226,
0.044390078634023666,
0.03633647412061691,
-0.018816614523530006,
-... | 0.838508 | 0.77939 | 0.059118 |
Please write the following solution using python:
Given a binary array `nums`, you should delete one element from it.
Return _the size of the longest non-empty subarray containing only_ `1`_'s in the resulting array_. Return `0` if there is no such subarray.
**Example 1:**
**Input:** nums = \[1,1,0,1\]
**Output:** 3... | dolphin | [
0.018462521955370903,
0.03668573498725891,
-0.03631310537457466,
-0.03611522167921066,
0.039848506450653076,
-0.030081283301115036,
-0.04067198932170868,
0.05444474145770073,
0.03114934079349041,
-0.010133414529263973,
0.02259519137442112,
0.01187953632324934,
-0.026559336110949516,
-0.008... | 0.83791 | 0.777752 | 0.060158 |
Please explain the following problem in detail and provide code in python:
Given an integer `n`, return _all the structurally unique **BST'**s (binary search trees), which has exactly_ `n` _nodes of unique values from_ `1` _to_ `n`. Return the answer in **any order**.
**Example 1:**
**Input:** n = 3
**Output:** \[\[1... | dolphin | [
0.027919232845306396,
0.03280719369649887,
-0.039094243198633194,
-0.020090145990252495,
0.029186880216002464,
-0.043610457330942154,
-0.0068123009987175465,
0.03162452578544617,
0.04040590673685074,
-0.0173497311770916,
0.029975704848766327,
0.023667411878705025,
-0.03242131322622299,
-0.... | 0.848153 | 0.794497 | 0.053656 |
Please write the following solution using C#:
Given the `root` of a binary tree, return the most frequent **subtree sum**. If there is a tie, return all the values with the highest frequency in any order.
The **subtree sum** of a node is defined as the sum of all the node values formed by the subtree rooted at that no... | dolphin | [
0.020536713302135468,
0.023803401738405228,
-0.035631775856018066,
-0.020988933742046356,
0.017044303938746452,
-0.03399091958999634,
0.001975082093849778,
0.06646022200584412,
0.019159017130732536,
0.00700864102691412,
0.0386057123541832,
0.01737101562321186,
-0.04065492004156113,
0.00327... | 0.826337 | 0.766116 | 0.060222 |
Please write the following solution using Go:
Given a positive integer `n`, find the **pivot integer** `x` such that:
* The sum of all elements between `1` and `x` inclusively equals the sum of all elements between `x` and `n` inclusively.
Return _the pivot integer_ `x`. If no such integer exists, return `-1`. It i... | dolphin | [
0.011239512823522091,
0.02750798873603344,
-0.017208561301231384,
-0.024546576663851738,
0.027006838470697403,
-0.031824078410863876,
-0.011188295669853687,
0.059999529272317886,
0.03632171452045441,
-0.011266790330410004,
0.03572152554988861,
0.02720777317881584,
-0.0348646380007267,
-0.0... | 0.838486 | 0.784776 | 0.053709 |
Please explain the reasoning behind the following solution and provide code in java:
The **product difference** between two pairs `(a, b)` and `(c, d)` is defined as `(a * b) - (c * d)`.
* For example, the product difference between `(5, 6)` and `(2, 7)` is `(5 * 6) - (2 * 7) = 16`.
Given an integer array `nums`, c... | dolphin | [
0.030184492468833923,
0.03288239613175392,
-0.029153794050216675,
-0.01504684891551733,
0.057967621833086014,
-0.01918296329677105,
-0.049517855048179626,
0.045145098119974136,
0.03716392070055008,
-0.016220148652791977,
0.02354441210627556,
0.03888367861509323,
-0.03320692107081413,
-0.01... | 0.846004 | 0.785319 | 0.060685 |
Please focus on the functionality of this problem and provide code in c++:
Given an integer array `nums` and an integer `k`, return `true` if it is possible to divide this array into `k` non-empty subsets whose sums are all equal.
**Example 1:**
**Input:** nums = \[4,3,2,3,5,2,1\], k = 4
**Output:** true
**Explanatio... | dolphin | [
0.013956381008028984,
0.018674619495868683,
-0.03001057542860508,
-0.03021191619336605,
0.050479911267757416,
-0.00997171550989151,
0.0001037782640196383,
0.09440089017152786,
0.016106434166431427,
-0.012236976996064186,
0.028945183381438255,
0.020287655293941498,
-0.02571067586541176,
0.0... | 0.835906 | 0.771562 | 0.064344 |
Please write the following solution using c++:
You are given an integer array `nums` and an integer `k`. You can partition the array into **at most** `k` non-empty adjacent subarrays. The **score** of a partition is the sum of the averages of each subarray.
Note that the partition must use every integer in `nums`, and... | dolphin | [
0.015453943982720375,
0.013144632801413536,
-0.04299897700548172,
-0.016652049496769905,
0.03906935825943947,
-0.007941018790006638,
-0.0336107537150383,
0.0690227523446083,
0.03665153309702873,
-0.007816392928361893,
0.040646303445100784,
0.033150672912597656,
-0.029414381831884384,
0.009... | 0.832735 | 0.763308 | 0.069427 |
Please focus on the algorithm of this problem and provide code in Scala:
You are given a **0-indexed** integer array `nums`. In one operation, you can:
* Choose two different indices `i` and `j` such that `0 <= i, j < nums.length`.
* Choose a non-negative integer `k` such that the `kth` bit (**0-indexed**) in the ... | dolphin | [
0.0064312731847167015,
0.04254920780658722,
-0.03265105187892914,
-0.011845181696116924,
0.04604649543762207,
-0.03693158179521561,
-0.03763207420706749,
0.05951046198606491,
0.04732976108789444,
-0.019638849422335625,
0.017275597900152206,
0.02430795319378376,
-0.025829311460256577,
-0.00... | 0.847802 | 0.793624 | 0.054178 |
Please write the following solution using Scheme:
Given a circular integer array `nums` (i.e., the next element of `nums[nums.length - 1]` is `nums[0]`), return _the **next greater number** for every element in_ `nums`.
The **next greater number** of a number `x` is the first greater number to its traversing-order nex... | dolphin | [
0.02503649704158306,
0.055222172290086746,
-0.016924068331718445,
-0.042359814047813416,
0.031173117458820343,
-0.013068467378616333,
-0.04394066333770752,
0.04565250501036644,
0.03472759947180748,
-0.011284422129392624,
0.03720366954803467,
0.02701554261147976,
-0.03966715931892395,
-0.00... | 0.83412 | 0.776684 | 0.057436 |
Please explain the reasoning behind the following solution and provide code in Go:
You have a graph of `n` nodes. You are given an integer `n` and an array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between `ai` and `bi` in the graph.
Return _the number of connected components in the graph_.
... | dolphin | [
0.017265427857637405,
0.02194279618561268,
-0.02596530318260193,
-0.028279412537813187,
0.02188168466091156,
-0.026513956487178802,
-0.019662421196699142,
0.05212114378809929,
0.04108013957738876,
0.011472952552139759,
0.023688320070505142,
0.01660914532840252,
-0.024263009428977966,
-0.02... | 0.840154 | 0.786715 | 0.053438 |
Please focus on the efficiency of this problem and provide code in Objective-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
**Explanat... | dolphin | [
0.022510593757033348,
0.02909424528479576,
-0.03621549904346466,
-0.027856534346938133,
0.024601252749562263,
-0.021750660613179207,
-0.032133277505636215,
0.0783473327755928,
0.028002509847283363,
-0.010511191561818123,
0.03178014978766441,
0.019301148131489754,
-0.028430866077542305,
-0.... | 0.838402 | 0.783672 | 0.05473 |
Please explain the reasoning behind the following solution and provide code in R:
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).
... | dolphin | [
0.007163661997765303,
0.02693268656730652,
-0.036950066685676575,
-0.04105985164642334,
0.04397375136613846,
-0.027691513299942017,
-0.023038048297166824,
0.05073945224285126,
0.027055131271481514,
-0.007023880258202553,
0.01072224322706461,
0.04217005893588066,
-0.03590402752161026,
-0.01... | 0.836916 | 0.782945 | 0.053971 |
Please write the following solution using ANSI C:
Given the `root` of a binary tree, return _the number of **uni-value**_ _subtrees_.
A **uni-value subtree** means all nodes of the subtree have the same value.
**Example 1:**
**Input:** root = \[5,1,5,5,5,null,5\]
**Output:** 4
**Example 2:**
**Input:** root = \[\]... | dolphin | [
0.010137039236724377,
0.03566437587141991,
-0.04159623011946678,
-0.02177451364696026,
0.03096429444849491,
-0.04006965458393097,
0.0010341310407966375,
0.07428193837404251,
0.02562348172068596,
-0.018956689164042473,
0.03652050346136093,
0.011174221523106098,
-0.03904035687446594,
-0.0238... | 0.831454 | 0.771609 | 0.059845 |
Please focus on the functionality of this problem and provide code in javascript:
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 `edg... | dolphin | [
-0.003213281976059079,
0.021708380430936813,
-0.019864654168486595,
-0.018717672675848007,
0.030796097591519356,
-0.03142191842198372,
-0.021601028740406036,
0.05570688471198082,
0.024402763694524765,
-0.006181016098707914,
0.024707138538360596,
0.013024273328483105,
-0.011981776915490627,
... | 0.851134 | 0.795931 | 0.055203 |
Please explain the following problem in detail and provide code in Objective-C:
You have a graph of `n` nodes. You are given an integer `n` and an array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between `ai` and `bi` in the graph.
Return _the number of connected components in the graph_.
**E... | dolphin | [
0.029222402721643448,
0.025023432448506355,
-0.035045597702264786,
-0.021637894213199615,
0.02003982663154602,
-0.02659325674176216,
-0.020248709246516228,
0.053161125630140305,
0.027294883504509926,
0.004767289385199547,
0.03201739117503166,
0.012460381723940372,
-0.02607826143503189,
-0.... | 0.838743 | 0.772901 | 0.065842 |
Please write the following solution using ANSI C:
You are standing at position `0` on an infinite number line. There is a destination at position `target`.
You can make some number of moves `numMoves` so that:
* On each move, you can either go left or right.
* During the `ith` move (starting from `i == 1` to `i =... | dolphin | [
0.011317973025143147,
0.027770496904850006,
-0.014138581231236458,
-0.03955671191215515,
0.030657339841127396,
-0.005889158230274916,
-0.04949327930808067,
0.06491350382566452,
0.029903756454586983,
-0.026425933465361595,
0.040104374289512634,
0.023727182298898697,
-0.0286412350833416,
-0.... | 0.843805 | 0.780736 | 0.063069 |
Please explain the following problem in detail and provide code in java:
You are given a string `s` consisting of lowercase letters and an integer `k`. We call a string `t` **ideal** if the following conditions are satisfied:
* `t` is a **subsequence** of the string `s`.
* The absolute difference in the alphabet o... | dolphin | [
0.02613549865782261,
0.02359517477452755,
-0.0252530500292778,
-0.03847729042172432,
0.04320676252245903,
-0.0506376177072525,
-0.020711755380034447,
0.026606446132063866,
0.03638583794236183,
-0.029646899551153183,
0.03358009457588196,
0.014501834288239479,
-0.027532313019037247,
-0.00151... | 0.831136 | 0.773218 | 0.057919 |
Please write the following solution using ANSI C:
You are given two arrays `rowSum` and `colSum` of non-negative integers where `rowSum[i]` is the sum of the elements in the `ith` row and `colSum[j]` is the sum of the elements of the `jth` column of a 2D matrix. In other words, you do not know the elements of the matri... | dolphin | [
0.011393791995942593,
0.02473699115216732,
-0.03454316779971123,
-0.0402323342859745,
0.05414872244000435,
-0.02780931629240513,
-0.02575964480638504,
0.07522360980510712,
0.03996700048446655,
-0.025995919480919838,
0.010808276943862438,
0.0016822144389152527,
-0.028207123279571533,
-0.027... | 0.824982 | 0.769604 | 0.055378 |
Please write the following solution using java:
Given a string `s`, return _the number of **distinct** substrings of_ `s`.
A **substring** of a string is obtained by deleting any number of characters (possibly zero) from the front of the string and any number (possibly zero) from the back of the string.
**Example 1:*... | dolphin | [
0.012541606090962887,
0.020114716142416,
-0.03377256542444229,
-0.02789747342467308,
0.0394478477537632,
-0.052873075008392334,
-0.009964578785002232,
0.03928982466459274,
0.04087767004966736,
0.0003473675751592964,
0.020696071907877922,
0.0030675274319946766,
-0.03532804548740387,
-0.0089... | 0.82987 | 0.771331 | 0.058539 |
Please focus on the algorithm of this problem and provide code in Mojo:
Suppose you have `n` integers labeled `1` through `n`. A permutation of those `n` integers `perm` (**1-indexed**) is considered a **beautiful arrangement** if for every `i` (`1 <= i <= n`), **either** of the following is true:
* `perm[i]` is div... | dolphin | [
0.029135948047041893,
0.035934437066316605,
-0.021240297704935074,
-0.03927379846572876,
0.033805277198553085,
-0.03338417038321495,
-0.04071519523859024,
0.06380725651979446,
0.027270304039120674,
-0.009582350961863995,
0.035921379923820496,
0.013549315743148327,
-0.027883144095540047,
-0... | 0.84614 | 0.788842 | 0.057298 |
Please explain the following problem in detail and provide code in Objective-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... | dolphin | [
0.009548434056341648,
0.028858046978712082,
-0.017366116866469383,
-0.027346786111593246,
0.030880896374583244,
-0.02403007447719574,
-0.03714251518249512,
0.06149236485362053,
0.033421970903873444,
-0.01702340692281723,
0.028727294877171516,
0.041663505136966705,
-0.02576790377497673,
-0.... | 0.842912 | 0.787413 | 0.055499 |
Please write the following solution using Rust:
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 should be in the range `[2,... | dolphin | [
0.054188571870326996,
0.04800586402416229,
0.001462601707316935,
-0.031451474875211716,
0.02149992436170578,
-0.016650386154651642,
-0.02191656082868576,
0.06002406030893326,
0.05427272990345955,
-0.0013284010346978903,
0.019439274445176125,
0.044486284255981445,
-0.0484408400952816,
-0.04... | 0.829446 | 0.776169 | 0.053276 |
Please write the following solution using Haskell:
You are given an integer `n` and an integer `start`.
Define an array `nums` where `nums[i] = start + 2 * i` (**0-indexed**) and `n == nums.length`.
Return _the bitwise XOR of all elements of_ `nums`.
**Example 1:**
**Input:** n = 5, start = 0
**Output:** 8
**Explan... | dolphin | [
0.029303930699825287,
0.02323297969996929,
-0.030645983293652534,
-0.02408110350370407,
0.028422707691788673,
-0.036535993218421936,
-0.016081804409623146,
0.0657915398478508,
0.04243560507893562,
-0.017876340076327324,
0.02290462516248226,
0.027486527338624,
-0.049646370112895966,
-0.0432... | 0.839493 | 0.784686 | 0.054807 |
Please write the following solution using Dart:
You have an undirected, connected graph of `n` nodes labeled from `0` to `n - 1`. You are given an array `graph` where `graph[i]` is a list of all the nodes connected with node `i` by an edge.
Return _the length of the shortest path that visits every node_. You may start... | dolphin | [
0.00034452369436621666,
0.023761678487062454,
-0.005119809415191412,
-0.03352874517440796,
0.03371806815266609,
-0.029948538169264793,
-0.03309721127152443,
0.03453570976853371,
0.04280228912830353,
-0.009890112094581127,
0.028563817963004112,
0.019498195499181747,
0.002464540069922805,
-0... | 0.836878 | 0.781917 | 0.054961 |
Please explain the reasoning behind the following solution and provide code in Scheme:
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 m... | dolphin | [
0.03231599181890488,
0.037966568022966385,
-0.015445354394614697,
-0.04414091259241104,
0.05164308473467827,
-0.03766085207462311,
-0.031841930001974106,
0.044168345630168915,
0.03187151625752449,
-0.024805476889014244,
0.031232785433530807,
0.01720445603132248,
-0.03943958505988121,
0.015... | 0.839279 | 0.780327 | 0.058953 |
Please write the following solution using python:
You are given an array of integers `nums`, there is a sliding window of size `k` which is moving from the very left of the array to the very right. You can only see the `k` numbers in the window. Each time the sliding window moves right by one position.
Return _the max... | dolphin | [
0.03504492715001106,
0.03861382603645325,
-0.02582148090004921,
-0.027128079906105995,
0.04514859616756439,
-0.008754336275160313,
-0.04071853682398796,
0.045654285699129105,
0.031487926840782166,
-0.00374767673201859,
0.04547486454248428,
0.024099625647068024,
-0.041072532534599304,
0.019... | 0.83661 | 0.782221 | 0.054388 |
Please focus on the efficiency of this problem and provide code in c++:
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 remai... | dolphin | [
0.002358334604650736,
0.026616370305418968,
-0.02142510749399662,
-0.03171537443995476,
0.023235348984599113,
-0.031066883355379105,
-0.0346018522977829,
0.1051391214132309,
0.02721043862402439,
-0.012376775965094566,
0.019395289942622185,
0.031176142394542694,
-0.026586035266518593,
-0.00... | 0.839825 | 0.785226 | 0.054599 |
Please write the following solution using Elixir:
Given a **sorted** integer array `arr`, two integers `k` and `x`, return the `k` closest integers to `x` in the array. The result should also be sorted in ascending order.
An integer `a` is closer to `x` than an integer `b` if:
* `|a - x| < |b - x|`, or
* `|a - x|... | dolphin | [
0.042310699820518494,
0.0452105738222599,
-0.021606413647532463,
-0.034936439245939255,
0.03223105147480965,
-0.03643045946955681,
-0.022736655548214912,
0.033451806753873825,
0.04902021959424019,
-0.009736022911965847,
0.035974230617284775,
0.007785325404256582,
-0.023977704346179962,
-0.... | 0.830593 | 0.776347 | 0.054246 |
Please explain the following problem in detail and provide code in java:
You are given a string `num` consisting of digits only.
Return _the **largest palindromic** integer (in the form of a string) that can be formed using digits taken from_ `num`. It should not contain **leading zeroes**.
**Notes:**
* You do **n... | dolphin | [
0.014783636666834354,
0.02227720245718956,
-0.013258378952741623,
-0.03973591327667236,
0.019579533487558365,
-0.03397096320986748,
-0.006870676763355732,
0.029921503737568855,
0.021950727328658104,
-0.016017738729715347,
0.04386161267757416,
0.03732740506529808,
-0.04631933197379112,
-0.0... | 0.824809 | 0.764749 | 0.060059 |
Please write the following solution using F#:
You are given two **0-indexed** integer arrays `fronts` and `backs` of length `n`, where the `ith` card has the positive integer `fronts[i]` printed on the front and `backs[i]` printed on the back. Initially, each card is placed on a table such that the front number is faci... | dolphin | [
0.016088634729385376,
0.024806249886751175,
-0.029067479074001312,
-0.025168053805828094,
0.028509818017482758,
-0.013295736163854599,
-0.022490035742521286,
0.054771699011325836,
0.03394714742898941,
-0.01356690376996994,
0.008146226406097412,
0.027403321117162704,
-0.01625829003751278,
-... | 0.849916 | 0.796539 | 0.053376 |
Please write the following solution using Swift:
You are given an `m x n` integer matrix `grid`.
We define an **hourglass** as a part of the matrix with the following form:
Return _the **maximum** sum of the elements of an hourglass_.
**Note** that an hourglass cannot be rotated and must be entirely contained within... | dolphin | [
0.024544667452573776,
0.02304702438414097,
-0.0230429545044899,
-0.05063461884856224,
0.06683827191591263,
-0.027932612225413322,
-0.035358976572752,
0.05811575427651405,
0.03989407792687416,
-0.009051957167685032,
0.024061482399702072,
0.026694828644394875,
-0.025673894211649895,
-0.03329... | 0.823573 | 0.764702 | 0.058871 |
Please write the following solution using ANSI C:
Given an array of **distinct** integers `arr`, find all pairs of elements with the minimum absolute difference of any two elements.
Return a list of pairs in ascending order(with respect to pairs), each pair `[a, b]` follows
* `a, b` are from `arr`
* `a < b`
* `... | dolphin | [
0.032549355179071426,
0.03968144953250885,
-0.015308072790503502,
-0.04124584421515465,
0.04429426044225693,
-0.023235471919178963,
-0.04242691397666931,
0.06349387019872665,
0.04134073480963707,
-0.030482301488518715,
0.025933776050806046,
-0.0039775175973773,
-0.04831022024154663,
0.0016... | 0.832577 | 0.772422 | 0.060155 |
Please write the following solution using Scheme:
Given an `m x n` integer matrix `grid` where each entry is only `0` or `1`, return _the number of **corner rectangles**_.
A **corner rectangle** is four distinct `1`'s on the grid that forms an axis-aligned rectangle. Note that only the corners need to have the value `... | dolphin | [
0.014981914311647415,
0.04277893900871277,
-0.017954440787434578,
-0.03168487548828125,
0.03586813434958458,
-0.03577638417482376,
-0.04398363456130028,
0.0385277159512043,
0.03363991528749466,
-0.002265020040795207,
0.00724459532648325,
0.027185611426830292,
-0.02974073961377144,
-0.02331... | 0.830554 | 0.776246 | 0.054308 |
Please write the following solution using Fortran:
Given an unsorted array of integers `nums`, return _the length of the longest **continuous increasing subsequence** (i.e. subarray)_. The subsequence must be **strictly** increasing.
A **continuous increasing subsequence** is defined by two indices `l` and `r` (`l < r... | dolphin | [
0.026496626436710358,
0.04283542558550835,
-0.020918186753988266,
-0.032959189265966415,
0.03629890829324722,
-0.01854606345295906,
-0.039728932082653046,
0.07071460783481598,
0.04259348288178444,
-0.018603205680847168,
0.023548388853669167,
0.0196594949811697,
-0.033569954335689545,
0.012... | 0.833512 | 0.779233 | 0.054279 |
Please explain the reasoning behind the following solution and provide code in ANSI C:
The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on.
The **nume... | dolphin | [
0.016725100576877594,
0.03464158996939659,
-0.006844805553555489,
-0.056993111968040466,
0.04236654192209244,
-0.029710978269577026,
-0.018534619361162186,
0.05762003734707832,
0.027397308498620987,
-0.012550977990031242,
0.03484608605504036,
0.03219464793801308,
-0.04718589037656784,
-0.0... | 0.83711 | 0.780266 | 0.056844 |
Please focus on the functionality of this problem and provide code in Scheme:
The **numeric value** of a **lowercase character** is defined as its position `(1-indexed)` in the alphabet, so the numeric value of `a` is `1`, the numeric value of `b` is `2`, the numeric value of `c` is `3`, and so on.
The **numeric value... | dolphin | [
0.021645689383149147,
0.03358076512813568,
-0.0101474579423666,
-0.052048590034246445,
0.048847977072000504,
-0.032718293368816376,
-0.013416373170912266,
0.032852888107299805,
0.024446064606308937,
-0.008510350249707699,
0.03508545830845833,
0.03280799090862274,
-0.03635840117931366,
-0.0... | 0.841952 | 0.787222 | 0.05473 |
Please write the following solution using Ruby:
You are given an integer array `nums` and a **positive** integer `k`.
The **frequency score** of an array is the sum of the **distinct** values in the array raised to the power of their **frequencies**, taking the sum **modulo** `109 + 7`.
* For example, the frequency... | dolphin | [
0.015919189900159836,
0.036560963839292526,
-0.04326310753822327,
-0.03825543448328972,
0.038724757730960846,
-0.03455018252134323,
-0.024189623072743416,
0.029793718829751015,
0.0221497043967247,
-0.012733212672173977,
0.03546815365552902,
0.026031464338302612,
-0.030487794429063797,
0.01... | 0.835314 | 0.779302 | 0.056011 |
Please explain the following problem in detail and provide code in Scala:
You are given an integer array `gifts` denoting the number of gifts in various piles. Every second, you do the following:
* Choose the pile with the maximum number of gifts.
* If there is more than one pile with the maximum number of gifts, ... | dolphin | [
-0.0035265309270471334,
0.03796632960438728,
-0.016259321942925453,
-0.04152194783091545,
0.026992855593562126,
-0.049899548292160034,
-0.020719241350889206,
0.033936746418476105,
0.024560149759054184,
-0.01800023950636387,
0.04425773769617081,
0.02949463576078415,
-0.03299838677048683,
0.... | 0.846498 | 0.792893 | 0.053605 |
Please focus on the algorithm of this problem and provide code in Dart:
Given an integer array `arr`, return _the number of distinct bitwise ORs of all the non-empty subarrays of_ `arr`.
The bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise OR of a subarray of one integer is that ... | dolphin | [
0.004980807658284903,
0.013599026016891003,
-0.024627268314361572,
-0.008533804677426815,
0.02445201948285103,
-0.034549281001091,
-0.03874201327562332,
0.0551757887005806,
0.04809538275003433,
-0.012410935945808887,
0.02223086729645729,
0.006577023770660162,
-0.02604120410978794,
-0.00404... | 0.840044 | 0.786233 | 0.053811 |
Please write the following solution using ANSI C:
Given an integer `n`, return all the **strobogrammatic numbers** that are of length `n`. You may return the answer in **any order**.
A **strobogrammatic number** is a number that looks the same when rotated `180` degrees (looked at upside down).
**Example 1:**
**Inpu... | dolphin | [
0.01704125851392746,
0.025269765406847,
-0.013625089079141617,
-0.048428721725940704,
0.020522257313132286,
-0.037027180194854736,
-0.028962381184101105,
0.05367129296064377,
0.019071977585554123,
-0.008121125400066376,
0.035710640251636505,
0.024923278018832207,
-0.05562608689069748,
-0.0... | 0.829775 | 0.767147 | 0.062629 |
Please write the following solution using c++:
You are given an integer array `banned` and two integers `n` and `maxSum`. You are choosing some number of integers following the below rules:
* The chosen integers have to be in the range `[1, n]`.
* Each integer can be chosen **at most once**.
* The chosen integer... | dolphin | [
0.040315892547369,
0.018780836835503578,
-0.023741284385323524,
-0.02426302805542946,
0.040448904037475586,
-0.019752701744437218,
-0.043391015380620956,
0.06525325775146484,
0.0304228737950325,
-0.007318584248423576,
0.01750771887600422,
0.03617265820503235,
-0.03972210735082626,
-0.02084... | 0.842193 | 0.775518 | 0.066675 |
Please write the following solution using Mojo:
You are given two integer arrays `nums1` and `nums2` sorted in **ascending order** and an integer `k`.
Define a pair `(u, v)` which consists of one element from the first array and one element from the second array.
Return _the_ `k` _pairs_ `(u1, v1), (u2, v2), ..., (uk... | dolphin | [
0.014779461547732353,
0.04252978041768074,
-0.016432613134384155,
-0.04255769029259682,
0.04615505039691925,
-0.007525544613599777,
-0.018504034727811813,
0.0579974390566349,
0.04191403090953827,
-0.019343065097928047,
0.03319564834237099,
0.019778059795498848,
-0.024531517177820206,
-0.00... | 0.853152 | 0.797952 | 0.0552 |
Please write the following solution using Groovy:
You are given an integer array `cards` where `cards[i]` represents the **value** of the `ith` card. A pair of cards are **matching** if the cards have the **same** value.
Return _the **minimum** number of **consecutive** cards you have to pick up to have a pair of **ma... | dolphin | [
0.015132620930671692,
0.022389711812138557,
-0.04321105778217316,
-0.031455978751182556,
0.034180764108896255,
-0.009860590100288391,
-0.024399733170866966,
0.03923115134239197,
0.027087634429335594,
-0.03902004659175873,
0.01662609353661537,
0.01655176468193531,
-0.019703591242432594,
0.0... | 0.841885 | 0.786808 | 0.055078 |
Please explain the following problem in detail and provide code in Objective-C:
Given a **0-indexed** integer array `nums` of size `n` and two integers `lower` and `upper`, return _the number of fair pairs_.
A pair `(i, j)` is **fair** if:
* `0 <= i < j < n`, and
* `lower <= nums[i] + nums[j] <= upper`
**Example... | dolphin | [
0.007211090065538883,
0.02954709902405739,
-0.038612768054008484,
-0.019407562911510468,
0.04151295870542526,
0.0007122014067135751,
-0.028430482372641563,
0.0806524008512497,
0.029235614463686943,
-0.021200213581323624,
0.02703653834760189,
0.028063669800758362,
-0.036224883049726486,
-0.... | 0.846273 | 0.782263 | 0.06401 |
Please explain the following problem in detail and provide code in c++:
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.032812051475048065,
0.02459978684782982,
-0.02165161445736885,
-0.0330270379781723,
0.046285033226013184,
-0.0005612939712591469,
-0.046879395842552185,
0.09235364943742752,
0.04748952016234398,
-0.007015817333012819,
0.015925832092761993,
0.03337031230330467,
-0.03246201202273369,
0.002... | 0.825184 | 0.757014 | 0.06817 |
Please focus on the algorithm of this problem and provide code in ANSI C:
You are given an `m x n` matrix `grid` consisting of positive integers.
Perform the following operation until `grid` becomes empty:
* Delete the element with the greatest value from each row. If multiple such elements exist, delete any of the... | dolphin | [
0.02266058512032032,
0.03240138664841652,
-0.013765214011073112,
-0.04450026899576187,
0.03455892577767372,
-0.054358258843421936,
-0.029347961768507957,
0.08915965259075165,
0.048545483499765396,
-0.02663755975663662,
0.018970252946019173,
0.016447607427835464,
-0.046624645590782166,
-0.0... | 0.837716 | 0.781243 | 0.056473 |
Please write the following solution using C#:
You are given an integer array `nums` with the following properties:
* `nums.length == 2 * n`.
* `nums` contains `n + 1` **unique** elements.
* Exactly one element of `nums` is repeated `n` times.
Return _the element that is repeated_ `n` _times_.
**Example 1:**
*... | dolphin | [
0.026140155270695686,
0.02518521621823311,
-0.024307679384946823,
-0.026287756860256195,
0.03308429569005966,
-0.027683774009346962,
-0.027934730052947998,
0.09059571474790573,
0.02419077232480049,
-0.0027516677509993315,
0.018720023334026337,
0.011301920749247074,
-0.03201309219002724,
-0... | 0.842166 | 0.773425 | 0.068742 |
Please focus on the algorithm of this problem and provide code in Fortran:
You have a graph of `n` nodes. You are given an integer `n` and an array `edges` where `edges[i] = [ai, bi]` indicates that there is an edge between `ai` and `bi` in the graph.
Return _the number of connected components in the graph_.
**Exampl... | dolphin | [
0.023693736642599106,
0.015213019214570522,
-0.02799583412706852,
-0.026652198284864426,
0.02066720463335514,
-0.019995177164673805,
-0.008887297473847866,
0.058272991329431534,
0.02472647652029991,
0.009865283034741879,
0.02372308261692524,
0.02493736892938614,
-0.014784744009375572,
-0.0... | 0.845265 | 0.786917 | 0.058348 |
Please write the following solution using ANSI C:
You are given an array of equal-length strings `words`. Assume that the length of each string is `n`.
Each string `words[i]` can be converted into a **difference integer array** `difference[i]` of length `n - 1` where `difference[i][j] = words[i][j+1] - words[i][j]` wh... | dolphin | [
0.028362827375531197,
0.021503817290067673,
-0.004836358595639467,
-0.03923475369811058,
0.03222286328673363,
-0.046398892998695374,
-0.034769318997859955,
0.06635846942663193,
0.04115116596221924,
-0.032981157302856445,
0.024573374539613724,
0.0052361334674060345,
-0.053108323365449905,
-... | 0.842541 | 0.78377 | 0.058771 |
Please focus on the functionality of this problem and provide code in Objective-C:
You are given two **non-increasing 0-indexed** integer arrays `nums1` and `nums2`.
A pair of indices `(i, j)`, where `0 <= i < nums1.length` and `0 <= j < nums2.length`, is **valid** if both `i <= j` and `nums1[i] <= nums2[j... | dolphin | [
0.020207107067108154,
0.029394125565886497,
-0.02905050851404667,
-0.020745020359754562,
0.040092695504426956,
-0.02046895958483219,
-0.04256805032491684,
0.06880702823400497,
0.03112892434000969,
-0.026123488321900368,
0.03174928203225136,
0.014693512581288815,
-0.034788765013217926,
-0.0... | 0.847395 | 0.789935 | 0.057461 |
Please explain the reasoning behind the following solution and provide code in PHP:
You are given an integer `n`. There is an **undirected** graph with `n` nodes, numbered from `0` to `n - 1`. You are given a 2D integer array `edges` where `edges[i] = [ai, bi]` denotes that there exists an **undirected** edge connectin... | dolphin | [
0.01988515444099903,
0.04280416667461395,
-0.013530201278626919,
-0.02757161296904087,
0.04087810218334198,
-0.026069220155477524,
-0.01927405409514904,
0.05298086255788803,
0.03479659557342529,
0.003924522083252668,
0.03351501375436783,
0.032039444893598557,
-0.023137183859944344,
-0.0196... | 0.849998 | 0.795303 | 0.054695 |
Please explain the reasoning behind the following solution and provide code in c++:
You have a pointer at index `0` in an array of size `arrLen`. At each step, you can move 1 position to the left, 1 position to the right in the array, or stay in the same place (The pointer should not be placed outside the array at any ... | dolphin | [
0.025384919717907906,
0.02250480279326439,
-0.022283535450696945,
-0.03661802038550377,
0.03416576236486435,
-0.004224459640681744,
-0.03290315717458725,
0.09229190647602081,
0.050983183085918427,
-0.013231052085757256,
0.021013837307691574,
0.03987737372517586,
-0.022007156163454056,
-0.0... | 0.844367 | 0.787508 | 0.05686 |
Please explain the following problem in detail and provide code in ANSI C:
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:**... | dolphin | [
0.0030857857782393694,
0.021256014704704285,
-0.025917621329426765,
-0.032122399657964706,
0.02459540218114853,
-0.01922132447361946,
-0.030514061450958252,
0.08168923109769821,
0.01901237480342388,
-0.0016336567932739854,
0.01689017377793789,
0.02811090275645256,
-0.03700534626841545,
-0.... | 0.830364 | 0.766658 | 0.063706 |
Please write the following solution using Objective-C:
You are given an array of integers `arr` and an integer `target`.
You have to find **two non-overlapping sub-arrays** of `arr` each with a sum equal `target`. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-a... | dolphin | [
0.01917603798210621,
0.02664458006620407,
-0.03909415751695633,
-0.035608869045972824,
0.06138565018773079,
-0.010227469727396965,
-0.03954704850912094,
0.04738888889551163,
0.03793106600642204,
-0.023233141750097275,
0.02986716292798519,
0.01317478995770216,
-0.03318771719932556,
-0.02335... | 0.837037 | 0.780754 | 0.056283 |
Please write the following solution using Perl:
Given an integer `n`, return _the number of positive integers in the range_ `[1, n]` _that have **at least one** repeated digit_.
**Example 1:**
**Input:** n = 20
**Output:** 1
**Explanation:** The only positive number (<= 20) with at least 1 repeated digit is 11.
**Ex... | dolphin | [
0.014828414656221867,
0.005071611143648624,
-0.030524425208568573,
-0.059136223047971725,
0.0292164646089077,
-0.030031295493245125,
-0.023404177278280258,
0.04150857403874397,
0.015170563943684101,
-0.0014815840404480696,
0.03286759555339813,
0.041800517588853836,
-0.04654538631439209,
-0... | 0.819875 | 0.762125 | 0.057749 |
Please focus on the efficiency of this problem and provide code in Object Pascal:
You are given a **0-indexed** array `nums` comprising of `n` non-negative integers.
In one operation, you must:
* Choose an integer `i` such that `1 <= i < n` and `nums[i] > 0`.
* Decrease `nums[i]` by 1.
* Increase `nums[i - 1]` ... | dolphin | [
0.020172465592622757,
0.03622284159064293,
-0.02885800041258335,
-0.01711910404264927,
0.03478071093559265,
-0.027959221974015236,
-0.034033261239528656,
0.06293825805187225,
0.049011263996362686,
-0.000368083652574569,
0.023430772125720978,
0.023705285042524338,
-0.03063303232192993,
-0.0... | 0.848711 | 0.791259 | 0.057452 |
Please explain the following problem in detail and provide code in c++:
You are given a **0-indexed** integer array `nums`. A pair of indices `(i, j)` is a **bad pair** if `i < j` and `j - i != nums[j] - nums[i]`.
Return _the total number of **bad pairs** in_ `nums`.
**Example 1:**
**Input:** nums = \[4,1,3,3\]
**Ou... | dolphin | [
0.0036082733422517776,
0.004362293053418398,
-0.032884906977415085,
-0.0306269358843565,
0.05584251135587692,
0.006988451350480318,
-0.03551027551293373,
0.08949076384305954,
0.023069418966770172,
-0.006580593064427376,
0.010212237015366554,
0.027948109433054924,
-0.027454696595668793,
-0.... | 0.837221 | 0.774499 | 0.062722 |
Please explain the following problem in detail and provide code in PHP:
You are given an integer array `values` where values\[i\] represents the value of the `ith` sightseeing spot. Two sightseeing spots `i` and `j` have a **distance** `j - i` between them.
The score of a pair (`i < j`) of sightseeing spots is `values... | dolphin | [
0.015661140903830528,
0.025895806029438972,
-0.02971680276095867,
-0.012553591281175613,
0.052182119339704514,
-0.02233876660466194,
-0.04867423325777054,
0.04542331397533417,
0.057128436863422394,
-0.01138682384043932,
0.03863844648003578,
0.043922778218984604,
-0.03637159615755081,
0.003... | 0.831732 | 0.77273 | 0.059001 |
Please explain the reasoning behind the following solution and provide code in Scheme:
_(This problem is an **interactive problem**.)_
You may recall that an array `arr` is a **mountain array** if and only if:
* `arr.length >= 3`
* There exists some `i` with `0 < i < arr.length - 1` such that:
* `arr[0] < a... | dolphin | [
0.03138328343629837,
0.035402700304985046,
-0.02554624155163765,
-0.04544813558459282,
0.03303398936986923,
-0.047117557376623154,
-0.04596913605928421,
0.054564718157052994,
0.035323675721883774,
-0.02079026587307453,
0.022292323410511017,
0.002090814057737589,
-0.02903113327920437,
-0.00... | 0.851407 | 0.793694 | 0.057713 |
Please focus on the algorithm of this problem and provide code in Objective-C:
You want to build some obstacle courses. You are given a **0-indexed** integer array `obstacles` of length `n`, where `obstacles[i]` describes the height of the `ith` obstacle.
For every index `i` between `0` and `n - 1` (**inclusive**), fi... | dolphin | [
0.016557978466153145,
0.018828134983778,
-0.022432060912251472,
-0.026081720367074013,
0.021781427785754204,
-0.029409505426883698,
-0.051127925515174866,
0.0574394129216671,
0.03289889171719551,
-0.026774758473038673,
0.027927754446864128,
0.014372533187270164,
-0.027064325287938118,
-0.0... | 0.839208 | 0.785128 | 0.054081 |
Please write the following solution using Swift:
You are given two **sorted** arrays of distinct integers `nums1` and `nums2.`
A **valid path** is defined as follows:
* Choose array `nums1` or `nums2` to traverse (from index-0).
* Traverse the current array from left to right.
* If you are reading any value tha... | dolphin | [
0.010325289331376553,
0.014409414492547512,
-0.028473347425460815,
-0.028391094878315926,
0.03011745773255825,
-0.023279214277863503,
-0.04090093448758125,
0.04170970991253853,
0.04242889583110809,
-0.027452265843749046,
0.031079107895493507,
0.023959491401910782,
-0.015788836404681206,
-0... | 0.845494 | 0.784881 | 0.060613 |
Please explain the following problem in detail and provide code in java:
Given an array of integers `arr`, a **lucky integer** is an integer that has a frequency in the array equal to its value.
Return _the largest **lucky integer** in the array_. If there is no **lucky integer** return `-1`.
**Example 1:**
**Input:... | dolphin | [
0.02663029171526432,
0.05020513758063316,
-0.02862497605383396,
-0.03592631593346596,
0.022352466359734535,
-0.002758552087470889,
-0.038080547004938126,
0.03315480053424835,
0.018777405843138695,
-0.0275864340364933,
0.032601285725831985,
0.026756007224321365,
-0.02380630001425743,
-0.002... | 0.825811 | 0.764171 | 0.06164 |
Please focus on the algorithm of this problem and provide code in Visual Basic .NET:
Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
**Note:** You can only move either down or right at any point in time.
**Examp... | dolphin | [
-0.005574128590524197,
0.0072288913652300835,
-0.026782618835568428,
-0.03499462455511093,
0.04022957757115364,
-0.040697794407606125,
-0.01640046387910843,
0.06477440893650055,
0.040285129100084305,
-0.02099745348095894,
0.019260739907622337,
0.0377102829515934,
-0.033058881759643555,
-0.... | 0.837483 | 0.780831 | 0.056652 |
Please explain the following problem in detail and provide code in c++:
You are given a string `s` and a **positive** integer `k`.
Select a set of **non-overlapping** substrings from the string `s` that satisfy the following conditions:
* The **length** of each substring is **at least** `k`.
* Each substring is a... | dolphin | [
0.01402262318879366,
0.012527377344667912,
-0.029395388439297676,
-0.021872637793421745,
0.04037401080131531,
-0.026023494079709053,
-0.007942740805447102,
0.07497270405292511,
0.030315596610307693,
-0.010435659438371658,
0.037650216370821,
0.03014392778277397,
-0.01745554618537426,
-0.003... | 0.838359 | 0.782229 | 0.05613 |
Please explain the following problem in detail and provide code in R:
You are given an array `nums` consisting of positive integers.
Split the array into **one or more** disjoint subarrays such that:
* Each element of the array belongs to **exactly one** subarray, and
* The **GCD** of the elements of each subarra... | dolphin | [
0.02030792273581028,
0.04018000140786171,
-0.01963258720934391,
-0.027035417035222054,
0.04359711706638336,
-0.016011931002140045,
-0.033320650458335876,
0.0602077916264534,
0.029562128707766533,
0.0016773263923823833,
0.004817507695406675,
0.014260192401707172,
-0.023625938221812248,
-0.0... | 0.839857 | 0.781742 | 0.058115 |
Please explain the reasoning behind the following solution and provide code in java:
You are given an integer array `nums` and an integer `k`.
For each index `i` where `0 <= i < nums.length`, change `nums[i]` to be either `nums[i] + k` or `nums[i] - k`.
The **score** of `nums` is the difference between the maximum an... | dolphin | [
0.010839104652404785,
0.029057908803224564,
-0.026319794356822968,
-0.029002053663134575,
0.05189089477062225,
-0.042565640062093735,
-0.039698485285043716,
0.04565092548727989,
0.030365167185664177,
-0.012972524389624596,
0.029192524030804634,
0.026288745924830437,
-0.03794333338737488,
0... | 0.839087 | 0.782012 | 0.057075 |
Please focus on the functionality of this problem and provide code in Haskell:
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... | dolphin | [
0.02036070078611374,
0.026294926181435585,
-0.028978116810321808,
-0.025933604687452316,
0.04778745770454407,
-0.0050105080008506775,
-0.01464064046740532,
0.04219081252813339,
0.04322609677910805,
-0.010657409206032753,
0.03306208550930023,
0.032626621425151825,
-0.029660886153578758,
-0.... | 0.837747 | 0.782983 | 0.054765 |
Please explain the reasoning behind the following solution and provide code in java:
There is a country of `n` cities numbered from `0` to `n - 1`. In this country, there is a road connecting **every pair** of cities.
There are `m` friends numbered from `0` to `m - 1` who are traveling through the country. Each one of... | dolphin | [
0.022050417959690094,
0.016902286559343338,
-0.03595007210969925,
-0.026568004861474037,
0.025005312636494637,
-0.021886585280299187,
-0.021319132298231125,
0.04788375645875931,
0.014721653424203396,
-0.035139549523591995,
0.02805059589445591,
0.029212741181254387,
-0.015572539530694485,
-... | 0.842829 | 0.788581 | 0.054248 |
Please explain the reasoning behind the following solution and provide code in ANSI 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)`... | dolphin | [
0.009188548661768436,
0.02711592987179756,
-0.031036263331770897,
-0.029488567262887955,
0.052059005945920944,
-0.022367702797055244,
-0.01768489181995392,
0.08840028196573257,
0.010490687564015388,
-0.01598743163049221,
0.0174581129103899,
0.0265054851770401,
-0.041995562613010406,
-0.021... | 0.850501 | 0.791081 | 0.05942 |
Please explain the following problem in detail and provide code in Scheme:
There is a tree (i.e. a connected, undirected graph with no cycles) consisting of `n` nodes numbered from `0` to `n - 1` and exactly `n - 1` edges.
You are given a **0-indexed** integer array `vals` of length `n` where `vals[i]` denotes the val... | dolphin | [
0.029751749709248543,
0.01707632467150688,
-0.028941405937075615,
-0.022091101855039597,
0.027065904811024666,
-0.034290846437215805,
-0.021229997277259827,
0.05274458974599838,
0.02472040429711342,
-0.0038196740206331015,
0.03031839244067669,
0.005840135272592306,
-0.01207248866558075,
-0... | 0.855458 | 0.794913 | 0.060545 |
Please explain the following problem in detail and provide code in Scheme:
You are given two arrays of positive integers, `boxes` and `warehouse`, representing the heights of some boxes of unit width and the heights of `n` rooms in a warehouse respectively. The warehouse's rooms are labelled from `0` to `n - 1` from le... | dolphin | [
0.03681516274809837,
0.02142396569252014,
-0.02389795146882534,
-0.011536463163793087,
0.026079505681991577,
-0.011982985772192478,
-0.03411678969860077,
0.055421750992536545,
0.030731404200196266,
-0.006378908641636372,
0.025085318833589554,
0.0394480861723423,
-0.027444610372185707,
-0.0... | 0.84726 | 0.791333 | 0.055927 |
Please write the following solution using Groovy:
A **wiggle sequence** is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal ... | dolphin | [
0.009195173159241676,
0.00483469245955348,
-0.02157493866980076,
-0.0314936637878418,
0.03560993820428848,
-0.032273150980472565,
-0.0401541106402874,
0.04594872519373894,
0.030756043270230293,
-0.02228701114654541,
0.022528521716594696,
0.02951076067984104,
-0.028846075758337975,
-0.00650... | 0.844291 | 0.788739 | 0.055552 |
Please explain the following problem in detail and provide code in java:
A **self-dividing number** is a number that is divisible by every digit it contains.
* For example, `128` is **a self-dividing number** because `128 % 1 == 0`, `128 % 2 == 0`, and `128 % 8 == 0`.
A **self-dividing number** is not allowed to co... | dolphin | [
0.030251672491431236,
0.03376522287726402,
-0.02468372881412506,
-0.03964794799685478,
0.024681370705366135,
-0.02615559659898281,
-0.013638462871313095,
0.04161730781197548,
0.034442685544490814,
-0.015891602262854576,
0.03611314296722412,
0.018921567127108574,
-0.03148806467652321,
-0.01... | 0.830658 | 0.767253 | 0.063406 |
Please explain the following problem in detail and provide code in Elixir:
You are given an integer array `nums`. The **range** of a subarray of `nums` is the difference between the largest and smallest element in the subarray.
Return _the **sum of all** subarray ranges of_ `nums`_._
A subarray is a contiguous **non-... | dolphin | [
0.008836161345243454,
0.030337002128362656,
-0.031160864979028702,
-0.034829311072826385,
0.039948686957359314,
-0.02257687598466873,
-0.04076339676976204,
0.02761317975819111,
0.032490264624357224,
-0.0024241639766842127,
0.03290427476167679,
0.045378293842077255,
-0.041496556252241135,
-... | 0.835533 | 0.780416 | 0.055117 |
Please explain the following problem in detail and provide code in Kotlin:
Given an array `nums` that represents a permutation of integers from `1` to `n`. We are going to construct a binary search tree (BST) by inserting the elements of `nums` in order into an initially empty BST. Find the number of different ways to ... | dolphin | [
0.012904217466711998,
0.01845402643084526,
-0.020050926133990288,
-0.015169764868915081,
0.031972043216228485,
-0.029587848111987114,
-0.00933129619807005,
0.056176137179136276,
0.0241861529648304,
-0.00954717118293047,
0.020476700738072395,
0.017462627962231636,
-0.03573905676603317,
0.01... | 0.846597 | 0.793306 | 0.053291 |
Please focus on the functionality of this problem and provide code in Julia:
In a linked list of size `n`, where `n` is **even**, the `ith` node (**0-indexed**) of the linked list is known as the **twin** of the `(n-1-i)th` node, if `0 <= i <= (n / 2) - 1`.
* For example, if `n = 4`, then node `0` is the twin of nod... | dolphin | [
0.025961846113204956,
0.0344420000910759,
-0.026256632059812546,
-0.03707077354192734,
0.029727380722761154,
-0.017403775826096535,
-0.011374881491065025,
0.056479986757040024,
0.037333518266677856,
-0.006798259448260069,
0.015509651973843575,
0.03138917312026024,
-0.021930141374468803,
0.... | 0.836695 | 0.782591 | 0.054105 |
Please write the following solution using ANSI C:
You are given an `m x n` binary matrix `mat` of `1`'s (representing soldiers) and `0`'s (representing civilians). The soldiers are positioned **in front** of the civilians. That is, all the `1`'s will appear to the **left** of all the `0`'s in each row.
A row `i` is **... | dolphin | [
0.046418484300374985,
0.033379241824150085,
-0.03399501368403435,
-0.04973791167140007,
0.048433929681777954,
-0.046231385320425034,
-0.016908196732401848,
0.0841139629483223,
0.04325931519269943,
-0.014327749609947205,
0.01509411633014679,
0.007395795080810785,
-0.05891581252217293,
-0.02... | 0.839329 | 0.781553 | 0.057776 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.