question
stringlengths 58
4.29k
| label
class label 3
classes |
---|---|
you give encode string s to decode string tape encode string read character time follow step takenif character read letter letter write tapeif character read digit d entire current tape repeatedly write d 1 time totalgiven integ k return kth letter 1indexed decode string Example 1input s leet2code3 k 10output oExplanation the decode string leetleetcodeleetleetcodeleetleetcodeThe 10th letter stre oexample 2input s ha22 k 5output hExplanation the decode string hahahahathe 5th letter hExample 3input s a2345678999999999999999 k 1output aExplanation the decode string repeat 8301530446056247680 timesthe 1st letter Constraints2 slength 100s consist lowercase english letter digit 2 9s start letter1 k 109it guarantee k equal length decode stringThe decode string guarantee 263 letter | 2string
|
you give array people peoplei weight ith person infinite number boat boat carry maximum weight limit each boat carry people time provide sum weight people limitreturn minimum number boat carry give person example 1input people 12 limit 3output 1explanation 1 boat 1 2example 2input people 3221 limit 3output 3explanation 3 boat 1 2 2 3example 3input people 3534 limit 5output 4explanation 4 boat 3 3 4 5 constraints1 peoplelength 5 1041 peoplei limit 3 104 | 0array
|
you give undirected graph original graph n node label 0 n 1 you decide subdivide edge graph chain node number new node vary edgethe graph give 2D array edge edgesi ui vi cnti indicate edge node ui vi original graph cnti total number new node subdivide edge Note cnti 0 mean subdivide edgeTo subdivide edge ui vi replace cnti 1 new edge cnti new node the new node x1 x2 xcnti new edge ui x1 x1 x2 x2 x3 xcnti1 xcnti xcnti viIn new graph want know node reachable node 0 node reachable distance maxmove lessGiven original graph maxmove return number node reachable node 0 new graph example 1input edge 0110021122 maxmove 6 n 3output 13explanation the edge subdivision show image abovethe node reachable highlight yellowexample 2input edge 014126028131 maxmove 10 n 4output 23example 3input edge 124145131234345 maxmove 17 n 5output 1explanation Node 0 disconnected rest graph node 0 reachable Constraints0 edgeslength minn n 1 2 104edgesilength 30 ui vi nThere multiple edge graph0 cnti 1040 maxmove 1091 n 3000 | 1graph
|
you give n x n grid place 1 x 1 x 1 cube axisaligne x y z axeseach value v gridij represent tower v cube place cell jwe view projection cubes xy yz zx planesA projection like shadow map 3dimensional figure 2dimensional plane we view shadow look cube sidereturn total area projection Example 1input grid 1234output 17explanation here projection shadow shape axisaligne planeexample 2input grid 2Output 5Example 3input grid 1002output 8 Constraintsn gridlength gridilength1 n 500 gridij 50 | 0array
|
a sentence string singlespace separate word word consist lowercase lettersA word uncommon appear exactly sentence appear sentenceGiven sentence s1 s2 return list uncommon word you return answer order Example 1input s1 apple sweet s2 apple souroutput sweetsourExample 2input s1 apple apple s2 bananaoutput banana Constraints1 s1length s2length 200s1 s2 consist lowercase English letter spacess1 s2 lead trail spacesall word s1 s2 separate single space | 2string
|
you start cell rStart cStart row x col grid face east the northwest corner row column grid southeast corner row columnyou walk clockwise spiral shape visit position grid whenever outside grids boundary continue walk outside grid return grid boundary later eventually reach row cols space gridreturn array coordinate represent position grid order visit Example 1input row 1 col 4 rstart 0 cStart 0output 00010203example 2input row 5 col 6 rStart 1 cStart 4Output 141525242313030405353433322212024544434241312111014030201000 Constraints1 row col 1000 rStart rows0 cStart col | 0array
|
we want split group n people label 1 n group size each person dislike people groupgiven integ n array dislikes dislikesi ai bi indicate person label ai like person label bi return true possible split group way Example 1input n 4 dislike 121324output trueexplanation group1 14 group2 23example 2input n 3 dislike 121323output falseexample 3input n 5 dislike 1223344515output false Constraints1 n 20000 dislikeslength 104dislikesilength 21 dislikesij nai biAll pair dislike unique | 1graph
|
Alice Bob different total number candy you give integer array alicesize bobsizes alicesizesi number candy ith box candy Alice bobsizesj number candy jth box candy Bob hassince friend like exchange candy box exchange total candy the total candy person sum number candy box haveReturn integer array answer answer0 number candy box Alice exchange answer1 number candy box Bob exchange if multiple answer return it guarantee answer exist Example 1input alicesize 11 bobsizes 22output 12example 2input alicesize 12 bobsize 23output 12example 3input alicesize 2 bobsizes 13Output 23 constraints1 alicesizeslength bobsizeslength 1041 alicesizesi bobsizesj 105alice Bob different total number candiesthere valid answer give input | 0array
|
give integer array preorder postorder preorder preorder traversal binary tree distinct value postorder postorder traversal tree reconstruct return binary treeif exist multiple answer return Example 1input preorder 1245367 postorder 4526731output 1234567example 2input preorder 1 postorder 1output 1 Constraints1 preorderlength 301 preorderi preorderlengthAll value preorder uniquepostorderlength preorderlength1 postorderi postorderlengthAll value postorder uniqueIt guarantee preorder postorder preorder traversal postorder traversal binary tree | 0array
|
the width sequence difference maximum minimum element sequencegiven array integer num return sum width nonempty subsequence num since answer large return modulo 109 7a subsequence sequence derive array delete element change order remain element for example 3627 subsequence array 0316227 Example 1input num 213output 6explanation the subsequence 1 2 3 21 23 13 213the correspond width 0 0 0 1 1 2 2the sum width 6example 2input num 2output 0 Constraints1 numslength 1051 numsi 105 | 0array
|
you give n x n grid place 1 x 1 x 1 cube each value v gridij represent tower v cube place cell jAfter placing cube decide glue directly adjacent cube form irregular 3d shapesreturn total surface area result shapesnote the face shape count surface area Example 1input grid 1234output 34example 2input grid 111101111output 32example 3input grid 222212222output 46 Constraintsn gridlength gridilength1 n 500 gridij 50 | 0array
|
an array monotonic monotone increase monotone decreasingan array num monotone increase j numsi numsj an array num monotone decrease j numsi numsjGiven integer array num return true give array monotonic false example 1input num 1223output trueExample 2input num 6544output trueexample 3input num 132Output false Constraints1 numslength 105105 numsi 105 | 0array
|
give root binary search tree rearrange tree inorder leftmost node tree root tree node leave child right child Example 1input root 53624null81nullnullnull79output 1null2null3null4null5null6null7null8null9example 2input root 517output 1null5null7 ConstraintsThe number node give tree range 1 1000 Nodeval 1000 | 1graph
|
we array arr nonnegative integersFor contiguous subarray sub arri arri 1 arrj j bitwise or element sub obtain result arri arri 1 arrjreturn number possible result result occur count final answer Example 1Input arr 0Output 1explanation there possible result 0example 2input arr 112output 3explanation the possible subarray 1 1 2 1 1 1 2 1 1 2these yield result 1 1 2 1 3 3there 3 unique value answer 3example 3Input arr 124output 6explanation the possible result 1 2 3 4 6 7 constraints1 numslength 5 1040 numsi 109 | 0array
|
you give string s integer k you choose k letter s append end stringreturn lexicographically small string apply mention step number move Example 1input s cba k 1Output acbexplanation in 1st character c end obtain string bacin second 1st character b end obtain final result acbexample 2Input s baaca k 3output aaabcexplanation in 1st character b end obtain string aacabin second 3rd character c end obtain final result aaabc Constraints1 k slength 1000 consist lowercase english letter | 2string
|
we use runlength encode ie RLE encode sequence integer in runlength encode array length encoding 0indexe encodingi tell number time nonnegative integer value encodingi 1 repeat sequencefor example sequence arr 88855 encode encoding 3825 encode 380925 encode 281825 valid RLE arrgiven runlength encode array design iterator iterate itImplement RLEIterator classrleiteratorint encode Initializes object encode array encodedint nextint n Exhausts n element return element exhausted way if element leave exhaust return 1 instead Example 1inputrleiterator next3 8 0 9 2 5 2 1 1 2outputnull 8 8 5 1explanationrleiterator rleiterator new RLEIterator3 8 0 9 2 5 this map sequence 88855rleiteratornext2 exhaust 2 term sequence return 8 the remain sequence 8 5 5rleiteratornext1 exhaust 1 term sequence return 8 the remain sequence 5 5rleiteratornext1 exhaust 1 term sequence return 5 the remain sequence 5rleiteratornext2 exhaust 2 term return 1 this term exhaust 5but second term exist since term exhaust exist return 1 constraints2 encodinglength 1000encodinglength even0 encodingi 1091 n 109At 1000 call | 0array
|
you visit farm single row fruit tree arrange left right the tree represent integer array fruit fruitsi type fruit ith tree producesyou want collect fruit possible however owner strict rule followyou basket basket hold single type fruit there limit fruit basket holdstarting tree choice pick exactly fruit tree include start tree move right the pick fruit fit basketsonce reach tree fruit fit basket stopGiven integer array fruit return maximum number fruit pick Example 1input fruit 121output 3explanation we pick 3 treesExample 2input fruit 0122output 3explanation we pick tree 122if start tree pick tree 01example 3input fruit 12322output 4explanation we pick tree 2322if start tree pick tree 12 Constraints1 fruitslength 1050 fruitsi fruitslength | 0array
|
give integer array num integer begin array follow odd integersreturn array satisfie condition example 1input num 3124output 2431explanation the output 4231 2413 4213 acceptedExample 2input num 0output 0 Constraints1 numslength 50000 numsi 5000 | 0array
|
give array integer arr find sum minb b range contiguous subarray arr since answer large return answer modulo 109 7 Example 1input arr 3124output 17explanation Subarrays 3 1 2 4 31 12 24 312 124 3124 Minimums 3 1 2 4 1 1 2 1 1 1sum 17example 2input arr 118194433output 444 Constraints1 arrlength 3 1041 arri 3 104 | 0array
|
you give integer array num integer kIn operation choose index 0 numslength change numsi numsi x x integer range k k you apply operation index iThe score num difference maximum minimum element numsreturn minimum score num apply mention operation index Example 1input num 1 k 0output 0explanation the score maxnums minnum 1 1 0example 2input num 010 k 2output 6explanation Change num 2 8 the score maxnums minnum 8 2 6example 3input num 136 k 3output 0explanation Change num 4 4 4 the score maxnums minnum 4 4 0 constraints1 numslength 1040 numsi 1040 k 104 | 0array
|
you give integer array num integer kFor index 0 numslength change numsi numsi k numsi kThe score num difference maximum minimum element numsreturn minimum score num change value index Example 1input num 1 k 0output 0explanation the score maxnums minnum 1 1 0example 2input num 010 k 2output 6explanation Change num 2 8 the score maxnums minnum 8 2 6example 3input num 136 k 3output 3explanation Change num 4 6 3 the score maxnums minnum 6 3 3 constraints1 numslength 1040 numsi 1040 k 104 | 0array
|
you give integer array person time in election ith vote cast personsi time timesifor query time t find person lead election time t Votes cast time t count query in case tie recent vote tie candidate winsimplement topvotedcandidate classtopvotedcandidateint person int time Initializes object person times arraysint qint t return number person lead election time t accord mention rule Example 1inputtopvotedcandidate q q q q q q0 1 1 0 0 1 0 0 5 10 15 20 25 30 3 12 25 15 24 8outputnull 0 1 1 0 0 1explanationtopvotedcandidate topvotedcandidate new TopVotedCandidate0 1 1 0 0 1 0 0 5 10 15 20 25 30topvotedcandidateq3 return 0 at time 3 vote 0 0 leadingtopvotedcandidateq12 return 1 at time 12 vote 011 1 leadingtopvotedcandidateq25 return 1 at time 25 vote 011001 1 lead tie recent votetopVotedCandidateq15 return 0topvotedcandidateq24 return 0topvotedcandidateq8 return 1 Constraints1 personslength 5000timeslength personslength0 personsi personslength0 timesi 109time sort strictly increase ordertimes0 t 109at 104 call q | 0array
|
give array integer num sort array ascend order return ityou solve problem builtin function onlogn time complexity small space complexity possible Example 1input num 5231output 1235explanation after sort array position number change example 2 3 position number change example 1 5example 2input num 511200output 001125explanation note value num necessairly unique Constraints1 numslength 5 1045 104 numsi 5 104 | 0array
|
a game undirected graph play player Mouse Cat alternate turnsthe graph give follow grapha list nod b ab edge graphThe mouse start node 1 go cat start node 2 go second hole node 0During player turn travel edge graph meet for example Mouse node 1 travel node graph1additionally allow Cat travel Hole node 0then game end waysif Cat occupy node Mouse Cat winsIf Mouse reach Hole Mouse winsIf position repeat ie player position previous turn player turn game drawGiven graph assume player play optimally return1 mouse win game2 cat win game or0 game draw example 1input graph 25304514523023output 0example 2input graph 130302output 1 constraints3 graphlength 501 graphilength graphlength0 graphij graphlengthgraphij igraphi uniqueThe mouse cat | 1graph
|
you give integer array deck decki represent number write ith cardpartition card group thateach group exactly x card x 1 andall card group integer write themreturn true partition possible false example 1input deck 12344321output trueexplanation possible partition 11223344example 2input deck 11122233output falseexplanation no possible partition Constraints1 decklength 1040 decki 104 | 0array
|
give integer array nums partition contiguous subarray leave right thatevery element leave equal element rightleft right nonemptyleft small possible sizereturn length leave partitioningt case generate partitioning exist Example 1input num 50386output 3explanation leave 503 right 86example 2input num 1110612output 4explanation leave 1110 right 612 constraints2 numslength 1050 numsi 106there valid answer give input | 0array
|
give string s reverse string accord follow rulesall character english letter remain positionall english letter lowercase uppercase reversedreturn s reverse Example 1input s abcdoutput dcbaExample 2input s abcdefghijoutput jihgfedcbaexample 3input s Test1ngLeetcodeQOutput Qedo1cteeLgntseT Constraints1 slength 100s consist character ascii value range 33 122 contain | 2string
|
give circular integer array num length n return maximum possible sum nonempty subarray numsA circular array mean end array connect begin array Formally element numsi numsi 1 n previous element numsi numsi 1 n nA subarray include element fix buffer num formally subarray numsi numsi 1 numsj exist k1 k2 j k1 n k2 n Example 1input num 1232output 3explanation Subarray 3 maximum sum 3example 2input num 535output 10explanation Subarray 55 maximum sum 5 5 10example 3input num 323output 2explanation Subarray 2 maximum sum 2 Constraintsn numslength1 n 3 1043 104 numsi 3 104 | 0array
|
a complete binary tree binary tree level possibly completely fill node far leave possibledesign algorithm insert new node complete binary tree keep complete insertionimplement CBTInserter classCBTInserterTreeNode root Initializes data structure root complete binary treeint insertint v Inserts TreeNode tree value Nodeval val tree remain complete return value parent insert TreeNodeTreeNode get_root Returns root node tree Example 1inputcbtinserter insert insert get_root1 2 3 4 outputnull 1 2 1 2 3 4explanationcbtinserter cbtinsert new cbtinserter1 2cBTInserterinsert3 return 1cBTInserterinsert4 return 2cbtinserterget_root return 1 2 3 4 ConstraintsThe number nod tree range 1 10000 Nodeval 5000root complete binary tree0 val 5000At 104 call insert get_root | 1graph
|
a parenthesis stre valid ifit stringit write AB a concatenate B A b valid string orIt write a a valid stringYou give parenthesis stre s in insert parenthesis position stringfor example s insert opening parenthesis closing parenthesis return minimum number move require s valid Example 1input s output 1example 2input s output 3 constraints1 slength 1000si | 2string
|
give array integer num half integer num odd half evensort array numsi odd odd numsi evenreturn answer array satisfy condition example 1input num 4257output 4527explanation 4725 2547 2745 acceptedExample 2input num 23output 23 constraints2 numslength 2 104numslength evenhalf integer num even0 numsi 1000 follow up could solve inplace | 0array
|
give integer array arr integer target return number tuple j k j k arri arrj arrk targetAs answer large return modulo 109 7 Example 1input arr 1122334455 target 8Output 20explanation enumerate value arri arrj arrk1 2 5 occur 8 times1 3 4 occur 8 times2 2 4 occur 2 times2 3 3 occur 2 timesExample 2input arr 112222 target 5Output 12Explanation arri 1 arrj arrk 2 occur 12 timesWe choose 1 11 2 waysand 2s 2222 6 waysExample 3input arr 213 target 6output 1explanation 1 2 3 occur time array return 1 constraints3 arrlength 30000 arri 1000 target 300 | 0array
|
your friend type keyboard sometimes type character c key long press character type 1 timesyou examine type character keyboard return true possible friend character possibly long press Example 1input alex type aaleexOutput trueExplanation e alex long pressedexample 2input saeed type ssaaeddoutput falseexplanation e press twice type output Constraints1 namelength typedlength 1000name type consist lowercase english letter | 2string
|
a binary string monotone increase consist number 0s possibly follow number 1s possibly noneyou give binary string s you flip si change 0 1 1 0return minimum number flip s monotone increase Example 1input s 00110output 1explanation we flip digit 00111example 2input s 010110output 2explanation we flip 011111 alternatively 000111example 3input s 00011000output 2explanation we flip 00000000 Constraints1 slength 105si 0 1 | 2string
|
you give array arr consist zeros one divide array nonempty part part represent binary valueif possible return j 1 j thatarr0 arr1 arri partarri 1 arri 2 arrj 1 second andarrj arrj 1 arrarrlength 1 partAll part equal binary valuesif possible return 1 1note entire consider binary value represent for example 110 represent 6 decimal 3 also lead zero allow 011 11 represent value Example 1input arr 10101output 03Example 2Input arr 11011output 11example 3Input arr 11001output 02 constraints3 arrlength 3 104arri 0 1 | 0array
|
give binary array num integer goal return number nonempty subarray sum goalA subarray contiguous array Example 1input num 10101 goal 2output 4explanation the 4 subarray bolde underline below10101101011010110101example 2input num 00000 goal 0output 15 constraints1 numslength 3 104numsi 0 10 goal numslength | 0array
|
give n x n array integer matrix return minimum sum fall path matrixa fall path start element row choose element row directly diagonally leftright specifically element position row col row 1 col 1 row 1 col row 1 col 1 Example 1input matrix 213654789output 13explanation there fall path minimum sum shownexample 2input matrix 1957405output 59explanation the fall path minimum sum show Constraintsn matrixlength matrixilength1 n 100100 matrixij 100 | 0array
|
an array num length n beautiful ifnum permutation integer range 1 nFor 0 j n index k k j 2 numsk numsi numsjGiven integer n return beautiful array num length n there valid answer give n Example 1input n 4Output 2143example 2input n 5Output 31254 Constraints1 n 1000 | 0array
|
you give string stamp target initially stre s length targetlength si in turn place stamp s replace letter s correspond letter stampfor example stamp abc target abcba s initially in turn canplace stamp index 0 s obtain abcplace stamp index 1 s obtain abc orplace stamp index 2 s obtain abcnote stamp fully contain boundary s order stamp ie place stamp index 3 sWe want convert s target 10 targetlength turnsReturn array index leftmost letter stamp turn if obtain target s 10 targetlength turn return array Example 1input stamp abc target ababcoutput 02explanation initially s Place stamp index 0 abc Place stamp index 2 ababc102 accept answer answersExample 2input stamp abca target aabcacaoutput 301explanation Initially s Place stamp index 3 abca Place stamp index 0 abcabca Place stamp index 1 aabcaca Constraints1 stamplength targetlength 1000stamp target consist lowercase english letter | 2string
|
give root node binary search tree integer low high return sum value node value inclusive range low high Example 1input root 1051537null18 low 7 high 15output 32explanation Nodes 7 10 15 range 7 15 7 10 15 32example 2input root 105153713181null6 low 6 high 10output 23explanation Nodes 6 7 10 range 6 10 6 7 10 23 ConstraintsThe number nod tree range 1 2 1041 Nodeval 1051 low high 105All Nodeval unique | 1graph
|
you give array point XY plane point pointsi xi yiReturn minimum area rectangle form point side parallel X Y axis if rectangle return 0 example 1input point 1113313322output 4example 2input point 111331334143output 2 Constraints1 pointslength 500pointsilength 20 xi yi 4 104all give point unique | 0array
|
give string s return number distinct nonempty subsequence s since answer large return modulo 109 7a subsequence stre new string form original string delete character disturb relative position remain character ie ace subsequence abcde aec Example 1input s abcoutput 7explanation the 7 distinct subsequence b c ab ac bc abcexample 2Input s abaoutput 6explanation the 6 distinct subsequence b ab aa ba abaExample 3Input s aaaoutput 3explanation the 3 distinct subsequence aa aaa Constraints1 slength 2000s consist lowercase english letter | 2string
|
give array integer arr return true valid mountain arrayrecall arr mountain array ifarrlength 3There exist 0 arrlength 1 thatarr0 arr1 arri 1 arriarri arri 1 arrarrlength 1 Example 1input arr 21output falseexample 2Input arr 355output falseexample 3input arr 0321output true Constraints1 arrlength 1040 arri 104 | 0array
|
you give integer array num in pick index 0 numslength increment numsi 1return minimum number move value num uniquethe test case generate answer fit 32bit integer Example 1input num 122output 1explanation after 1 array 1 2 3example 2input num 321217output 6explanation after 6 move array 3 4 1 2 5 7it show 5 move impossible array unique value Constraints1 numslength 1050 numsi 105 | 0array
|
give integer array pushed pop distinct value return true result sequence push pop operation initially stack false example 1input push 12345 pop 45321output trueexplanation we follow sequencepush1 push2 push3 push4pop 4push5pop 5 pop 3 pop 2 pop 1example 2input push 12345 pop 43512output falseexplanation 1 pop 2 Constraints1 pushedlength 10000 pushedi 1000all element push uniquepoppedlength pushedlengthpoppe permutation push | 0array
|
on 2D plane place n stone integer coordinate point each coordinate point stoneA stone remove share row column stone removedGiven array stone length n stonesi xi yi represent location ith stone return large possible number stone remove example 1input stone 000110122122output 5explanation one way remove 5 stone follows1 remove stone 22 share row 212 Remove stone 21 share column 013 remove stone 12 share row 104 Remove stone 10 share column 005 remove stone 01 share row 00stone 00 remove share rowcolumn stone planeexample 2input stone 0002112022output 3explanation one way 3 move follows1 remove stone 22 share row 202 remove stone 20 share column 003 Remove stone 02 share row 00stone 00 11 remove share rowcolumn stone planeexample 3input stone 00output 0explanation 00 stone plane remove Constraints1 stoneslength 10000 xi yi 104No stone coordinate point | 1graph
|
you initial power power initial score 0 bag tokens tokensi value ith token 0indexedyour goal maximize total score potentially play token waysif current power tokensi play ith token face lose tokensi power gain 1 scoreif current score 1 play ith token face gain tokensi power lose 1 scoreEach token play order you play tokensreturn large possible score achieve playing number token Example 1Input token 100 power 50output 0explanation play token bag impossible little power little scoreExample 2input tokens 100200 power 150output 1explanation play 0th token 100 face power 50 score 1there need play 1st token play face add scoreexample 3input tokens 100200300400 power 200output 2explanation play token order score 21 play 0th token 100 face power 100 score 12 play 3rd token 400 face power 500 score 03 play 1st token 200 face power 300 score 14 play 2nd token 300 face power 0 score 2 constraints0 tokenslength 10000 tokensi power 104 | 0array
|
give array arr 4 digit find late 24hour time digit exactly once24hour time format HHMM HH 00 23 MM 00 59 the early 24hour time 0000 late 2359return latest 24hour time HHMM format if valid time return string Example 1input arr 1234output 2341explanation the valid 24hour time 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 of time 2341 latestexample 2input arr 5555output Explanation there valid 24hour time 5555 valid Constraintsarrlength 40 arri 9 | 2string
|
you give integer array deck there deck card card unique integer the integer ith card deckiyou order deck order want Initially card start face unrevealed deckyou follow step repeatedly card revealedtake card deck reveal deckif card deck card deck deckif unrevealed card step 1 otherwise stopreturn order deck reveal card increase ordernote entry answer consider deck example 1input deck 1713112357output 2133115177explanation we deck order 1713112357 order matter reorder itafter reorder deck start 2133115177 2 deckwe reveal 2 13 the deck 311517713we reveal 3 11 the deck 51771311we reveal 5 17 the deck 7131117we reveal 7 13 the deck 111713we reveal 11 17 the deck 1317we reveal 13 17 the deck 17we reveal 17since card reveal increase order answer correctexample 2input deck 11000output 11000 Constraints1 decklength 10001 decki 106All value deck unique | 0array
|
for binary tree t define flip operation follows choose node swap leave right child subtreesA binary tree x flip equivalent binary tree Y X equal Y number flip operationsgiven root binary tree root1 root2 return true tree flip equivalent false Example 1input root1 123456nullnullnull78 root2 132null645nullnullnullnull87output trueexplanation we flip node value 1 3 5example 2input root1 root2 output trueExample 3input root1 root2 1Output false ConstraintsThe number nod tree range 0 100each tree unique node value range 0 99 | 1graph
|
you give integer array unique positive integer num consider follow graphthere numslength node label nums0 numsnumslength 1there undirected edge numsi numsj numsi numsj share common factor great 1return size large connect component graph Example 1input num 461535output 4example 2input num 2050963output 2example 3input num 23674122139output 8 Constraints1 numslength 2 1041 numsi 105All value num unique | 0array
|
give integer array length arr return true possible reorder arr arr2 1 2 arr2 0 lenarr 2 false Example 1input arr 3136output falseExample 2input arr 2126output falseExample 3Input arr 4224output trueexplanation we group 24 24 form 2424 2424 constraints2 arrlength 3 104arrlength even105 arri 105 | 0array
|
you instal billboard want large height the billboard steel support each steel support equal heightyou give collection rod weld for example rod length 1 2 3 weld support length 6return large possible height billboard installation if support billboard return 0 example 1input rod 1236output 6explanation we disjoint subset 123 6 sum 6example 2input rod 123456output 10explanation we disjoint subset 235 46 sum 10example 3input rod 12output 0explanation the billboard support return 0 Constraints1 rodslength 201 rodsi 1000sumrodsi 5000 | 0array
|
there 8 prison cell row cell occupy vacantEach day cell occupy vacant change accord follow rulesIf cell adjacent neighbor occupy vacant cell occupiedotherwise vacantnote prison row cell row can not adjacent neighborsyou give integer array cell cellsi 1 ith cell occupy cellsi 0 ith cell vacant give integer nReturn state prison n day ie n change describe Example 1input cell 01011001 n 7output 00110000explanation the following table summarize state prison dayday 0 0 1 0 1 1 0 0 1day 1 0 1 1 0 0 0 0 0day 2 0 0 0 0 1 1 1 0day 3 0 1 1 0 0 1 0 0day 4 0 0 0 0 0 1 0 0day 5 0 1 1 1 0 1 0 0day 6 0 0 1 0 1 1 0 0day 7 0 0 1 1 0 0 0 0example 2input cell 10010010 n 1000000000output 00111110 constraintscellslength 8cellsi 0 11 n 109 | 0array
|
give root binary tree determine complete binary treeIn complete binary tree level possibly completely fill node level far leave possible it 1 2h node inclusive level h example 1input root 123456output trueexplanation every level ie level nodevalue 1 2 3 node level 4 5 6 far leave possibleexample 2input root 12345null7output falseexplanation the node value 7 is not far leave possible ConstraintsThe number nod tree range 1 1001 Nodeval 1000 | 1graph
|
an n x n grid compose 1 x 1 square 1 x 1 square consist blank space these character divide square contiguous regionsGiven grid grid represent string array return number regionsnote backslash character escape represent Example 1input grid output 2example 2input grid Output 1example 3input grid Output 5explanation Recall character escape refer refer Constraintsn gridlength gridilength1 n 30gridij | 1graph
|
you give integer array num follow propertiesnumslength 2 nnum contain n 1 unique elementsexactly element num repeat n timesreturn element repeat n time Example 1input num 1233output 3example 2input num 212532output 2example 3input num 51525354output 5 constraints2 n 5000numslength 2 n0 numsi 104nums contain n 1 unique element repeat exactly n time | 0array
|
a ramp integer array num pair j j numsi numsj the width ramp j iGiven integer array num return maximum width ramp num if ramp num return 0 example 1input num 608215output 4explanation the maximum width ramp achieve j 1 5 nums1 0 nums5 5example 2input num 9810194041output 7explanation the maximum width ramp achieve j 2 9 nums2 1 nums9 1 constraints2 numslength 5 1040 numsi 5 104 | 0array
|
you give array point XY plane point pointsi xi yiReturn minimum area rectangle form point side necessarily parallel x Y axis if rectangle return 0answer 105 actual answer accept Example 1input point 12211001output 200000explanation the minimum area rectangle occur 12211001 area 2example 2input point 0121111020output 100000explanation the minimum area rectangle occur 10112120 area 1example 3input point 0312311321output 0explanation there possible rectangle form point Constraints1 pointslength 50pointsilength 20 xi yi 4 104all give point unique | 0array
|
a binary tree univalue node tree valueGiven root binary tree return true give tree univalue false Example 1input root 11111null1output trueExample 2input root 22252output false ConstraintsThe number nod tree range 1 1000 Nodeval 100 | 1graph
|
give integer n k return array integer length n difference consecutive digit k you return answer ordernote integer lead zero integer 02 043 allow Example 1input n 3 k 7output 181292707818929explanation note 070 valid number lead zeroesexample 2input n 2 k 1Output 1012212332344345545665677678878998 Constraints2 n 90 k 9 | 1graph
|
you give root binary tree we install camera tree nod camera node monitor parent immediate childrenReturn minimum number camera need monitor node tree Example 1input root 00null00output 1explanation one camera monitor node place shownexample 2input root 00null0null0nullnull0Output 2explanation at camera need monitor node tree the image show valid configuration camera placement ConstraintsThe number nod tree range 1 1000nodeval 0 | 1graph
|
give array integer arr sort array perform series pancake flipsIn pancake flip follow stepschoose integer k 1 k arrlengthReverse subarray arr0k1 0indexedFor example arr 3214 perform pancake flip choose k 3 reverse subarray 321 arr 1234 pancake flip k 3Return array kvalue correspond sequence pancake flips sort arr any valid answer sort array 10 arrlength flip judge correct Example 1input arr 3241output 4243explanation we perform 4 pancake flips k value 4 2 4 3starting state arr 3 2 4 1after 1st flip k 4 arr 1 4 2 3after 2nd flip k 2 arr 4 1 2 3after 3rd flip k 4 arr 3 2 1 4after 4th flip k 3 arr 1 2 3 4 sortedexample 2input arr 123Output Explanation the input sort need flip anythingnote answer 3 3 accept Constraints1 arrlength 1001 arri arrlengthAll integers arr unique ie arr permutation integer 1 arrlength | 0array
|
you give root binary tree n node node uniquely assign value 1 n you give sequence n value voyage desire preorder traversal binary treeAny node binary tree flip swapping leave right subtree for example flip node 1 follow effectflip small number node preorder traversal tree match voyagereturn list value flip node you return answer order if impossible flip node tree preorder traversal match voyage return list 1 Example 1input root 12 voyage 21output 1explanation it impossible flip node preorder traversal match voyageexample 2input root 123 voyage 132output 1explanation Flipping node 1 swap nod 2 3 preorder traversal match voyageexample 3input root 123 voyage 123output Explanation the tree preorder traversal match voyage node need flip ConstraintsThe number nod tree nn voyagelength1 n 1001 Nodeval voyagei nAll value tree uniqueall value voyage unique | 1graph
|
give string s t represent nonnegative rational number return true represent number the string use parenthesis denote repeat rational numbera rational number represent part IntegerPart nonrepeatingpart RepeatingPart the number represent follow waysIntegerPartFor example 12 0 123integerpartnonrepeatingpartfor example 05 1 212 1230001integerpartnonrepeatingpartrepeatingpartfor example 016 19 123001212the repeat portion decimal expansion conventionally denote pair round bracket for example16 016666666 016 016666 016666 Example 1input s 052 t 0525output trueexplanation because 052 represent 052525252 0525 represent 052525252525 string represent numberExample 2input s 016666 t 016666output trueExample 3input s 099 t 1output trueExplanation 099 represent 0999999999 repeat forever equal 1 see link explanation1 represent number 1 form correctly IntegerPart 1 nonrepeatingpart ConstraintsEach consist digitsthe IntegerPart lead zero zero itself1 IntegerPartlength 40 nonrepeatingpartlength 41 RepeatingPartlength 4 | 2string
|
give array point pointsi xi yi represent point XY plane integer k return k close point origin 0 0the distance point XY plane Euclidean distance ie x1 x22 y1 y22you return answer order the answer guarantee unique order Example 1input point 1322 k 1Output 22explanationthe distance 1 3 origin sqrt10the distance 2 2 origin sqrt8Since sqrt8 sqrt10 2 2 close originWe want close k 1 point origin answer 22example 2input point 335124 k 2output 3324explanation the answer 2433 accept Constraints1 k pointslength 104104 xi yi 104 | 0array
|
give integer array num integer k return number nonempty subarray sum divisible kA subarray contiguous array Example 1input num 450231 k 5output 7explanation there 7 subarray sum divisible k 54 5 0 2 3 1 5 5 0 5 0 2 3 0 0 2 3 2 3example 2input num 5 k 9output 0 Constraints1 numslength 3 104104 numsi 1042 k 104 | 0array
|
you give integer array arr from start index series jump the 1st 3rd 5th jump series call oddnumbered jump 2nd 4th 6th jump series call evennumbered jump Note jumps number indicesyou jump forward index index j j follow wayduring oddnumbered jump ie jump 1 3 5 jump index j arri arrj arrj small possible value if multiple index j jump small index jDuring evennumbered jump ie jump 2 4 6 jump index j arri arrj arrj large possible value if multiple index j jump small index jIt case index legal jumpsA start index good start index reach end array index arrlength 1 jumping number time possibly 0 oncereturn number good start index Example 1input arr 1013121415output 2explanation from start index 0 1st jump 2 arr2 small arr1 arr2 arr3 arr4 greater equal arr0 jump moreFrom start index 1 2 1st jump 3 jump moreFrom start index 3 1st jump 4 reach endfrom start index 4 reach end alreadyIn total 2 different start index 3 4 reach end number ofjumpsexample 2input arr 23114output 3explanation from start index 0 jump 1 2 3during 1st jump oddnumbered jump 1 arr1 small value arr1 arr2 arr3 arr4 greater equal arr0during 2nd jump evennumbered jump 1 2 arr2 large value arr2 arr3 arr4 equal arr1 arr3 large value 2 small index jump 2 3during 3rd jump oddnumbered jump 2 3 arr3 small value arr3 arr4 greater equal arr2We can not jump 3 4 start index 0 goodIn similar manner deduce thatfrom start index 1 jump 4 reach endfrom start index 2 jump 3 can not jump anymorefrom start index 3 jump 4 reach endfrom start index 4 endIn total 3 different start index 1 3 4 reach end somenumber jumpsExample 3Input arr 51342output 3explanation we reach end start index 1 2 4 constraints1 arrlength 2 1040 arri 105 | 0array
|
give integer array num return large perimeter triangle nonzero area form length if impossible form triangle nonzero area return 0 example 1input num 212output 5Example 2input num 121output 0 constraints3 numslength 1041 numsi 106 | 0array
|
give integer array num sort nondecrease order return array square number sort nondecrease order Example 1input num 410310output 01916100explanation after square array 16109100after sort 01916100example 2input num 732311output 49949121 Constraints1 numslength 104104 numsi 104nums sort nondecrease order Follow squaring element sort new array trivial find on solution different approach | 0array
|
give integer array arr return length maximum size turbulent subarray arrA subarray turbulent comparison sign flips adjacent pair element subarrayMore formally subarray arri arri 1 arrj arr say turbulent ifFor k jarrk arrk 1 k odd andarrk arrk 1 k evenOr k jarrk arrk 1 k andarrk arrk 1 k odd Example 1input arr 9421078819output 5explanation arr1 arr2 arr3 arr4 arr5Example 2Input arr 481216output 2Example 3Input arr 100Output 1 Constraints1 arrlength 4 1040 arri 109 | 0array
|
you give root binary tree n node node tree nodeval coin there n coin total treeIn choose adjacent node coin node a parent child child parentreturn minimum number move require node exactly coin Example 1input root 300output 2explanation from root tree coin leave child coin right childExample 2input root 030output 3explanation from left child root coin root take move then coin root tree right child ConstraintsThe number nod tree n1 n 1000 Nodeval nThe sum Nodeval n | 1graph
|
you give m x n integer array grid gridij be1 represent start square there exactly start square2 represent end square there exactly end square0 represent square walk over1 represent obstacle walk overreturn number 4directional walk start square end square walk nonobstacle square exactly Example 1input grid 100000000021output 2explanation we follow path 1 00010203131211102021222 0010202111010203131222example 2input grid 100000000002output 4explanation we follow path 1 0001020313121110202122232 0001111020212212020313233 0010202122121101020313234 001020211101020313122223example 3input grid 0120output 0explanation there path walk square exactly oncenote start end square grid Constraintsm gridlengthn gridilength1 m n 201 m n 201 gridij 2There exactly start cell end cell | 0array
|
Design timebase keyvalue data structure store multiple value key different time stamp retrieve key value certain timestampimplement TimeMap classtimemap initialize object datum structurevoid setstre key String value int timestamp store key key value value give time timestampstre getstre key int timestamp return value set call previously timestamp_prev timestamp if multiple value return value associate large timestamp_prev if value return Example 1inputtimemap set set foo bar 1 foo 1 foo 3 foo bar2 4 foo 4 foo 5outputnull null bar bar null bar2 bar2ExplanationTimeMap timeMap new TimeMaptimeMapsetfoo bar 1 store key foo value bar timestamp 1timemapgetfoo 1 return bartimeMapgetfoo 3 return bar value correspond foo timestamp 3 timestamp 2 value timestamp 1 bartimeMapsetfoo bar2 4 store key foo value bar2 timestamp 4timemapgetfoo 4 return bar2timeMapgetfoo 5 return bar2 Constraints1 keylength valuelength 100key value consist lowercase English letter digits1 timestamp 107all timestamp timestamp set strictly increasingat 2 105 call set | 2string
|
give integer array num return number and triplesan and triple triple index j k that0 numslength0 j numslength0 k numslengthnumsi numsj numsk 0 represent bitwiseand operator Example 1input num 213output 12Explanation we choose follow j k triplesi0 j0 k1 2 2 1i0 j1 k0 2 1 2i0 j1 k1 2 1 1i0 j1 k2 2 1 3i0 j2 k1 2 3 1i1 j0 k0 1 2 2i1 j0 k1 1 2 1i1 j0 k2 1 2 3i1 j1 k0 1 1 2i1 j2 k0 1 3 2i2 j0 k1 3 2 1i2 j1 k0 3 1 2example 2input num 000output 27 Constraints1 numslength 10000 numsi 216 | 0array
|
you plan train travel year advance the day year travel give integer array day each day integer 1 365train ticket sell different waysa 1day pass sell costs0 dollarsa 7day pass sell costs1 dollar anda 30day pass sell costs2 dollarsthe pass allow day consecutive travelFor example 7day pass day 2 travel 7 day 2 3 4 5 6 7 8return minimum number dollar need travel day give list day Example 1input day 1467820 cost 2715output 11explanation for example way buy pass let travel travel planOn day 1 buy 1day pass costs0 2 cover day 1on day 3 buy 7day pass costs1 7 cover day 3 4 9on day 20 buy 1day pass costs0 2 cover day 20in total spend 11 cover day travelExample 2input day 123456789103031 cost 2715output 17explanation for example way buy pass let travel travel planOn day 1 buy 30day pass costs2 15 cover day 1 2 30on day 31 buy 1day pass costs0 2 cover day 31in total spend 17 cover day travel Constraints1 dayslength 3651 daysi 365days strictly increase ordercostslength 31 costsi 1000 | 0array
|
give integer b return string s that s length b contain exactly letter exactly b b lettersthe substre aaa occur s andthe substre bbb occur s Example 1input 1 b 2output abbexplanation abb bab bba correct answersexample 2input 4 b 1Output aabaa Constraints0 b 100it guarantee s exist give b | 2string
|
you give integer array nums array query queriesi vali indexiFor query apply numsindexi numsindexi vali print sum value numsReturn integer array answer answeri answer ith query Example 1input num 1234 query 10314023output 8624explanation at begin array 1234after add 1 nums0 array 2234 sum value 2 2 4 8after add 3 nums1 array 2134 sum value 2 4 6after add 4 nums0 array 2134 sum value 2 4 2after add 2 nums3 array 2136 sum value 2 6 4example 2input num 1 query 40output 0 constraints1 numslength 104104 numsi 1041 querieslength 104104 vali 1040 indexi numslength | 0array
|
you give list close interval firstlist secondlist firstListi starti endi secondListj startj endj each list interval pairwise disjoint sort orderreturn intersection interval listsA close interval b b denote set real number x x bThe intersection close interval set real number represent closed interval for example intersection 1 3 2 4 2 3 Example 1input firstlist 0251013232425 secondlist 1581215242526output 1255810152324242525example 2input firstlist 1359 secondList output Constraints0 firstlistlength secondlistlength 1000firstlistlength secondlistlength 10 starti endi 109endi starti10 startj endj 109endj startj1 | 0array
|
give root binary tree calculate vertical order traversal binary treefor node position row col leave right child position row 1 col 1 row 1 col 1 respectively the root tree 0 0the vertical order traversal binary tree list toptobottom ordering column index start leftmost column end rightmost column there multiple node row column in case sort nod valuesreturn vertical order traversal binary tree Example 1input root 3920nullnull157output 9315207explanationcolumn 1 only node 9 columncolumn 0 node 3 15 column order bottomcolumn 1 only node 20 columncolumn 2 only node 7 columnexample 2input root 1234567output 4215637explanationcolumn 2 only node 4 columnColumn 1 only node 2 columncolumn 0 node 1 5 6 column 1 come 5 6 position 2 0 order value 5 6column 1 only node 3 columncolumn 2 only node 7 columnExample 3input root 1234657output 4215637explanationthis case exact example 2 node 5 6 swappednote solution remain 5 6 location order value ConstraintsThe number nod tree range 1 10000 Nodeval 1000 | 1graph
|
the arrayform integer num array represent digit leave right orderfor example num 1321 array form 1321given num arrayform integer integer k return arrayform integer num k Example 1input num 1200 k 34output 1234explanation 1200 34 1234example 2input num 274 k 181Output 455Explanation 274 181 455example 3input num 215 k 806output 1021explanation 215 806 1021 Constraints1 numlength 1040 numi 9num contain lead zeros zero itself1 k 104 | 0array
|
give integer array num integer k return number good subarray numsA good array array number different integer array exactly kFor example 12312 3 different integer 1 2 3A subarray contiguous array Example 1input num 12123 k 2output 7Explanation Subarrays form exactly 2 different integer 12 21 12 23 121 212 1212example 2input num 12134 k 3output 3explanation Subarrays form exactly 3 different integer 1213 213 134 Constraints1 numslength 2 1041 numsi k numslength | 0array
|
give root binary tree unique value value different node tree x y return true node correspond value x y tree cousin false otherwisetwo nod binary tree cousin depth different parentsNote binary tree root node depth 0 child depth k node depth k 1 Example 1input root 1234 x 4 y 3Output falseExample 2input root 123null4null5 x 5 y 4Output trueExample 3input root 123null4 x 2 y 3output false ConstraintsThe number nod tree range 2 1001 Nodeval 100each node unique valuex yx y exist tree | 1graph
|
you give binary array nums integer kA kbit flip choose subarray length k num simultaneously change 0 subarray 1 1 subarray 0return minimum number kbit flips require 0 array if possible return 1A subarray contiguous array Example 1input num 010 k 1output 2Explanation Flip nums0 flip nums2Example 2input num 110 k 2output 1explanation no matter flip subarray size 2 array 111example 3input num 00010110 k 3output 3explanation Flip nums0nums1nums2 num 11110110Flip nums4nums5nums6 nums 11111000Flip nums5nums6nums7 num 11111111 Constraints1 numslength 1051 k numslength | 0array
|
an array squareful sum pair adjacent element perfect squaregiven integer array num return number permutation num squarefultwo permutation perm1 perm2 different index perm1i perm2i Example 1input num 1178output 2explanation 1817 1781 valid permutationsExample 2input num 222output 1 constraints1 numslength 120 numsi 109 | 0array
|
on 8 x 8 chessboard exactly white rook r number white bishop b black pawn p square when rook move choose cardinal direction north east south west move direction choose stop reach edge board capture black pawn block white bishop a rook consider attack pawn rook capture pawn rook turn the number available captures white rook number pawns rook attackingreturn number available captures white rook Example 1input board prppoutput 3explanation in example rook attack pawnsexample 2input board pppppppbpppbrbpppbpppppppoutput 0explanation the bishop block rook attack pawnsexample 3input board pppprpbbpoutput 3explanation the rook attack pawn position b5 d6 f5 Constraintsboardlength 8boardilength 8boardij r b pThere exactly cell boardij r | 0array
|
there n pile stone arrange row the ith pile stonesi stonesA consist merge exactly k consecutive pile pile cost equal total number stone k pilesreturn minimum cost merge pile stone pile if impossible return 1 example 1input stone 3241 k 2output 20explanation we start 3 2 4 1we merge 3 2 cost 5 leave 5 4 1we merge 4 1 cost 5 leave 5 5we merge 5 5 cost 10 leave 10the total cost 20 minimum possibleExample 2input stone 3241 k 3output 1explanation after merge operation 2 pile leave can not merge anymore so task impossibleExample 3input stone 35126 k 3output 25explanation we start 3 5 1 2 6we merge 5 1 2 cost 8 leave 3 8 6we merge 3 8 6 cost 17 leave 17the total cost 25 minimum possible Constraintsn stoneslength1 n 301 stonesi 1002 k 30 | 0array
|
there 2D grid size n x n cell grid lamp initially turn offyou give 2D array lamp position lamp lampsi rowi coli indicate lamp gridrowicoli turn even lamp list turn onwhen lamp turn illuminates cell cell row column diagonalyou give 2D array query queriesj rowj colj for jth query determine gridrowjcolj illuminate after answer jth query turn lamp gridrowjcolj 8 adjacent lamp exist a lamp adjacent cell share corner gridrowjcoljReturn array integer ans ansj 1 cell jth query illuminate 0 lamp Example 1input n 5 lamp 0044 query 1110output 10explanation we initial grid lamp turn in picture grid turn lamp grid00 turn lamp grid44the 0th query ask lamp grid11 illuminate blue square it illuminate set ans0 1 then turn lamp red squarethe 1st query ask lamp grid10 illuminate blue square it illuminate set ans1 0 then turn lamp red rectangleexample 2input n 5 lamp 0044 query 1111output 11example 3input n 5 lamp 0004 query 040114output 110 Constraints1 n 1090 lampslength 200000 querieslength 20000lampsilength 20 rowi coli nqueriesjlength 20 rowj colj n | 0array
|
give string s determine valida string s valid start string t transform t s perform follow operation number timesInsert stre abc position t more formally t tleft abc tright t tleft tright Note tleft tright emptyReturn true s valid string return false example 1input s aabcbcoutput trueexplanation abc aabcbcthus aabcbc validExample 2input s abcabcababccoutput trueexplanation abc abcabc abcabcabc abcabcababccThus abcabcababcc validExample 3input s abccbaoutput falseexplanation it impossible abccba operation Constraints1 slength 2 104s consist letter b c | 2string
|
give binary array num integer k return maximum number consecutive 1s array flip k 0s Example 1input num 11100011110 k 2output 6explanation 11100111111bolded number flip 0 1 the long subarray underlinedExample 2input num 0011001110110001111 k 3Output 10explanation 0011111111110001111bolded number flip 0 1 the long subarray underline Constraints1 numslength 105numsi 0 10 k numslength | 0array
|
give integer array num integer k modify array follow waychoose index replace numsi numsiyou apply process exactly k time you choose index multiple timesreturn large possible sum array modifying way example 1input num 423 k 1output 5Explanation Choose index 1 num 423example 2input num 3102 k 3output 6explanation Choose index 1 2 2 num 3102example 3input num 23154 k 2output 13explanation Choose index 1 4 num 23154 Constraints1 numslength 104100 numsi 1001 k 104 | 0array
|
in row domino topsi bottomsi represent half ith domino a domino tile number 1 6 half tileWe rotate ith domino topsi bottomsi swap valuesreturn minimum number rotation value top value bottom sameif return 1 Example 1input top 212422 bottom 526232output 2explanation the figure represent domino give top bottom rotationsIf rotate second fourth domino value row equal 2 indicate second figureexample 2input top 35123 bottom 36334output 1explanation in case possible rotate domino row value equal Constraints2 topslength 2 104bottomslength topslength1 topsi bottomsi 6 | 0array
|
give array integer preorder represent preorder traversal BST ie binary search tree construct tree return rootIt guarantee possible find binary search tree give requirement give test casesA binary search tree binary tree node descendant Nodeleft value strictly Nodeval descendant Noderight value strictly great NodevalA preorder traversal binary tree display value node traverse Nodeleft traverse Noderight Example 1input preorder 85171012output 851017null12example 2input preorder 13Output 1null3 Constraints1 preorderlength 1001 preorderi 1000all value preorder unique | 0array
|
you give list song ith song duration timei secondsReturn number pair song total duration second divisible 60 formally want number indice j j timei timej 60 0 example 1input time 302015010040output 3explanation three pair total duration divisible 60time0 30 time2 150 total duration 180time1 20 time3 100 total duration 120time1 20 time4 40 total duration 60example 2input time 606060output 3explanation all pair total duration 120 divisible 60 Constraints1 timelength 6 1041 timei 500 | 0array
|
a conveyor belt package ship port day daysThe ith package conveyor belt weight weightsi each day load ship package conveyor belt order give weight we load weight maximum weight capacity shipreturn weight capacity ship result package conveyor belt ship day day Example 1input weight 12345678910 day 5output 15explanation a ship capacity 15 minimum ship package 5 day like this1st day 1 2 3 4 52nd day 6 73rd day 84th day 95th day 10note cargo ship order give ship capacity 14 splitting package part like 2 3 4 5 1 6 7 8 9 10 allowedexample 2input weight 322414 day 3output 6explanation a ship capacity 6 minimum ship package 3 day like this1st day 3 22nd day 2 43rd day 1 4example 3input weight 12311 day 4Output 3Explanation1st day 12nd day 23rd day 34th day 1 1 constraints1 day weightslength 5 1041 weightsi 500 | 0array
|
give array integer arr return true partition array nonempty part equal sumsformally partition array find index 1 j arr0 arr1 arri arri 1 arri 2 arrj 1 arrj arrj 1 arrarrlength 1 Example 1input arr 02166791201output trueexplanation 0 2 1 6 6 7 9 1 2 0 1example 2input arr 02166791201Output falseexample 3input arr 3365225194output trueexplanation 3 3 6 5 2 2 5 1 9 4 constraints3 arrlength 5 104104 arri 104 | 0array
|
you give integer array value valuesi represent value ith sightseeing spot two sightseeing spot j distance j themthe score pair j sightseeing spot valuesi valuesj j sum value sightseeing spot minus distance themreturn maximum score pair sightseeing spot Example 1input value 81526output 11explanation 0 j 2 valuesi valuesj j 8 5 0 2 11example 2input value 12output 2 constraints2 valueslength 5 1041 valuesi 1000 | 0array
|
give binary string s positive integer n return true binary representation integer range 1 n substring s false otherwisea substre contiguous sequence character string Example 1input s 0110 n 3output trueExample 2Input s 0110 n 4output false Constraints1 slength 1000si 0 11 n 109 | 2string
|
you give binary array num 0indexedwe define xi number binary representation subarray nums0i mostsignificantbit leastsignificantbitfor example num 101 x0 1 x1 2 x2 5Return array booleans answer answeri true xi divisible 5 Example 1input num 011output truefalsefalseexplanation the input number binary 0 01 011 0 1 3 base10only number divisible 5 answer0 trueexample 2input num 111output falsefalsefalse Constraints1 numslength 105numsi 0 1 | 0array
|
you give head link list n nodesfor node list find value great node that node find value node strictly large value itreturn integer array answer answeri value great node ith node 1indexed if ith node great node set answeri 0 example 1input head 215output 550example 2input head 27435output 70550 ConstraintsThe number node list n1 n 1041 Nodeval 109 | 0array
|
Subsets and Splits