question
stringlengths
58
4.29k
label
class label
3 classes
a valid parenthesis stre a a B A b valid parenthesis string represent stre concatenationfor example valid parenthesis stringsa valid parenthesis stre s primitive nonempty exist way split s a B a b nonempty valid parenthesis stringsgiven valid parenthesis string s consider primitive decomposition s p1 P2 Pk Pi primitive valid parenthese stringsReturn s remove outermost parenthese primitive string primitive decomposition s Example 1input s Output Explanation the input string primitive decomposition after remove outer parenthesis Example 2input s Output Explanation the input string primitive decomposition after remove outer parenthesis Example 3input s Output Explanation the input string primitive decomposition after remove outer parenthesis Constraints1 slength 105si s valid parenthesis string
2string
you give root binary tree node value 0 1 each roottoleaf path represent binary number start significant bitFor example path 0 1 1 0 1 represent 01101 binary 13For leave tree consider number represent path root leaf Return sum numbersthe test case generate answer fit 32bits integer Example 1input root 1010101output 22explanation 100 101 110 111 4 5 6 7 22example 2input root 0output 0 constraintsthe number nod tree range 1 1000nodeval 0 1
1graph
give array string query string pattern return boolean array answer answeri true queriesi match pattern false otherwisea query word queriesi match pattern insert lowercase English letter pattern equal query you insert character position insert character Example 1input query foobarfoobartestfootballframebufferforcefeedback pattern FBOutput truefalsetruetruefalseexplanation foobar generate like F oo B arfootball generate like F oot B allframebuffer generate like F rame B ufferexample 2input query foobarfoobartestfootballframebufferforcefeedback pattern FoBaOutput truefalsetruefalsefalseExplanation FooBar generate like Fo o Ba rfootball generate like Fo ot Ba llExample 3input query foobarfoobartestfootballframebufferforcefeedback pattern fobatoutput falsetruefalsefalsefalseexplanation foobartest generate like Fo o Ba r t e Constraints1 patternlength querieslength 1001 queriesilength 100queriesi pattern consist english letter
2string
you give series video clip sport event last time second these video clip overlap vary lengthsEach video clip describe array clip clipsi starti endi indicate ith clip start starti end endiWe cut clip segment freelyFor example clip 0 7 cut segment 0 1 1 3 3 7return minimum number clip need cut clip segment cover entire sporting event 0 time if task impossible return 1 example 1input clip 0246810191559 time 10output 3explanation we clip 02 810 19 total 3 clipsthen reconstruct sporting event followsWe cut 19 segment 12 28 89now segment 02 28 810 cover sporting event 0 10example 2input clip 0112 time 5output 1explanation we cover 05 01 12example 3input clip 01680256040367134714252634455769 time 9output 3explanation we clip 04 47 69 Constraints1 clipslength 1000 starti endi 1001 time 100
0array
give root binary tree find maximum value v exist different node b v aval bval ancestor ba node ancestor b child equal b child ancestor b Example 1input root 831016null14nullnull4713output 7explanation we ancestornode difference give 8 3 53 7 48 1 710 13 3among possible difference maximum value 7 obtain 8 1 7example 2input root 1null2null03Output 3 ConstraintsThe number nod tree range 2 50000 Nodeval 105
1graph
give array num integer return length long arithmetic subsequence numsrecall subsequence array num list numsi1 numsi2 numsik 0 i1 i2 ik numslength 1 sequence seq arithmetic seqi1 seqi value 0 seqlength 1 example 1input num 36912output 4explanation the array arithmetic sequence step length 3example 2input num 947210output 3explanation the long arithmetic subsequence 4710example 3input num 2011531058output 4explanation the long arithmetic subsequence 2015105 constraints2 numslength 10000 numsi 500
0array
a company planning interview 2n people give array cost costsi aCosti bCosti cost fly ith person city aCosti cost fly ith person city b bcostireturn minimum cost fly person city exactly n people arrive city Example 1input cost 102030200400503020output 110explanation the person go city a cost 10the second person go city a cost 30the person go city B cost 50the fourth person go city b cost 20the total minimum cost 10 30 50 20 110 half people interview cityExample 2input cost 25977044854926667184139840118577469output 1859example 3input cost 5155634517135377093438198557794576065035963142output 3086 Constraints2 n costslength2 costslength 100costslength even1 aCosti bCosti 1000
0array
you give integer row cols rCenter cCenter there row x cols matrix cell coordinate rCenter ccenterreturn coordinate cell matrix sort distance rCenter cCenter small distance large distance you return answer order satisfie conditionthe distance cell r1 c1 r2 c2 r1 r2 c1 c2 Example 1input row 1 col 2 rcenter 0 ccenter 0output 0001explanation the distance 0 0 cell 01Example 2input row 2 col 2 rcenter 0 cCenter 1output 01001110explanation the distance 0 1 cell 0112the answer 01110010 accept correctExample 3input row 2 col 3 rcenter 1 ccenter 2output 120211011000explanation the distance 1 2 cell 011223there answer accept correct 121102100100 Constraints1 row col 1000 rCenter rows0 ccenter col
0array
give integer array num integer firstlen secondlen return maximum sum element nonoverlappe subarray length firstlen secondlenthe array length firstLen occur array length secondLen nonoverlappinga subarray contiguous array Example 1input num 065225194 firstLen 1 secondlen 2output 20explanation one choice subarray 9 length 1 65 length 2example 2input num 381321890 firstlen 3 secondlen 2output 29explanation one choice subarray 381 length 3 89 length 2example 3input num 2156095038 firstLen 4 secondlen 3output 31Explanation one choice subarray 5609 length 4 038 length 3 constraints1 firstlen secondLen 10002 firstLen secondlen 1000firstlen secondLen numslength 10000 numsi 1000
0array
you give integer array nums1 nums2 we write integer nums1 nums2 order give separate horizontal linesWe draw connect line straight line connect number nums1i nums2j thatnums1i nums2j andthe line draw intersect connect nonhorizontal linenote connect line intersect endpoint ie number belong connect lineReturn maximum number connect line draw way example 1input nums1 142 nums2 124output 2explanation we draw 2 uncrossed line diagramWe draw 3 uncrossed line line nums11 4 nums22 4 intersect line nums122 nums212Example 2Input nums1 25125 nums2 1052152output 3Example 3input nums1 137175 nums2 19251output 2 Constraints1 nums1length nums2length 5001 nums1i nums2j 2000
0array
give array point pointsi xi yi represent point XY plane return true point boomerangA boomerang set point distinct straight line example 1input point 112332output trueexample 2input point 112233output false constraintspointslength 3pointsilength 20 xi yi 100
0array
give root Binary Search Tree BST convert Greater Tree key original BST change original key plus sum key great original key bsta reminder binary search tree tree satisfie constraintsthe leave subtree node contain node key node keythe right subtree node contain nod key great node keyBoth leave right subtree binary search tree Example 1input root 4160257nullnullnull3nullnullnull8Output 30362136352615nullnullnull33nullnullnull8example 2input root 0null1output 1null1 constraintsthe number nod tree range 1 1000 Nodeval 100all value tree unique Note this question 538 httpsleetcodecomproblemsconvertbsttogreatertree
1graph
you convex nside polygon vertex integer value you give integer array value valuesi value ith vertex ie clockwise orderyou triangulate polygon n 2 triangle for triangle value triangle product value vertice total score triangulation sum value n 2 triangle triangulationreturn small possible total score achieve triangulation polygon example 1input value 123output 6explanation the polygon triangulate score triangle 6example 2input value 3745output 144explanation there triangulation possible score 375 457 245 345 347 144the minimum score 144example 3input value 131415output 13explanation the minimum score triangulation score 113 114 115 111 13 Constraintsn valueslength3 n 501 valuesi 100
0array
there stone different position Xaxis you give integer array stone position stonescall stone endpoint stone small large position in pick endpoint stone unoccupied position long endpoint stonein particular stone stone 125 endpoint stone position 5 move position 0 3 stone endpoint stoneThe game end move ie stone consecutive positionsReturn integer array answer length 2 whereanswer0 minimum number move play andanswer1 maximum number move play Example 1input stone 749output 12explanation we 4 8 finish gameOr 9 5 4 6 move finish gameexample 2input stone 654310output 23explanation we 3 8 10 7 finish gameor 3 7 4 8 5 9 finish gameNotice 10 2 finish game illegal Constraints3 stoneslength 1041 stonesi 109All value stone unique
0array
on infinite plane robot initially stand 0 0 face north Note thatthe north direction positive direction yaxisthe south direction negative direction yaxisthe east direction positive direction xaxisThe west direction negative direction xaxisthe robot receive instructionsg straight 1 unitL turn 90 degree leave ie anticlockwise directionR turn 90 degree right ie clockwise directionthe robot perform instruction give order repeat foreverreturn true exist circle plane robot leave circle Example 1input instruction GGLLGGOutput trueexplanation the robot initially 0 0 face north directionG step position 0 1 direction NorthG step position 0 2 direction NorthL turn 90 degree anticlockwise position 0 2 direction WestL turn 90 degree anticlockwise position 0 2 direction southg step position 0 1 direction southg step position 0 0 Direction SouthRepeating instruction robot go cycle 0 0 0 1 0 2 0 1 0 0based return trueexample 2input instruction ggoutput falseexplanation the robot initially 0 0 face north directionG step position 0 1 direction NorthG step position 0 2 direction NorthRepeating instruction keep advance north direction cyclesbase return falseexample 3input instruction gloutput trueexplanation the robot initially 0 0 face north directionG step position 0 1 direction NorthL turn 90 degree anticlockwise position 0 1 Direction WestG step position 1 1 Direction WestL turn 90 degree anticlockwise position 1 1 direction southg step position 1 0 direction southl turn 90 degree anticlockwise position 1 0 Direction EastG step position 0 0 Direction EastL turn 90 degree anticlockwise position 0 0 Direction NorthRepeating instruction robot go cycle 0 0 0 1 1 1 1 0 0 0base return true Constraints1 instructionslength 100instructionsi G L R
2string
you n garden label 1 n array path pathsi xi yi describe bidirectional path garden xi garden yi in garden want plant 4 type flowersAll garden 3 path come leave ityour task choose flower type garden garden connect path different type flowersreturn choice array answer answeri type flower plant i1th garden the flower type denote 1 2 3 4 it guarantee answer exist Example 1input n 3 path 122331output 123explanationgardens 1 2 different typesgarden 2 3 different typesgarden 3 1 different typeshence 123 valid answer other valid answer include 124 142 321example 2input n 4 path 1234output 1212example 3input n 4 path 122334411324output 1234 Constraints1 n 1040 pathslength 2 104pathsilength 21 xi yi nxi yiEvery garden 3 path come leave
1graph
give integer array arr partition array contiguous subarray length k after partition subarray value change maximum value subarrayreturn large sum give array partition test case generate answer fit 32bit integer Example 1input arr 115792510 k 3Output 84Explanation arr 1515159101010example 2Input arr 14157361993 k 4Output 83Example 3input arr 1 k 1output 1 Constraints1 arrlength 5000 arri 1091 k arrlength
0array
you give array integer stones stonesi weight ith stoneWe playing game stone on turn choose heavy stone smash suppose heavy stone weight x y x y the result smash isIf x y stone destroy andIf x y stone weight x destroy stone weight y new weight y xAt end game stone leftReturn weight remain stone if stone leave return 0 example 1input stone 274181output 1explanation we combine 7 8 1 array convert 24111 thenwe combine 2 4 2 array convert 2111 thenwe combine 2 1 1 array convert 111 thenwe combine 1 1 0 array convert 1 that s value stoneexample 2input stone 1output 1 Constraints1 stoneslength 301 stonesi 1000
0array
you give string s consist lowercase english letter a duplicate removal consists choose adjacent equal letter remove themWe repeatedly duplicate removal s long canreturn final string duplicate removal it prove answer unique Example 1input s abbacaoutput caexplanation for example abbaca remove bb letter adjacent equal possible the result stre aaca aa possible final string caExample 2input s azxxzyoutput ay Constraints1 slength 105s consist lowercase english letter
2string
you give array integer stones stonesi weight ith stoneWe playing game stone on turn choose stone smash suppose stone weight x y x y the result smash isIf x y stone destroy andIf x y stone weight x destroy stone weight y new weight y xAt end game stone leftReturn small possible weight leave stone if stone leave return 0 example 1input stone 274181output 1explanationwe combine 2 4 2 array convert 27181 thenwe combine 7 8 1 array convert 2111 thenwe combine 2 1 1 array convert 111 thenwe combine 1 1 0 array convert 1 that s optimal valueexample 2input stone 3126332140output 5 Constraints1 stoneslength 301 stonesi 100
0array
a school try annual photo student the student ask stand single file line nondecrease order height let ordering represent integer array expect expectedi expect height ith student lineyou give integer array height represent current order student stand each heightsi height ith student line 0indexedreturn number index heightsi expectedi Example 1input height 114213output 3explanation height 114213expecte 111234indices 2 4 5 matchexample 2input height 51234output 5explanationheight 51234expecte 12345all index matchexample 3input height 12345output 0explanationheight 12345expecte 12345all index match Constraints1 heightslength 1001 heightsi 100
0array
there bookstore owner store open n minute every minute number customer enter store you give integer array customer length n customersi number customer enter store start ith minute customer leave end minuteOn minutes bookstore owner grumpy you give binary array grumpy grumpyi 1 bookstore owner grumpy ith minute 0 otherwiseWhen bookstore owner grumpy customer minute satisfied satisfiedThe bookstore owner know secret technique grumpy minute consecutive minute use oncereturn maximum number customer satisfy day Example 1input customer 10121175 grumpy 01010101 minute 3output 16explanation the bookstore owner keep grumpy 3 minute the maximum number customer satisfy 1 1 1 1 7 5 16example 2input customer 1 grumpy 0 minute 1output 1 Constraintsn customerslength grumpylength1 minute n 2 1040 customersi 1000grumpyi 0 1
0array
give array positive integer arr necessarily distinct return lexicographically large permutation small arr exactly swap a swap exchange position number arri arrj if return array Example 1input arr 321Output 312explanation Swapping 2 1example 2input arr 115Output 115explanation this small permutationExample 3input arr 19467output 17469explanation swap 9 7 constraints1 arrlength 1041 arri 104
0array
in warehouse row barcode ith barcode barcodesirearrange barcode adjacent barcode equal you return answer guarantee answer exist Example 1input barcode 111222output 212121example 2input barcode 11112233output 13131212 Constraints1 barcodeslength 100001 barcodesi 10000
0array
for string s t t divide s s t t ie t concatenate timesgiven string str1 str2 return large string x x divide str1 str2 Example 1input str1 ABCABC str2 ABCOutput ABCExample 2input str1 ABABAB str2 ABABOutput abexample 3input str1 LEET str2 CODEOutput Constraints1 str1length str2length 1000str1 str2 consist english uppercase letter
2string
you give m x n binary matrix matrixyou choose number column matrix flip cell column ie Change value cell 0 1 vice versareturn maximum number row value equal number flip Example 1input matrix 0111output 1explanation after flip value 1 row value equalexample 2input matrix 0110output 2explanation after flip value column row equal valuesexample 3input matrix 000001110output 2explanation after flip value column row equal value Constraintsm matrixlengthn matrixilength1 m n 300matrixij 0 1
0array
give number arr1 arr2 base 2 return result add togetherEach number give array format array 0s 1s significant bit significant bit for example arr 1101 represent number 23 22 20 3 a number arr array format guarantee lead zero arr 0 arr0 1return result add arr1 arr2 format array 0s 1s lead zero example 1input arr1 11111 arr2 101Output 10000explanation arr1 represent 11 arr2 represent 5 output represent 16example 2input arr1 0 arr2 0output 0example 3input arr1 0 arr2 1output 1 Constraints1 arr1length arr2length 1000arr1i arr2i 0 1arr1 arr2 lead zero
0array
give matrix target return number nonempty submatrice sum targetA submatrix x1 y1 x2 y2 set cell matrixxy x1 x x2 y1 y y2Two submatrice x1 y1 x2 y2 x1 y1 x2 y2 different coordinate different example x1 x1 Example 1input matrix 010111010 target 0output 4explanation the 1x1 submatrice contain 0example 2input matrix 1111 target 0output 5explanation the 1x2 submatrice plus 2x1 submatrice plus 2x2 submatrixexample 3input matrix 904 target 0output 0 Constraints1 matrixlength 1001 matrix0length 1001000 matrixi 1000108 target 108
0array
give string second consider occurrence text form second second come immediately come immediately secondreturn array word occurrence second Example 1input text alice good girl good student second goodoutput girlstudentexample 2input text rock second willoutput werock Constraints1 textlength 1000text consist lowercase english letter spacesall word text separate single space1 firstlength secondlength 10first second consist lowercase english letter
2string
you n tile tile letter tilesi print itreturn number possible nonempty sequence letter letter print tile example 1input tile aaboutput 8explanation the possible sequence A B aa AB BA AAB ABA BAAExample 2input tile AAABBCOutput 188example 3input tile VOutput 1 constraints1 tileslength 7tiles consist uppercase english letter
2string
give root binary tree integer limit delete insufficient node tree simultaneously return root result binary treeA node insufficient root leaf path intersect node sum strictly limitA leaf node child Example 1input root 12349999789999912139914 limit 1output 1234nullnull789null14example 2input root 54811null17471nullnull53 limit 22output 54811null1747nullnullnull5example 3input root 1235null4null limit 1output 1null34 ConstraintsThe number nod tree range 1 5000105 Nodeval 105109 limit 109
1graph
give string s return lexicographically smallest subsequence s contain distinct character s exactly Example 1input s bcabcoutput abcexample 2Input s cbacdcbcoutput acdb Constraints1 slength 1000 consists lowercase english letter note this question 316 httpsleetcodecomproblemsremoveduplicateletter
2string
give fixedlength integer array arr duplicate occurrence zero shift remain element rightnote element length original array write do modification input array place return Example 1input arr 10230450output 10023004explanation after call function input array modify 10023004example 2input arr 123output 123explanation after call function input array modify 123 Constraints1 arrlength 1040 arri 9
0array
there set n item you give integer array value label value label ith element valuesi labelsi respectively you give integer numwante uselimitchoose subset s n element thatthe size subset s equal numwantedthere uselimit item label sthe score subset sum value subsetreturn maximum score subset s example 1input value 54321 label 11223 numwante 3 uselimit 1output 9explanation the subset choose fifth itemsExample 2input value 54321 label 13332 numwante 3 uselimit 2output 12Explanation the subset choose second itemsExample 3input value 98876 label 00011 numwante 3 uselimit 1output 16explanation the subset choose fourth item Constraintsn valueslength labelslength1 n 2 1040 valuesi labelsi 2 1041 numwante uselimit n
0array
give string str1 str2 return short string str1 str2 subsequence if multiple valid string return thema string s subsequence string t delete number character t possibly 0 result stre s example 1input str1 abac str2 caboutput cabacexplanation str1 abac subsequence cabac delete cstr2 cab subsequence cabac delete acThe answer provide short string satisfie propertiesexample 2input str1 aaaaaaaa str2 aaaaaaaaoutput aaaaaaaa Constraints1 str1length str2length 1000str1 str2 consist lowercase english letter
2string
there car capacity seat the vehicle drive east ie turn drive westyou give integer capacity array trip tripsi numPassengersi fromi toi indicate ith trip numPassengersi passenger location pick drop fromi toi respectively the location give number kilometer east car initial locationreturn true possible pick drop passenger give trip false Example 1input trip 215337 capacity 4Output falseExample 2input trip 215337 capacity 5output true Constraints1 tripslength 1000tripsilength 31 numpassengersi 1000 fromi toi 10001 capacity 105
0array
this problem interactive problemyou recall array arr mountain array ifarrlength 3There exist 0 arrlength 1 thatarr0 arr1 arri 1 arriarri arri 1 arrarrlength 1given mountain array mountainArr return minimum index mountainarrgetindex target if index exist return 1you access mountain array directly you access array MountainArray interfaceMountainArraygetk returns element array index k 0indexedmountainarraylength return length arraysubmission make 100 call MountainArrayget judge Wrong Answer Also solution attempt circumvent judge result disqualification Example 1input array 1234531 target 3output 2explanation 3 exist array index2 index5 return minimum index 2example 2Input array 012421 target 3output 1explanation 3 exist array return 1 Constraints3 mountain_arrlength 1040 target 1090 mountain_arrgetindex 109
0array
you give array books booksi thicknessi heighti indicate thickness height ith book you give integer shelfwidthwe want place book order bookcase shelf total width shelfwidthwe choose book place shelf sum thickness equal shelfWidth build level shelf bookcase total height bookcase increase maximum height book we repeat process book placenote step process order book place order give sequence booksfor example order list 5 book place second book shelf book second shelf fourth fifth book shelfReturn minimum possible height total bookshelf place shelf manner Example 1input book 11232311111112 shelf_width 4Output 6explanationthe sum height 3 shelf 1 3 2 6notice book number 2 shelfexample 2input book 132432 shelfwidth 6output 4 Constraints1 bookslength 10001 thicknessi shelfwidth 10001 heighti 1000
0array
a boolean expression expression evaluate true false it follow shap evaluate truef evaluate falsesubExpr evaluate logical not inner expression subexprsubexpr1 subexpr2 subexprn evaluate logical and inner expression subexpr1 subexpr2 subExprn n 1subexpr1 subExpr2 subexprn evaluate logical or inner expression subexpr1 subexpr2 subExprn n 1given string expression represent boolean expression return evaluation expressionIt guarantee give expression valid follow give rule example 1input expression fOutput falseexplanation first evaluate f f the expression fThen evaluate f f the expression ffinally return falseexample 2input expression ffftoutput trueexplanation the evaluation false or false or false or true trueexample 3input expression ftoutput trueexplanation first evaluate ft false and true false f the expression fThen evaluate f not false true we return true Constraints1 expressionlength 2 104expressioni follow character t f
2string
give valid ipv4 IP address return defang version IP addressA defang IP address replace period example 1input address 1111output 1111example 2input address 255100500output 255100500 ConstraintsThe give address valid ipv4 address
2string
there n flight label 1 nyou give array flight booking booking bookingsi firsti lasti seatsi represent booking flight firsti lasti inclusive seatsi seat reserve flight rangereturn array answer length n answeri total number seat reserve flight Example 1input booking 121023202525 n 5Output 1055452525explanationflight label 1 2 3 4 5booking 1 reserve 10 10booking 2 reserve 20 20booking 3 reserve 25 25 25 25total seat 10 55 45 25 25hence answer 1055452525example 2input booking 12102215 n 2Output 1025explanationflight label 1 2booking 1 reserve 10 10booking 2 reserve 15total seat 10 25hence answer 1025 Constraints1 n 2 1041 bookingslength 2 104bookingsilength 31 firsti lasti n1 seatsi 104
0array
give root binary tree node tree distinct valueafter delete node value to_delete leave forest disjoint union treesReturn root tree remain forest you return result order Example 1input root 1234567 to_delete 35output 12null467example 2input root 124null3 to_delete 3Output 124 ConstraintsThe number node give tree 1000each node distinct value 1 1000to_deletelength 1000to_delete contain distinct value 1 1000
1graph
a string valid parenthesis stre denote VPS consist character andIt string orIt write AB a concatenate B A b vps orit write a a VPSWe similarly define nesting depth depths VPS S followsdepth 0depthA B maxdepthA depthB a b vpssdepth a 1 depthA A VPSFor example VPSs nesting depth 0 1 2 vps give VPS seq split disjoint subsequence a B A b vps Alength Blength seqlengthnow choose a b maxdeptha depthb minimum possible valuereturn answer array length seqlength encodes choice A b answeri 0 seqi a answeri 1 note multiple answer exist return Example 1input seq output 011110example 2input seq Output 00011011 Constraints1 seqsize 10000
2string
give array arr1 arr2 element arr2 distinct element arr2 arr1sort element arr1 relative order item arr1 arr2 element appear arr2 place end arr1 ascending order Example 1input arr1 231324679219 arr2 214396output 222143396719example 2input arr1 2862284417 arr2 222886output 2228861744 Constraints1 arr1length arr2length 10000 arr1i arr2i 1000all element arr2 distincteach arr2i arr1
0array
give root binary tree return low common ancestor deep leavesRecall thatthe node binary tree leaf childrenthe depth root tree 0 depth node d depth child d 1the low common ancestor set S node node a large depth node S subtree root A Example 1input root 3516208nullnull74output 274explanation we return node value 2 colored yellow diagramThe node colour blue deep leafnode treenote node 6 0 8 leaf node depth 2 depth node 7 4 3example 2input root 1output 1explanation the root deep node tree lca itselfexample 3input root 013null2output 2explanation the deep leaf node tree 2 lca node ConstraintsThe number nod tree range 1 10000 Nodeval 1000The value nod tree unique Note this question 865 httpsleetcodecomproblemssmallestsubtreewithallthedeepestnode
1graph
we give hour list number hour work day give employeea day consider tiring day number hour work strictly great 8a wellperforming interval interval day number tiring day strictly large number nontire daysreturn length longest wellperforming interval example 1input hour 9960669output 3explanation the long wellperforming interval 996example 2input hour 666output 0 Constraints1 hourslength 1040 hoursi 16
0array
in project list require skill req_skill list people the ith person peoplei contain list skill person hasconsider sufficient team set people require skill req_skill person team skill we represent team index personFor example team 0 1 3 represent people skill people0 people1 people3return sufficient team small possible size represent index person you return answer orderIt guarantee answer exist Example 1input req_skill javanodejsreactjs people javanodejsnodejsreactjsOutput 02example 2input req_skill algorithmsmathjavareactjscsharpaw people algorithmsmathjavaalgorithmsmathreactjsjavacsharpawsreactjscsharpcsharpmathawsjavaoutput 12 Constraints1 req_skillslength 161 req_skillsilength 16req_skillsi consist lowercase english lettersall string req_skill unique1 peoplelength 600 peopleilength 161 peopleijlength 16peopleij consists lowercase english lettersall string peoplei uniqueevery skill peoplei skill req_skillsIt guarantee sufficient team exist
0array
give list domino dominoesi b equivalent dominoesj c d c b d d b c domino rotate equal dominoreturn number pair j 0 j dominoeslength dominoesi equivalent dominoesj Example 1input dominoe 12213456output 1example 2input dominoe 1212111222output 3 Constraints1 dominoeslength 4 104dominoesilength 21 dominoesij 9
0array
you give integer n number node direct graph node label 0 n 1 each edge red blue graph selfedge parallel edgesyou give array rededges blueedge whereredEdgesi ai bi indicate direct red edge node ai node bi graph andblueEdgesj uj vj indicate direct blue edge node uj node vj graphReturn array answer length n answerx length short path node 0 node x edge color alternate path 1 path exist Example 1input n 3 rededge 0112 blueedge Output 011example 2input n 3 rededges 01 blueedge 21output 011 Constraints1 n 1000 rededgeslength blueedgeslength 400rededgesilength blueedgesjlength 20 ai bi uj vj n
1graph
give array integer equal length return maximum value ofarr1i arr1j arr2i arr2j jwhere maximum take 0 j arr1length Example 1input arr1 1234 arr2 1456output 13example 2input arr1 125010 arr2 02174output 20 Constraints2 arr1length arr2length 40000106 arr1i arr2i 106
0array
on alphabet board start position 0 0 correspond character board00Here board abcde fghij klmno pqrst uvwxy z show diagram belowWe follow movesU move position row position exist boardD move position row position exist boardL move position leave column position exist boardR move position right column position exist board add character boardrc current position r c answerHere position exist board position letter themreturn sequence move make answer equal target minimum number move you return path Example 1input target leetoutput DDRUURRRDDDExample 2input target codeoutput RRDDRRUULR Constraints1 targetlength 100target consist english lowercase letter
2string
give 2D grid 0s 1s return number element large square subgrid 1s border 0 subgrid do not exist grid Example 1input grid 111101111output 9example 2input grid 1100output 1 Constraints1 gridlength 1001 grid0length 100gridij 0 1
0array
Alice Bob continue game pile stone there number pile arrange row pile positive integer number stone pilesi the objective game end stone Alice Bob turn Alice start Initially M 1on player turn player stone x remain pile 1 x 2 M then set M maxm XThe game continue stone takenassuming Alice Bob play optimally return maximum number stone Alice Example 1input pile 27944output 10explanation if Alice take pile begin Bob take pile Alice take 2 pile Alice 2 4 4 10 pile total if Alice take pile begin Bob pile leave in case Alice 2 7 9 pile total so return 10 large Example 2input pile 12345100output 104 Constraints1 pileslength 1001 pilesi 104
0array
give string text1 text2 return length long common subsequence if common subsequence return 0A subsequence stre new string generate original string character delete change relative order remain charactersFor example ace subsequence abcdeA common subsequence string subsequence common string Example 1input text1 abcde text2 ace output 3 Explanation the long common subsequence ace length 3example 2input text1 abc text2 abcoutput 3explanation the long common subsequence abc length 3example 3input text1 abc text2 defOutput 0explanation there common subsequence result 0 constraints1 text1length text2length 1000text1 text2 consist lowercase english character
2string
give array num integer consist choose element decrease 1an array a zigzag array eitherevery evenindexe element great adjacent element ie A0 A1 A2 A3 A4 or oddindexe element great adjacent element ie A0 A1 A2 A3 A4 return minimum number move transform give array nums zigzag array Example 1input num 123output 2explanation we decrease 2 0 3 1example 2input num 96162output 4 Constraints1 numslength 10001 numsi 1000
0array
two player play turn base game binary tree we give root binary tree number node n tree n odd node distinct value 1 nInitially player name value x 1 x n second player name value y 1 y n y x the player color node value x red second player color node value y blueThen player turn start player in turn player choose node color red player 1 blue player 2 color uncolore neighbor choose node leave child right child parent choose nodeIf player choose node way pass turn if player pass turn game end winner player color nodesyou second player if possible choose y ensure win game return true if possible return false Example 1input root 1234567891011 n 11 x 3output trueexplanation the second player choose node value 2example 2input root 123 n 3 x 1output false ConstraintsThe number nod tree n1 x n 100n odd1 Nodeval nAll value tree unique
1graph
Implement SnapshotArray support follow interfacesnapshotarrayint length initialize arraylike data structure give length Initially element equal 0void setindex val set element give index equal valint snap take snapshot array return snap_id total number time call snap minus 1int getindex snap_id return value give index time take snapshot give snap_id Example 1input SnapshotArraysetsnapsetget3050600Output nullnull0null5explanation SnapshotArray snapshotarr new SnapshotArray3 set length 3snapshotarrset05 Set array0 5snapshotarrsnap take snapshot return snap_id 0snapshotarrset06snapshotarrget00 get value array0 snap_id 0 return 5 constraints1 length 5 1040 index length0 val 1090 snap_id total number time snapat 5 104 call set snap
0array
you give string text you split k substring subtext1 subtext2 subtextk thatsubtexti nonempty stringThe concatenation substring equal text ie subtext1 subtext2 subtextk textsubtexti subtextk 1 valid value ie 1 kReturn large possible value k Example 1input text ghiabcdefhelloadamhelloabcdefghiOutput 7explanation we split stre ghiabcdefhelloadamhelloabcdefghiExample 2input text merchantoutput 1explanation we split stre merchantexample 3input text antaprezatepzapreantaoutput 11explanation we split stre antaprezatepzapreanta Constraints1 textlength 1000text consist lowercase english character
2string
give string date represent gregorian calendar date format YYYYMMDD return day number year Example 1input date 20190109output 9explanation give date 9th day year 2019example 2input date 20190210Output 41 Constraintsdatelength 10date4 date7 dateis digitsdate represent calendar date Jan 1st 1900 Dec 31th 2019
2string
you give string text you swap character textreturn length long substre repeat character example 1input text ababaoutput 3explanation we swap b b then long repeat character substring aaa length 3example 2input text aaabaaaoutput 6explanation Swap b long repeat character substring aaaaaa length 6example 3input text aaaaaoutput 5explanation no need swap long repeat character substre aaaaa length 5 constraints1 textlength 2 104text consist lowercase english character
2string
design datum structure efficiently find majority element give subarraythe majority element subarray element occur threshold time subarrayimplemente MajorityChecker classmajoritycheckerint arr Initializes instance class give array arrint queryint leave int right int threshold return element subarray arrleftright occur threshold times 1 element exist Example 1inputmajoritychecker query query query1 1 2 2 1 1 0 5 4 0 3 3 2 3 2outputnull 1 1 2explanationmajoritychecker majoritychecker new MajorityChecker1 1 2 2 1 1majoritycheckerquery0 5 4 return 1majoritycheckerquery0 3 3 return 1majoritycheckerquery2 3 2 return 2 Constraints1 arrlength 2 1041 arri 2 1040 leave right arrlengththreshold right leave 12 threshold right leave 1At 104 call query
0array
give root binary tree level root 1 level child 2 onreturn small level x sum value nod level x maximal Example 1input root 17078nullnulloutput 2explanation level 1 sum 1Level 2 sum 7 0 7level 3 sum 7 8 1so return level maximum sum level 2example 2input root 989null102509869389388nullnullnull32127Output 2 ConstraintsThe number nod tree range 1 104105 Nodeval 105
1graph
give string s return substre s lexicographical order Example 1input s ababoutput babexplanation the substring ab aba abab b ba bab the lexicographically maximum substre babexample 2input s leetcodeoutput tcode Constraints1 slength 4 105s contain lowercase english letter
2string
you give stre s array query queriesi lefti righti ki we rearrange substre sleftirighti query choose ki replace lowercase English letterif substre possible palindrome string operation result query true otherwise result falseReturn boolean array answer answeri result ith query queriesinote letter count individually replacement example sleftirighti aaa ki 2 replace letter also note query modify initial string s Example Input s abcda query 330120031032041output truefalsefalsetruetrueexplanationqueries0 substre d palidromequeries1 substre bc palidromequeries2 substre abcd palidrome replace 1 characterqueries3 substre abcd change abba palidrome also change baab rearrange bacd replace cd abqueries4 substre abcda change abcba palidromeExample 2Input s lyb query 010221output falsetrue Constraints1 slength querieslength 1050 lefti righti slength0 ki slengths consist lowercase english letter
2string
a bus n stop number 0 n 1 form circle we know distance pair neighboring stop distancei distance stop number 1 nThe bus go direction ie clockwise counterclockwisereturn short distance give start destination stop Example 1input distance 1234 start 0 destination 1output 1explanation Distance 0 1 1 9 minimum 1 Example 2input distance 1234 start 0 destination 2output 3explanation Distance 0 2 3 7 minimum 3 Example 3input distance 1234 start 0 destination 3output 4explanation Distance 0 3 6 4 minimum 4 Constraints1 n 104distancelength n0 start destination n0 distancei 104
0array
give array integer return maximum sum nonempty subarray contiguous element element deletion in word want choose subarray optionally delete element element leave sum remain element maximum possiblenote subarray need nonempty delete element Example 1input arr 1203output 4explanation because choose 1 2 0 3 drop 2 subarray 1 0 3 maximum valueExample 2input arr 1223output 3explanation we choose 3 maximum sumexample 3input arr 1111output 1explanation the final subarray need nonempty you can not choose 1 delete 1 subarray sum equal 0 Constraints1 arrlength 105104 arri 104
0array
give integer array arr1 arr2 return minimum number operation possibly zero need arr1 strictly increasingIn operation choose index 0 arr1length 0 j arr2length assignment arr1i arr2jif way arr1 strictly increase return 1 Example 1input arr1 15367 arr2 1324output 1explanation replace 5 2 arr1 1 2 3 6 7example 2input arr1 15367 arr2 431output 2explanation replace 5 3 replace 3 4 arr1 1 3 4 6 7example 3input arr1 15367 arr2 1633output 1explanation you can not arr1 strictly increase Constraints1 arr1length arr2length 20000 arr1i arr2i 109
0array
give string text want use character text form instance word balloon possibleyou use character text return maximum number instance form example 1input text nlaebolkooutput 1example 2input text loonbalxballpoonOutput 2example 3input text leetcodeoutput 0 Constraints1 textlength 104text consist low case english letter
2string
you give string s consist low case english letter bracketsreverse string pair matching parenthesis start innermost oneyour result contain bracket Example 1input s abcdoutput dcbaExample 2input s uloveioutput iloveuexplanation the substre love reverse string reversedExample 3input s edetoceloutput leetcodeexplanation first reverse substre oc etco finally stre Constraints1 slength 2000s contain low case english character parenthesesIt guarantee parenthesis balance
2string
give integer array arr integer k modify array repeat k timesFor example arr 1 2 k 3 modify array 1 2 1 2 1 2return maximum subarray sum modify array note length subarray 0 sum case 0as answer large return answer modulo 109 7 Example 1input arr 12 k 3output 9Example 2input arr 121 k 5output 2example 3Input arr 12 k 7Output 0 Constraints1 arrlength 1051 k 105104 arri 104
0array
there n server number 0 n 1 connect undirected servertoserver connection form network connectionsi ai bi represent connection server ai bi any server reach server directly indirectly networka critical connection connection remove server unable reach serverreturn critical connection network order Example 1input n 4 connection 01122013output 13explanation 31 acceptedExample 2Input n 2 connection 01output 01 Constraints2 n 105n 1 connectionslength 1050 ai bi n 1ai biThere repeat connection
1graph
give array distinct integer arr find pair element minimum absolute difference elementsreturn list pair ascend orderwith respect pair pair b followsa b arra bb equal minimum absolute difference element arr Example 1input arr 4213output 122334explanation the minimum absolute difference 1 list pair difference equal 1 ascend orderexample 2input arr 1361015output 13example 3input arr 3810231941427output 141019232327 Constraints2 arrlength 105106 arri 106
0array
there n item belong zero m group groupi group ith item belong equal 1 ith item belong group the item group zero index a group item belong itReturn sorted list item thatthe item belong group sort listThere relation item beforeItemsi list contain item come ith item sort array leave ith itemreturn solution solution return list solution Example 1input n 8 m 2 group 11100101 beforeitem 65636output 63415207example 2input n 8 m 2 group 11100101 beforeitem 65634output Explanation this example 1 4 need 6 sorted list Constraints1 m n 3 104grouplength beforeitemslength n1 groupi m 10 beforeitemsilength n 10 beforeItemsij n 1i beforeItemsijbeforeItemsi contain duplicate element
1graph
give array integer arr return true number occurrence value array unique false Example 1input arr 122113output trueexplanation the value 1 3 occurrence 2 2 3 1 no value number occurrencesExample 2Input arr 12Output falseExample 3input arr 30131113100output true Constraints1 arrlength 10001000 arri 1000
0array
you give string s t length integer maxCostYou want change s t change ith character s ith character t cost si ti ie absolute difference ascii value charactersreturn maximum length substring s change correspond substre t cost equal maxcost if substre s change correspond substre t return 0 example 1input s abcd t bcdf maxcost 3output 3explanation abc s change bcdthat cost 3 maximum length 3example 2Input s abcd t cdef maxCost 3output 1explanation each character s cost 2 change character t maximum length 1example 3input s abcd t acde maxCost 0output 1explanation you change maximum length 1 Constraints1 slength 105tlength slength0 maxcost 106s t consist lowercase english letter
2string
you give string s integer k k duplicate removal consist choose k adjacent equal letter s remove cause left right delete substre concatenate togetherWe repeatedly k duplicate removal s long canreturn final string duplicate removal it guarantee answer unique Example 1input s abcd k 2output abcdexplanation there s deleteexample 2input s deeedbbcccbdaa k 3output aaexplanation first delete eee ccc ddbbbdaathen delete bbb dddaafinally delete ddd aaexample 3input s pbbcggttciiippooaais k 2Output ps Constraints1 slength 1052 k 104s contain lowercase english letter
2string
we n chip position ith chip positioniWe need chip position in step change position ith chip positioni topositioni 2 positioni 2 cost 0positioni 1 positioni 1 cost 1return minimum cost need chip position Example 1input position 123output 1explanation first step move chip position 3 position 1 cost 0second step move chip position 2 position 1 cost 1total cost 1example 2input position 22233output 2explanation we chip position 3 position 2 each cost 1 the total cost 2example 3input position 11000000000output 1 Constraints1 positionlength 1001 positioni 109
0array
give integer array arr integer difference return length long subsequence arr arithmetic sequence difference adjacent element subsequence equal differencea subsequence sequence derive arr delete element change order remain element Example 1input arr 1234 difference 1output 4explanation the long arithmetic subsequence 1234example 2input arr 1357 difference 1output 1explanation the long arithmetic subsequence single elementExample 3input arr 157853421 difference 2output 4explanation the long arithmetic subsequence 7531 Constraints1 arrlength 105104 arri difference 104
0array
in gold grid size m x n cell integer represent gold cell 0 emptyReturn maximum gold collect conditionsevery time locate cell collect gold cellFrom position walk step leave right downyou can not visit cell oncenever visit cell 0 goldyou start stop collect gold position grid gold Example 1input grid 060587090output 24explanation060 587 090path maximum gold 9 8 7example 2input grid 1072063450309020output 28explanation107 206 345 030 9020path maximum gold 1 2 3 4 5 6 7 Constraintsm gridlengthn gridilength1 m n 150 gridij 100there 25 cell contain gold
0array
balanced string equal quantity l R charactersgiven balanced string s split number substring thateach substre balancedreturn maximum number balance string obtain Example 1input s RLRRLLRLRLOutput 4explanation s split RL RRLL RL RL substring contain number L RExample 2input s rlrrrllrlloutput 2explanation s split RL RRRLLRLL substring contain number L RNote s split RL rr RL LR LL 2nd 5th substring balancedExample 3input s LLLLRRRROutput 1explanation s split LLLLRRRR constraints2 slength 1000si L Rs balanced string
2string
on 8x8 chessboard multiple Black Queens White KingGiven array integer coordinate queen represent position Black Queens pair coordinate king represent position White King return coordinate queen order attack King Example 1input queen 011040043324 king 00output 011033explanation the queen 01 attack king cause they re row the queen 10 attack king cause they re column the queen 33 attack king cause they re diagnal the queen 04 can not attack king cause block queen 01 the queen 40 can not attack king cause block queen 10 the queen 24 can not attack king cause rowcolumndiagnal kingExample 2input queen 00112234354445 king 33output 223444example 3input queen 56772107165137034012635004221164540026455214752305421027014661064317 king 34output 23141637435445 Constraints1 queenslength 63queensilength 20 queensij 8kinglength 20 king0 king1 8At piece allow cell
0array
a die simulator generate random number 1 6 roll you introduce constraint generator roll number rollmaxi 1indexed consecutive timesgiven array integer rollmax integer n return number distinct sequence obtain exact n roll since answer large return modulo 109 7two sequence consider different element differ Example 1input n 2 rollmax 112223output 34explanation there 2 roll die constraint die 6 6 36 possible combination in case look rollMax array number 1 2 appear consecutively sequence 11 22 occur final answer 362 34example 2input n 2 rollMax 111111output 30example 3input n 3 rollmax 111223output 181 constraints1 n 5000rollmaxlength 61 rollMaxi 15
0array
give array num positive integer return long possible length array prefix num possible remove exactly element prefix number appear number occurrencesif remove element remain element consider appear number number ocurrence 0 example 1input num 22115335output 7explanation for subarray 2211533 length 7 remove nums4 5 221133 number appear exactly twiceexample 2input num 1112223334445output 13 constraints2 numslength 1051 numsi 105
0array
you give array coordinate coordinatesi x y x y represent coordinate point check point straight line xy plane Example 1input coordinate 122334455667output trueExample 2input coordinate 112234455677output false constraints2 coordinateslength 1000coordinatesilength 2104 coordinatesi0 coordinatesi1 104coordinates contain duplicate point
0array
you give stre s length n contain kind character Q W e RA string say balanced character appear n 4 time n length stringreturn minimum length substring replace string length s balanced if s balanced return 0 example 1input s qweroutput 0explanation s balancedExample 2input s QQWEOutput 1explanation we need replace Q r rqwe qrwe balancedexample 3input s qqqwoutput 2explanation we replace QQ ER Constraintsn slength4 n 105n multiple 4s contain Q W e r
2string
we n job job schedule startTimei endTimei obtain profit profitiyoure give starttime endtime profit array return maximum profit job subset overlap time rangeIf choose job end time X able start job start time X Example 1input starttime 1233 endtime 3456 profit 50104070output 120explanation the subset choose fourth job Time range 1336 profit 120 50 70example 2input starttime 12346 endtime 351069 profit 20201007060output 150explanation the subset choose fourth fifth job Profit obtain 150 20 70 60example 3input starttime 111 endtime 234 profit 564output 6 constraints1 starttimelength endtimelength profitlength 5 1041 startTimei endTimei 1091 profiti 104
0array
you give string s1 s2 equal length consist letter x y your task string equal you swap character belong different string means swap s1i s2jreturn minimum number swap require s1 s2 equal return 1 impossible Example 1input s1 xx s2 yyoutput 1explanation swap s10 s21 s1 yx s2 yxexample 2input s1 xy s2 yxoutput 2explanation swap s10 s20 s1 yy s2 xxSwap s10 s21 s1 xy s2 xyNote swap s10 s11 s1 equal yx cause swap char different stringsExample 3input s1 xx s2 xyOutput 1 Constraints1 s1length s2length 1000s1 s2 contain x y
2string
give array integer num integer k a continuous subarray call nice k odd number itreturn number nice subarray Example 1input num 11211 k 3output 2explanation the subarray 3 odd number 1121 1211example 2input num 246 k 1output 0explanation there odd number arrayexample 3input num 2221221222 k 2Output 16 Constraints1 numslength 500001 numsi 1051 k numslength
0array
give string s lowercase English charactersYour task remove minimum number parenthese position result parenthesis stre valid return valid stringformally parenthese stre valid ifit string contain lowercase character orit write AB a concatenate B A b valid string orIt write a a valid string Example 1input s leetcodeoutput leetcodeexplanation leetcode leetcode acceptedExample 2Input s abcdOutput abcdexample 3input s Output Explanation an string valid Constraints1 slength 105si lowercase english letter
2string
give array num positive integer your task select subset num multiply element integer add number the array say good obtain sum 1 array possible subset multiplicandreturn true array good return False Example 1input num 125723output trueexplanation Pick number 5 753 72 1example 2input num 29610output trueExplanation Pick number 29 6 10291 63 101 1example 3input num 36output false Constraints1 numslength 1051 numsi 109
0array
there m x n matrix initialize 0s there 2D array indice indicesi ri ci represent 0indexed location perform increment operation matrixfor location indicesi followingincrement cell row riincrement cell column ciGiven m n index return number oddvalue cell matrix apply increment location indice Example 1input m 2 n 3 index 0111output 6explanation initial matrix 000000after apply increment 121010the final matrix 131131 contain 6 odd numbersExample 2Input m 2 n 2 index 1100output 0explanation final matrix 2222 there odd number final matrix Constraints1 m n 501 indiceslength 1000 ri m0 ci n Follow could solve on m indiceslength time on m extra space
0array
give follow detail matrix n column 2 row the matrix binary matrix mean element matrix 0 1the sum element 0thupper row give upperThe sum element 1stlower row give lowerThe sum element ith column0indexe colsumi colsum give integer array length nYour task reconstruct matrix upper low colsumReturn 2D integer arrayif valid solution acceptedif valid solution exist return 2d array Example 1input upper 2 low 1 colsum 111output 110001explanation 101010 011100 correct answersexample 2input upper 2 low 3 colsum 2211output Example 3input upper 5 low 5 colsum 2120101201output 11101001001010001101 Constraints1 colsumlength 1050 upper low colsumlength0 colsumi 2
0array
give 2D grid size m x n integer k you need shift grid k timesIn shift operationElement gridij move gridij 1element gridin 1 move gridi 10element gridm 1n 1 move grid00return 2D grid apply shift operation k times Example 1input grid 123456789 k 1Output 912345678example 2input grid 3819197254611101202113 k 4Output 1202113381919725461110example 3input grid 123456789 k 9output 123456789 Constraintsm gridlengthn gridilength1 m 501 n 501000 gridij 10000 k 100
0array
give binary tree follow rulesrootval 0if treeNodeval x treeNodeleft null treeNodeleftval 2 x 1if treeNodeval x treeNoderight null treenoderightval 2 x 2now binary tree contaminate mean treeNodeval change 1implement findelement classfindelementstreenode root Initializes object contaminate binary tree recover itbool findint target return true target value exist recover binary tree Example 1inputfindelementsfindfind1null112outputnullfalsetrueexplanationfindelements findelement new findelements1null1 findelementsfind1 return false findelementsfind2 return True Example 2inputfindelementsfindfindfind11111135outputnulltruetruefalseexplanationfindelements findelement new FindElements11111findElementsfind1 return TruefindElementsfind3 return TruefindElementsfind5 return FalseExample 3inputfindelementsfindfindfindfind1null11null12345outputnulltruefalsefalsetrueexplanationfindelements findelement new findelements1null11null1findelementsfind2 return TruefindElementsfind3 return falsefindelementsfind4 return FalsefindElementsfind5 return true ConstraintsTreeNodeval 1the height binary tree equal 20the total number nod 1 104total call find 1 1040 target 106
1graph
give integer array num return maximum possible sum element array divisible Example 1input num 36518output 18explanation Pick number 3 6 1 8 sum 18 maximum sum divisible 3example 2input num 4Output 0explanation since 4 divisible 3 pick numberexample 3input num 12344output 12explanation Pick number 1 3 4 4 sum 12 maximum sum divisible 3 Constraints1 numslength 4 1041 numsi 104
0array
on 2D plane n point integer coordinate pointsi xi yi return minimum time second visit point order give pointsyou accord rulesIn 1 second eithermove vertically unitmove horizontally unit ormove diagonally sqrt2 unit word unit vertically unit horizontally 1 secondyou visit point order appear arrayyou allow pass point appear later order count visit Example 1input point 113410output 7explanation one optimal path 11 22 33 34 23 12 01 10 Time 11 34 3 second Time 34 10 4 secondstotal time 7 secondsexample 2input point 3222output 5 Constraintspointslength n1 n 100pointsilength 21000 pointsi0 pointsi1 1000
0array
Tictactoe play player A B 3 x 3 grid the rule TicTacToe areplayers turn place character square the player a place x character second player B place o charactersx o character place square fill onesThe game end nonempty character filling row column diagonalThe game end square nonemptyNo move play game overGiven 2D integer array move movesi rowi coli indicate ith play gridrowicoli return winner game exist a b in case game end draw return Draw if movement play return PendingYou assume move valid ie follow rule tictactoe grid initially a play Example 1input move 0020112122output AExplanation a win play firstexample 2input move 001101021020output BExplanation B winsexample 3input move 001120101221010222output DrawExplanation the game end draw move Constraints1 moveslength 9movesilength 20 rowi coli 2there repeat element movesmove follow rule tic tac toe
0array
give m n matrix one zero return square submatrice one example 1input matrix 0111 1111 0111output 15explanation there 10 square 1there 4 square 2There 1 square 3total number square 10 4 1 15example 2input matrix 101 110 110output 7explanation there 6 square 1 there 1 square 2 total number square 6 1 7 constraints1 arrlength 3001 arr0length 3000 arrij 1
0array
you give string s contain lowercase letter integer k you need first change character s lowercase English lettersThen divide s k nonempty disjoint substring substre palindromereturn minimal number character need change divide string Example 1input s abc k 2output 1explanation you split string ab c change 1 character ab palindromeExample 2Input s aabbc k 3output 0explanation you split string aa bb c palindromeExample 3Input s leetcode k 8Output 0 Constraints1 k slength 100s contain lowercase english letter
2string
there n people split unknown number group each person label unique ID 0 n 1you give integer array groupsize groupSizesi size group person for example groupsizes1 3 person 1 group size 3return list group person group size groupsizesieach person appear exactly group person group if multiple answer return it guarantee valid solution give input Example 1input groupsize 3333313output 5012346explanation the group 5 the size 1 groupsizes5 1the second group 012 the size 3 groupsizes0 groupsizes1 groupsizes2 3the group 346 the size 3 groupsizes3 groupsizes4 groupsizes6 3other possible solution 2165043 5062431example 2input groupsize 213332output 105234 ConstraintsgroupSizeslength n1 n 5001 groupSizesi n
0array