question
stringlengths
58
4.29k
label
class label
3 classes
to learn soon possible late news favourite fundamentally new operating system BolgenOS community Nizhni Tagil decide develop scheme accord scheme community member learn news call member turn call member ie person index get person index fi learn news with time BolgenOS community member understand scheme do not work case member do not learn news now want supplement scheme add scheme instruction type xiyi mean person xi person yi what minimum instruction need add end learn news matter learn
2string
Bob get job system administrator x corporation his task connect n server help m twoway direct connection possible transmit datum server server connection each direct connection link different server pair server direct connection Y corporation business rival X corporation Bob offer could not refuse Bob ask connect server way server index v fail transmission datum server impossible ie system stop connected Help Bob connect server
2string
Jabber ID national Berland service Babber form usernamehostnameresource username sequence Latin letter lowercase uppercase digit underscore character _ length username 1 16 inclusive hostname sequence word separate period character word contain character allow username length word 1 16 inclusive the length hostname 1 32 inclusive resource sequence Latin letter lowercase uppercase digit underscore character _ length resource 1 16 inclusive the content square brackets optional present absentThere sample correct Jabber IDs mikecodeforcescom 007encodeforcescomcontestyour task write program check give string correct Jabber ID
1graph
once Bob take paper stripe n square height stripe 1 square in square write integer number possibly negative he interested way exist cut stripe piece sum number piece equal sum number piece piece contain positive integer square would help Bob solve problem
1graph
Nick like string like rotate sort rearrange character string once write random string character b c piece paper begin perform follow operation adjacent character replace second character adjacent character replace character second to understand action well let look stre abc all follow string obtain perform describe operation abc bbc abb acc Lets denote frequency character character b c number occurrence character string for example stre abc 1 b 1 c 1 string bbc 0 b 2 c 1 while perform describe operation Nick get balanced string Lets string balanced frequency character differ 1 that 1ab1 1ac1 и 1bc1 would help Nick find number different balanced string obtain perform operation describe multiple time give stre s this number calculate modulo 51123987
1graph
Nicks company employ n people now Nick need build tree hierarchy supervisorsurbodinate relation company employee exactly supervisor there m application write follow form employee ai ready supervisor employee bi extra cost ci the qualification qj employee know application follow true qaiqbi would help Nick calculate minimum cost hierarchy find impossible build
1graph
several month later Alex finally get brother Bobs creation post and turn Alex want boast brother he think come conclusion ready creation decide write program rectangle detection accord plan program detect give segment form rectangle positive area side parallel coordinate axis as Alex badly school can not write program ask help
1graph
there secret base Potatoland potato mash accord special recipe the neighbour Porridgia decide seize recipe sell Pilauland for mission prepare special agent Pearlo year when finally Pearlo learn secret espionage penetrate Potatoland territory reach secret basenow stand entrance inside need pass combination lock Minute ago worker enter password terminal open door the terminal square digital keyboard 33 digit 1 9Pearlo know password consist distinct digit probably symmetric respect central button terminal he heat sensor allow detect digit worker press now want check password enter worker symmetric respect central button terminal this fact help Pearlo reduce number different possible password combination
0array
this problem differ online contestthe sequence a1a2an call increase aiai1 inThe sequence s1s2sk call subsequence sequence a1a2an exist set index 1i1i2ikn aijsj in word sequence s derive sequence crossing elementsyou give sequence integer number you find long common increase subsequence ie increase sequence maximum length subsequence sequence
2string
one beautiful July morning terrible thing happen Mainframe mean virus Megabyte get access memory mean sister Hexadecimal he load huge n different natural number 1 n obtain total control energybut plan fail the reason simple Hexadecimal do not perceive information apart number write binary format this mean number decimal representation contain character apart 0 1 store memory Now Megabyte want know number load successfully
1graph
one martian boy call Zorg want present string bead friend Earth Masha he know Masha like colour blue red right shop come variety adornment bead colour all string bead small fastener unfasten notice string bead shop length because peculiarity martian eyesight Zorg see blueandre string bead red bead instead blue one blue instead red regard string bead identical in word Zorg regard identical string bead derive string turnover derive mutual replacement colours andor string turnoverit know Martians orderly Martian see object try good order Zorg think red bead small blue Lets 0 red bead 1 blue from string Martian put early string red bead ith position provide second string blue bead ith position bead i1 identicalAt Zorg unfasten string bead put small heap heap string identical opinion then sort heap choose minimum string heap opinion he give unnecassary string shop assistant say do not need then Zorg sort remain string bead buy stre index k all manupulation Zorg lot time that s ask help find string bead Masha
1graph
the world got obsess robotsand pace progress great Berlands programmer Draude decide build robot he work hard robot he teach walk short path point record movement like Draudes program bug robot do not walk short path Fortunately robot record movement correctly now Draude want find robot function wrong Heh Draude remember map field test robot easily robot walk right direction but field map lose find that s ask find exist map path record robot shortestthe map infinite checker field square contain obstruction it know robot try run obstruction by record robot movement find exist map possible choose robot start square start square robot move square movement coincide record one robot do not run move square path start square end shortestIn movement robot square provide obstrution square common side square robot currently
2string
Peter like travel train he like train fall asleep once summer Peter go train city a city b usual sleeping then wake start look window notice railway station flag particular colourthe boy start memorize order flag colour see but soon fall asleep unfortunately do not sleep long wake go memorize colour then fall asleep time sleep till end journeyAt station tell parent write sequence colour see sleep respectivelypeter parent know son like fantasize they list flag colours station train pass sequentially way a b ask find Peter sequence way A b B a remember Peter period wakefulnesspeter parent lowercase latin letter colour the letter stand colour different letter different colour
1graph
there little time leave release national operating system berlos some component finish memory manager accord developer plan release memory manager simple rectilinear it support operation alloc n allocate n byte memory return allocate block identifier x erase x erase block identifier x defragment defragment free memory bring block close beginning memory possible preserve respective order the memory model case simple it sequence m byte number convenience mthThe operation alloc n take parameter size memory block allocate while process operation free block n successive byte allocate memory if block block close beginning memory ie byte prefer all byte mark free memory manager return 32bit integer numerical token identifi block if impossible allocate free block size function return nullthe second operation erase x take parameter identifi block this operation free system memory mark byte block free use in case identifier point previously allocate block erase function return illegal_erase_argumentthe operation defragment argument simply bring occupy memory section close begin memory change respective orderin current implementation use successive integer start 1 identifier each successful alloc operation procession return follow number unsuccessful alloc operation affect numerationyou write implementation memory manager you output return value alloc command you output illegal_erase_argument fail erase command
1graph
President Berland vast officeroom apart work subordinate each subordinate President desk unique colour each desk rectangular side parallel office wall one day President decide establish assembly deputy member unfortunately remember exact deputy remember desk deputy adjacent desk desk president deputy common positive lengththe officeroom plan view matrix n row m column each cell matrix contain desk an uppercase latin letter stand desk colour the period character stand cell
2string
everyone know long ago territory presentday Berland live bindian tribe their capital surround n hill form circle on hill watchman watch neighbourhood day nightIn case danger watchman fire hill one watchman signal watchman circle arc connect hills hill high as hill different circle arc connect signal see mention condition satisfy arc for example neighbouring watchman true signal see otheran important characteristic watch system pair watchman able signal you find give height hill
1graph
polycarp work new project call Polychat follow modern tendency it decide project contain chat to achieve goal Polycarp spend hour laptop implement chat server process type command include person chat Add command Remove person chat remove command send message person people currently chat include send message Send command now Polycarp wants find outgoing traffic server produce processing particular set commandspolycarp know chat server send traffic Add Remove command when Send command process server send l byte participant chat l length messageas Polycarp time ask help solve problem
2string
a new email service Berlandesk going open Berland near future the site administration want launch project soon possible that s ask help you re suggest implement prototype site registration system the system work follow principle each time new user want register send system request if exist system database insert database user get response ok confirm successful registration if exist system database system make new user send user prompt inserts prompt database the new form follow rule number start 1 append name1 name2 number find namei exist database
1graph
one hot summer day Pete friend Billy decide buy watermelon they choose big ripe opinion after watermelon weigh scale show w kilos they rush home die thirst decide divide berry face hard problemPete Billy great fan number that s want divide watermelon way part weigh number kilos time obligatory part equal the boy extremely tired want start meal soon possible that s help find divide watermelon way want for sure positive weight
1graph
the winner card game popular Berland Berlogging determine accord follow rule if end game player maximum number point winner the situation difficult number player during round player gain lose particular number point in course game number point register line score player score number point gain round integer number if score negative mean player lose round so player maximum number point equal m end game win score m point Initially player 0 point its guarantee end game player positive number point
1graph
Theatre Square capital city Berland rectangular shape size nm meter on occasion citys anniversary decision take pave Square square granite flagstone each flagstone size aawhat number flagstone need pave Square its allow cover surface large Theatre Square Square cover its allow break flagstone the side flagstone parallel side Square
2string
give integer array num sort nondecrease order remove duplicate inplace unique element appear the relative order element keep samesince impossible change length array language instead result place array num more formally k element remove duplicate k element num hold final result it matter leave k elementsReturn k place final result k slot numsDo allocate extra space array you modify input array inplace O1 extra memoryCustom JudgeThe judge test solution follow codeint num Input arrayint expectednum the expected answer correct lengthint k removeduplicatesnum Calls implementationassert k expectednumslengthfor int 0 k assert numsi expectednumsiif assertion pass solution accept Example 1input num 112output 2 num 12_explanation your function return k 2 element num 1 2 respectivelyit matter leave return k underscoresExample 2input num 0011122334output 5 num 01234_____explanation your function return k 5 element num 0 1 2 3 4 respectivelyit matter leave return k underscore Constraints1 numslength 3 104100 numsi 100nums sort nondecrease order
0array
give array integer num integer target return index number add targetyou assume input exactly solution use element twiceyou return answer order Example 1input num 271115 target 9output 01Explanation because nums0 nums1 9 return 0 1example 2input num 324 target 6output 12example 3input num 33 target 6output 01 constraints2 numslength 104109 numsi 109109 target 109only valid answer exist Followup can come algorithm on2 time complexity
0array
give string s find length long substre repeat character example 1input s abcabcbboutput 3explanation the answer abc length 3Example 2input s bbbbboutput 1explanation the answer b length 1example 3input s pwwkewoutput 3explanation the answer wke length 3notice answer substre pwke subsequence substre constraints0 slength 5 104s consist english letter digit symbol space
2string
give sort array nums1 nums2 size m n respectively return median sort arraysthe overall run time complexity Olog mn Example 1input nums1 13 nums2 2output 200000explanation merge array 123 median 2example 2input nums1 12 nums2 34output 250000explanation merge array 1234 median 2 3 2 25 constraintsnums1length mnums2length n0 m 10000 n 10001 m n 2000106 nums1i nums2i 106
0array
give string s return long palindromic substre s example 1input s babadoutput babexplanation aba valid answerExample 2input s cbbdoutput bb Constraints1 slength 1000 consist digit english letter
2string
the string paypalishiring write zigzag pattern give number row like want display pattern fix font well legibilityP a h NA P L S I I gy I RAnd read line line PAHNAPLSIIGYIRWrite code string conversion give number rowsstre convertstre s int numrow Example 1input s paypalishiring numrow 3output pahnaplsiigyirexample 2input s paypalishiring numrow 4output pinalsigyahrpiexplanationp I NA L S I gy a h rp IExample 3input s a numrow 1output a Constraints1 slength 1000 consist english letter lowercase uppercase 1 numrow 1000
2string
implement myatoistring s function convert string 32bit sign integer similar ccs atoi functionThe algorithm myatoistre s followsread ignore lead whitespacecheck character end string read character this determine final result negative positive respectively Assume result positive presentread character nondigit character end input reach the rest string ignoredConvert digit integer ie 123 123 0032 32 if digit read integer 0 change sign necessary step 2If integer 32bit sign integer range 231 231 1 clamp integer remain range specifically integer 231 clamp 231 integer great 231 1 clamp 231 1return integer final resultnoteonly space character consider whitespace characterDo ignore character lead whitespace rest string digit Example 1input s 42output 42explanation the underlined character read caret current reader positionstep 1 42 character read lead whitespace step 2 42 character read step 3 42 42 read the parse integer 42since 42 range 231 231 1 final result 42example 2input s 42output 42explanationstep 1 42 lead whitespace read ignore step 2 42 read result negative step 3 42 42 read the parse integer 42since 42 range 231 231 1 final result 42example 3input s 4193 wordsoutput 4193explanationstep 1 4193 word character read lead whitespace Step 2 4193 word character read step 3 4193 word 4193 read read stop character nondigit the parsed integer 4193since 4193 range 231 231 1 final result 4193 constraints0 slength 200s consist english letter lowercase uppercase digit 09
2string
give input string s pattern p implement regular expression matching support match single character match zero precede elementThe match cover entire input string partial Example 1input s aa p aOutput falseexplanation match entire string aaexample 2input s aa p aoutput trueexplanation mean zero precede element therefore repeat aaexample 3input s ab p output trueexplanation mean zero character Constraints1 slength 201 plength 30 contain lowercase english lettersp contain lowercase english letter it guarantee appearance character previous valid character match
2string
you give integer array height length n there n vertical line draw endpoint ith line 0 heightifind line xaxis form container container contain waterreturn maximum water container storenotice slant container Example 1input height 186254837output 49explanation the vertical line represent array 186254837 in case max area water blue section container contain 49example 2input height 11output 1 Constraintsn heightlength2 n 1050 heighti 104
0array
roman numeral represent seven different symbol I v X l C D MSymbol ValueI 1V 5x 10L 50c 100d 500 M 1000for example 2 write II roman numeral one add 12 write XII simply X II the number 27 write XXVII XX V IIRoman numeral usually write large small left right however numeral iiii instead number write IV because subtract make the principle apply number write IX there instance subtraction usedi place V 5 x 10 4 9 x place l 50 C 100 40 90 c place D 500 M 1000 400 900given integer convert roman numeral Example 1input num 3output IIIExplanation 3 represent 3 onesexample 2input num 58output LVIIIExplanation l 50 V 5 iii 3example 3input num 1994output MCMXCIVExplanation M 1000 CM 900 XC 90 IV 4 Constraints1 num 3999
2string
roman numeral represent seven different symbol I v X l C D MSymbol ValueI 1V 5x 10L 50c 100d 500 M 1000for example 2 write II roman numeral one add 12 write XII simply X II the number 27 write XXVII XX V IIRoman numeral usually write large small left right however numeral iiii instead number write IV because subtract make the principle apply number write IX there instance subtraction usedi place V 5 x 10 4 9 x place l 50 C 100 40 90 c place D 500 M 1000 400 900given roman numeral convert integer Example 1input s iiioutput 3explanation III 3example 2input s LVIIIOutput 58explanation L 50 V 5 iii 3example 3input s MCMXCIVOutput 1994explanation M 1000 CM 900 XC 90 IV 4 Constraints1 slength 15s contain character I v X l C D MIt guarantee s valid roman numeral range 1 3999
2string
write function find long common prefix string array stringsIf common prefix return string Example 1input strs flowerflowflightoutput flexample 2input strs dogracecarcaroutput Explanation there common prefix input string Constraints1 strslength 2000 strsilength 200strsi consist lowercase english letter
2string
give integer array num return triplet numsi numsj numsk j k j k numsi numsj numsk 0Notice solution set contain duplicate triplet Example 1input num 101214output 112101explanation nums0 nums1 nums2 1 0 1 0nums1 nums2 nums4 0 1 1 0nums0 nums3 nums4 1 2 1 0the distinct triplet 101 112notice order output order triplet matterexample 2input num 011output Explanation the possible triplet sum 0example 3input num 000output 000explanation the possible triplet sum 0 constraints3 numslength 3000105 numsi 105
0array
give integer array num length n integer target find integer num sum close targetreturn sum integersyou assume input exactly solution example 1input num 1214 target 1output 2explanation the sum close target 2 1 2 1 2example 2input num 000 target 1output 0explanation the sum close target 0 0 0 0 0 constraints3 numslength 5001000 numsi 1000104 target 104
0array
give string contain digits 29 inclusive return possible letter combination number represent Return answer orderA mapping digit letter like telephone button give Note 1 map letter Example 1input digit 23output adaeafbdbebfcdcecfExample 2input digit Output Example 3input digit 2output abc Constraints0 digitslength 4digitsi digit range 2 9
2string
give array num n integer return array unique quadruplet numsa numsb numsc numsd that0 b c d na b c d distinctnumsa numsb numsc numsd targetyou return answer order Example 1input nums 101022 target 0output 211220021001example 2input num 22222 target 8Output 2222 Constraints1 numslength 200109 numsi 109109 target 109
0array
give string s contain character determine input string validan input string valid ifopen bracket close type bracketsopen bracket close correct orderevery close bracket corresponding open bracket type Example 1input s output trueexample 2input s output trueExample 3input s output false constraints1 slength 104s consist parenthese
2string
give n pair parenthesis write function generate combination wellforme parenthese Example 1input n 3Output Example 2input n 1output Constraints1 n 8
2string
give integer array num sort nondecrease order remove duplicate inplace unique element appear the relative order element keep samesince impossible change length array language instead result place array num more formally k element remove duplicate k element num hold final result it matter leave k elementsReturn k place final result k slot numsDo allocate extra space array you modify input array inplace O1 extra memoryCustom JudgeThe judge test solution follow codeint num Input arrayint expectednum the expected answer correct lengthint k removeduplicatesnum Calls implementationassert k expectednumslengthfor int 0 k assert numsi expectednumsiif assertion pass solution accept Example 1input num 112output 2 num 12_explanation your function return k 2 element num 1 2 respectivelyit matter leave return k underscoresExample 2input num 0011122334output 5 num 01234_____explanation your function return k 5 element num 0 1 2 3 4 respectivelyit matter leave return k underscore Constraints1 numslength 3 104100 numsi 100nums sort nondecrease order
0array
give integer array nums integer val remove occurrence val num inplace the relative order element changedsince impossible change length array language instead result place array num more formally k element remove duplicate k element num hold final result it matter leave k elementsReturn k place final result k slot numsDo allocate extra space array you modify input array inplace O1 extra memoryCustom JudgeThe judge test solution follow codeint num Input arrayint val value removeint expectednum the expected answer correct length it sort value equal valint k removeelementnum val Calls implementationassert k expectednumslengthsortnum 0 k Sort k element numsfor int 0 actuallength assert numsi expectednumsiif assertion pass solution accept Example 1input num 3223 val 3Output 2 num 22__explanation your function return k 2 element num 2It matter leave return k underscoresExample 2input num 01223042 val 2output 5 num 01403___Explanation your function return k 5 element num contain 0 0 1 3 4note element return orderit matter leave return k underscore Constraints0 numslength 1000 numsi 500 val 100
0array
give string needle haystack return index occurrence needle haystack 1 needle haystack Example 1input haystack sadbutsad needle sadOutput 0explanation sad occur index 0 6the occurrence index 0 return 0example 2Input haystack leetcode needle leetoOutput 1explanation leeto occur leetcode return 1 Constraints1 haystacklength needlelength 104haystack needle consist lowercase english character
2string
you give stre s array string word all string word lengthA concatenate substre s substring contain string permutation word concatenatedfor example word abcdef abcdef abefcd cdabef cdefab efabcd efcdab concatenate string acdbef concatenate substre concatenation permutation wordsreturn start index concatenate substring s you return answer order Example 1input s barfoothefoobarman word foobaroutput 09explanation since wordslength 2 wordsilength 3 concatenate substring length 6the substring start 0 barfoo it concatenation barfoo permutation wordsthe substring start 9 foobar it concatenation foobar permutation wordsThe output order matter return 90 fine tooexample 2input s wordgoodgoodgoodbestword word wordgoodbestwordOutput Explanation since wordslength 4 wordsilength 4 concatenate substring length 16there substre length 16 s equal concatenation permutation wordsWe return arrayExample 3Input s barfoofoobarthefoobarman word barfootheOutput 6912explanation since wordslength 3 wordsilength 3 concatenate substre length 9the substring start 6 foobarthe it concatenation foobarthe permutation wordsthe substring start 9 barthefoo it concatenation barthefoo permutation wordsthe substre start 12 thefoobar it concatenation thefoobar permutation word Constraints1 slength 1041 wordslength 50001 wordsilength 30 wordsi consist lowercase english letter
2string
a permutation array integer arrangement member sequence linear orderfor example arr 123 follow permutation arr 123 132 2 1 3 2 3 1 312 321the permutation array integer lexicographically great permutation integer more formally permutation array sort container accord lexicographical order permutation array permutation follow sorted container if arrangement possible array rearrange low possible order ie sort ascending orderfor example permutation arr 123 132similarly permutation arr 231 312while permutation arr 321 123 321 lexicographical large rearrangementGiven array integer num find permutation numsthe replacement place use constant extra memory Example 1input num 123output 132example 2input num 321output 123Example 3input num 115Output 151 Constraints1 numslength 1000 numsi 100
0array
give string contain character return length long valid wellformed parenthesis substre Example 1input s output 2explanation the long valid parenthesis substre Example 2input s output 4explanation the long valid parenthesis substre Example 3input s output 0 constraints0 slength 3 104si
2string
there integer array num sort ascending order distinct valuesPrior pass function num possibly rotate unknown pivot index k 1 k numslength result array numsk numsk1 numsn1 nums0 nums1 numsk1 0indexed for example 0124567 rotate pivot index 3 4567012given array num possible rotation integer target return index target num 1 numsYou write algorithm Olog n runtime complexity Example 1input num 4567012 target 0output 4example 2input num 4567012 target 3output 1Example 3input num 1 target 0output 1 Constraints1 numslength 5000104 numsi 104All value num uniquenum ascend array possibly rotated104 target 104
0array
give array integer num sort nondecrease order find start end position give target valueif target find array return 1 1you write algorithm Olog n runtime complexity Example 1input num 5778810 target 8Output 34example 2input num 5778810 target 6output 11example 3input num target 0Output 11 constraints0 numslength 105109 numsi 109nums nondecrease array109 target 109
0array
give sorted array distinct integer target value return index target find if return index insert orderyou write algorithm Olog n runtime complexity Example 1input num 1356 target 5Output 2example 2input num 1356 target 2Output 1Example 3input num 1356 target 7Output 4 Constraints1 numslength 104104 numsi 104nums contain distinct value sort ascend order104 target 104
0array
determine 9 x 9 Sudoku board valid only fill cell need validate accord follow ruleseach row contain digit 19 repetitioneach column contain digit 19 repetitioneach 3 x 3 subboxes grid contain digit 19 repetitionnotea Sudoku board partially fill valid necessarily solvableonly fill cell need validate accord mention rule Example 1input board 537619598686348317266284195879output trueExample 2input board 837619598686348317266284195879output falseExplanation Same Example 1 5 leave corner modify 8 since 8 leave 3x3 subbox invalid Constraintsboardlength 9boardilength 9boardij digit 19
0array
write program solve sudoku puzzle fill cellsa sudoku solution satisfy follow ruleseach digit 19 occur exactly roweach digits 19 occur exactly columneach digits 19 occur exactly 9 3x3 subboxe gridThe character indicate cell Example 1input board 537619598686348317266284195879output 534678912672195348198342567859761423426853791713924856961537284287419635345286179explanation the input board show valid solution show Constraintsboardlength 9boardilength 9boardij digit it guarantee input board solution
0array
the countandsay sequence sequence digit string define recursive formulacountandsay1 1countandsayn way digit string countandsayn1 convert different digit stringTo determine digit string split minimal number substring substring contain exactly unique digit then substre number digits digit finally concatenate say digitfor example say conversion digit string 3322251given positive integer n return nth term countandsay sequence Example 1input n 1output 1explanation this base caseExample 2Input n 4Output 1211ExplanationcountAndSay1 1countandsay2 1 1 11countandsay3 11 1s 21countandsay4 21 2 1 12 11 1211 Constraints1 n 30
2string
give array distinct integer candidate target integer target return list unique combination candidate choose number sum target you return combination orderthe number choose candidate unlimited number time two combination unique frequency choose number differentThe test case generate number unique combination sum target 150 combination give input Example 1input candidate 2367 target 7output 2237explanation2 3 candidate 2 2 3 7 note 2 multiple times7 candidate 7 7these combinationsExample 2input candidate 235 target 8Output 222223335example 3input candidate 2 target 1output Constraints1 candidateslength 302 candidatesi 40all element candidate distinct1 target 40
0array
give collection candidate number candidate target number target find unique combination candidate candidate number sum targeteach number candidate combinationnote the solution set contain duplicate combination example 1input candidate 10127615 target 8output 1161251726example 2input candidate 25212 target 5output 1225 Constraints1 candidateslength 1001 candidatesi 501 target 30
0array
give unsorted integer array num return smallest miss positive integeryou implement algorithm run on time use constant extra space Example 1input num 120output 3explanation the number range 12 arrayExample 2input num 3411output 2explanation 1 array 2 missingexample 3input num 7891112output 1explanation the small positive integer 1 miss Constraints1 numslength 105231 numsi 231 1
0array
give n nonnegative integer represent elevation map width bar 1 compute water trap rain Example 1input height 010210132121output 6explanation the elevation map black section represent array 010210132121 in case 6 unit rain water blue section trappedexample 2input height 420325output 9 Constraintsn heightlength1 n 2 1040 heighti 105
0array
give nonnegative integer num1 num2 represent string return product num1 num2 represent stringnote you use builtin BigInteger library convert inputs integer directly Example 1input num1 2 num2 3output 6Example 2input num1 123 num2 456Output 56088 Constraints1 num1length num2length 200num1 num2 consist digit onlyboth num1 num2 contain lead zero number 0
2string
give input string s pattern p implement wildcard pattern matching support match single character match sequence character include sequencethe match cover entire input string partial Example 1input s aa p aOutput falseexplanation match entire string aaexample 2input s aa p output trueexplanation match sequenceexample 3input s cb p aOutput falseexplanation match c second letter match b constraints0 slength plength 2000s contain lowercase english lettersp contain lowercase english letter
2string
you give 0indexed array integer num length n you initially position nums0each element numsi represent maximum length forward jump index in word numsi jump numsi j where0 j numsi andi j nReturn minimum number jump reach numsn 1 the test case generate reach numsn 1 Example 1input num 23114output 2explanation the minimum number jump reach index 2 jump 1 step index 0 1 3 step indexExample 2input num 23014output 2 Constraints1 numslength 1040 numsi 1000
0array
give array num distinct integer return possible permutation you return answer order Example 1input num 123output 123132213231312321example 2input num 01output 0110example 3input num 1output 1 Constraints1 numslength 610 numsi 10All integer num unique
0array
give collection number num contain duplicate return possible unique permutation order Example 1input num 112Output112 121 211example 2input num 123output 123132213231312321 Constraints1 numslength 810 numsi 10
0array
you give n x n 2D matrix represent image rotate image 90 degree clockwiseYou rotate image inplace mean modify input 2D matrix directly do not allocate 2d matrix rotation example 1input matrix 123456789output 741852963example 2input matrix 51911248101336715141216output 15132514341126891671011 Constraintsn matrixlength matrixilength1 n 201000 matrixij 1000
0array
the nqueen puzzle problem place n queen n x n chessboard queens attack otherGiven integer n return distinct solution nqueen puzzle you return answer ordereach solution contain distinct board configuration nqueens placement Q indicate queen space respectively Example 1input n 4Output QQQQQQQQExplanation there exist distinct solution 4queens puzzle show aboveexample 2input n 1output Q Constraints1 n 9
0array
give integer array num find subarray large sum return sum Example 1input num 213412154output 6explanation 4121 large sum 6Example 2input num 1Output 1example 3input num 54178output 23 Constraints1 numslength 105104 numsi 104 Follow if figure on solution try code solution divide conquer approach subtle
0array
give m x n matrix return element matrix spiral order Example 1input matrix 123456789output 123698745example 2input matrix 123456789101112output 123481211109567 Constraintsm matrixlengthn matrixilength1 m n 10100 matrixij 100
0array
you give integer array num you initially position array index element array represent maximum jump length positionreturn true reach index false Example 1input num 23114output trueexplanation jump 1 step index 0 1 3 step indexExample 2input num 32104output falseexplanation you arrive index 3 matter its maximum jump length 0 make impossible reach index Constraints1 numslength 1040 numsi 105
0array
give array intervals intervalsi starti endi merge overlap interval return array nonoverlapping intervals cover interval input Example 1input interval 13268101518output 168101518explanation since interval 13 26 overlap merge 16example 2input interval 1445output 15explanation interval 14 45 consider overlap Constraints1 intervalslength 104intervalsilength 20 starti endi 104
0array
you give array nonoverlapping intervals intervals intervalsi starti endi represent start end ith interval interval sort ascending order starti you give interval newinterval start end represent start end intervalInsert newInterval interval interval sort ascending order starti interval overlap interval merge overlap interval necessaryReturn interval insertion Example 1input interval 1369 newInterval 25output 1569example 2input interval 1235678101216 newinterval 48output 123101216explanation because new interval 48 overlap 3567810 constraints0 intervalslength 104intervalsilength 20 starti endi 105intervals sort starti ascend ordernewintervallength 20 start end 105
0array
give string s consist word space return length word stringa word maximal substring consist nonspace character example 1input s hello WorldOutput 5explanation the word World length 5example 2input s fly moon Output 4explanation the word moon length 4example 3input s luffy joyboyoutput 6explanation the word joyboy length 6 constraints1 slength 104s consist english letter space there word s
2string
give positive integer n generate n x n matrix fill element 1 n2 spiral order Example 1input n 3output 123894765example 2input n 1output 1 Constraints1 n 20
0array
you give m x n integer array grid there robot initially locate topleft corner ie grid00 the robot try bottomright corner ie gridm 1n 1 the robot right point timeAn obstacle space mark 1 0 respectively grid a path robot take include square obstaclereturn number possible unique path robot reach bottomright cornerthe testcase generate answer equal 2 109 Example 1input obstacleGrid 000010000output 2explanation there obstacle middle 3x3 grid aboveThere way reach bottomright corner1 right right down down2 down down right RightExample 2input obstacleGrid 0100output 1 Constraintsm obstacleGridlengthn obstaclegridilength1 m n 100obstaclegridij 0 1
0array
give m x n grid fill nonnegative number find path leave right minimize sum number pathnote you right point time Example 1input grid 131151421output 7explanation because path 1 3 1 1 1 minimize sumExample 2input grid 123456output 12 Constraintsm gridlengthn gridilength1 m n 2000 gridij 100
0array
a valid number split component ordera decimal number integeroptional an e e follow integerA decimal number split component orderoptional a sign character one follow formatsone digit follow dot one digit follow dot follow digitsa dot follow digitsAn integer split component orderoptional a sign character one digitsfor example follow valid number 2 0089 01 314 4 9 2e10 90e3 3e7 6e1 535e93 123456e789 follow valid number abc 1a 1e e3 99e25 6 3 95a54e53given string s return true s valid number Example 1input s 0output trueExample 2input s eOutput falseexample 3input s output false Constraints1 slength 20 consist english letter uppercase lowercase digit 09 plus minus dot
2string
you give large integer represent integer array digits digitsi ith digit integer the digit order significant significant lefttoright order the large integer contain lead 0sincrement large integer return result array digit Example 1input digit 123output 124explanation the array represent integer 123incrementing give 123 1 124thus result 124example 2input digits 4321output 4322explanation the array represent integer 4321incrementing give 4321 1 4322thus result 4322example 3input digits 9output 10explanation the array represent integer 9incrementing give 9 1 10thus result 10 Constraints1 digitslength 1000 digitsi 9digits contain lead 0s
0array
give binary string b return sum binary string Example 1input 11 b 1output 100example 2input 1010 b 1011output 10101 Constraints1 alength blength 104a b consist 0 1 characterseach string contain lead zero zero
2string
give string path absolute path start slash file directory Unixstyle file system convert simplified canonical pathIn Unixstyle file system period refer current directory double period refer directory level multiple consecutive slash ie treat single slash for problem format period treat filedirectory namesthe canonical path follow formatthe path start single slash any directory separate single slash the path end trail the path contain directory path root directory target file directory ie period double period Return simplify canonical path Example 1input path homeOutput homeExplanation note trail slash directory nameExample 2input path Output Explanation go level root directory noop root level high level goexample 3input path homefoooutput homefooexplanation in canonical path multiple consecutive slash replace single Constraints1 pathlength 3000path consist english letter digit period slash _ path valid absolute Unix path
2string
give string word1 word2 return minimum number operation require convert word1 word2You follow operation permit wordInsert characterdelete characterreplace character example 1input word1 horse word2 rosOutput 3explanation horse rorse replace h rrorse rise remove rrose ros remove eExample 2input word1 intention word2 executionOutput 5explanation intention inention remove tinention enention replace eenention exention replace n xexention exection replace n cexection execution insert u constraints0 word1length word2length 500word1 word2 consist lowercase english letter
2string
give m x n integer matrix matrix element 0 set entire row column 0syou place example 1input matrix 111101111output 101000101example 2input matrix 012034521315output 000004500310 Constraintsm matrixlengthn matrix0length1 m n 200231 matrixij 231 1 Follow upa straightforward solution Omn space probably bad ideaa simple improvement use Om n space well solutioncould devise constant space solution
0array
write efficient algorithm search value target m x n integer matrix matrix this matrix follow propertiesinteger row sort leave rightThe integer row great integer previous row Example 1input matrix 13571011162023303460 target 3output trueExample 2input matrix 13571011162023303460 target 13Output false Constraintsm matrixlengthn matrixilength1 m n 100104 matrixij target 104
0array
give array num n object color red white blue sort inplace object color adjacent color order red white blueWe use integer 0 1 2 represent color red white blue respectivelyyou solve problem library sort function Example 1input num 202110output 001122example 2input num 201output 012 Constraintsn numslength1 n 300numsi 0 1 2 follow could come onepass algorithm constant extra space
0array
give string s t length m n respectively return minimum window substring s character t include duplicate include window if substre return stre the testcase generate answer unique Example 1input s adobecodebanc t abcoutput BANCExplanation the minimum window substre BANC include a b c string tExample 2input s t aOutput aExplanation the entire string s minimum windowexample 3input s t aaOutput Explanation both t include windowsince large window s return string Constraintsm slengthn tlength1 m n 105s t consist uppercase lowercase english letter Follow could find algorithm run Om n time
2string
give integer array num unique element return possible subset power setthe solution set contain duplicate subset return solution order Example 1input num 123output 121231323123example 2input num 0output 0 Constraints1 numslength 1010 numsi 10all number num unique
0array
give m x n grid character board string word return true word exist gridthe word construct letter sequentially adjacent cell adjacent cell horizontally vertically neighbor the letter cell Example 1input board ABCESFCSADEE word ABCCEDOutput trueExample 2Input board ABCESFCSADEE word SEEOutput trueExample 3input board ABCESFCSADEE word ABCBOutput false Constraintsm boardlengthn boardilength1 m n 61 wordlength 15board word consist lowercase uppercase English letter Follow could use search prune solution fast large board
0array
give integer array num sort nondecrease order remove duplicate inplace unique element appear twice the relative order element keep samesince impossible change length array language instead result place array num more formally k element remove duplicate k element num hold final result it matter leave k elementsReturn k place final result k slot numsDo allocate extra space array you modify input array inplace O1 extra memoryCustom JudgeThe judge test solution follow codeint num Input arrayint expectednum the expected answer correct lengthint k removeduplicatesnum Calls implementationassert k expectednumslengthfor int 0 k assert numsi expectednumsiif assertion pass solution accept Example 1input num 111223output 5 num 11223_explanation your function return k 5 element num 1 1 2 2 3 respectivelyit matter leave return k underscoresExample 2input num 001111233output 7 num 0011233__explanation your function return k 7 seven element num 0 0 1 1 2 3 3 respectivelyit matter leave return k underscore Constraints1 numslength 3 104104 numsi 104nums sort nondecrease order
0array
there integer array num sort nondecrease order necessarily distinct valuesbefore pass function num rotate unknown pivot index k 0 k numslength result array numsk numsk1 numsn1 nums0 nums1 numsk1 0indexed for example 0124445667 rotate pivot index 5 4566701244given array num rotation integer target return true target num false numsYou decrease overall operation step possible Example 1input num 2560012 target 0output trueExample 2input nums 2560012 target 3output false Constraints1 numslength 5000104 numsi 104nums guarantee rotate pivot104 target 104 follow this problem similar Search rotate Sorted Array num contain duplicate would affect runtime complexity how
0array
give array integer height represent histograms bar height width bar 1 return area large rectangle histogram Example 1input height 215623output 10explanation the histogram width bar 1the large rectangle show red area area 10 unitsexample 2input height 24output 4 constraints1 heightslength 1050 heightsi 104
0array
give row x col binary matrix fill 0s 1s find large rectangle contain 1 return area Example 1input matrix 10100101111111110010output 6explanation the maximal rectangle show pictureexample 2input matrix 0output 0Example 3Input matrix 1Output 1 Constraintsrows matrixlengthcol matrixilength1 row col 200matrixij 0 1
0array
we scramble stre s string t follow algorithmif length string 1 stopif length string 1 followingsplit string nonempty substring random index ie string s divide x y s x yRandomly decide swap substring order ie step s s x y s y xApply step 1 recursively substring x ygiven string s1 s2 length return true s2 scramble string s1 return false Example 1input s1 great s2 rgeatoutput trueExplanation one possible scenario apply s1 isgreat great divide random indexgreat great random decision swap substring ordergreat gr eat apply algorithm recursively substring divide random index themgr eat rg eat random decision swap substre second substre orderrg eat rg e apply algorithm recursively divide atrg e rg e random decision substring orderthe algorithm stop result stre rgeat s2a possible scenario lead s1 scramble s2 return trueexample 2input s1 abcde s2 caebdoutput falseexample 3input s1 s2 aoutput true constraintss1length s2length1 s1length 30s1 s2 consist lowercase english letter
2string
you give integer array nums1 nums2 sort nondecrease order integer m n represent number element nums1 nums2 respectivelyMerge nums1 nums2 single array sort nondecrease orderthe final sorted array return function instead store inside array nums1 to accommodate nums1 length m n m element denote element merge n element set 0 ignore nums2 length n example 1input nums1 123000 m 3 nums2 256 n 3output 122356explanation the array merge 123 256the result merge 122356 underline element come nums1Example 2input nums1 1 m 1 nums2 n 0output 1explanation the array merge 1 the result merge 1example 3input nums1 0 m 0 nums2 1 n 1output 1explanation the array merge 1the result merge 1note m 0 element nums1 the 0 ensure merge result fit nums1 Constraintsnums1length m nnums2length n0 m n 2001 m n 200109 nums1i nums2j 109 Follow can come algorithm run Om n time
0array
give integer array num contain duplicate return possible subset power setthe solution set contain duplicate subset return solution order Example 1input num 122output 112122222example 2input num 0output 0 Constraints1 numslength 1010 numsi 10
0array
a message contain letter AZ encode number follow mappingA 1B 2Z 26To decode encode message digit group map letter reverse mapping multiple way for example 11106 map intoAAJF group 1 1 10 6kjf group 11 10 6note group 1 11 06 invalid 06 map F 6 different 06given string s contain digit return number way decode itThe test case generate answer fit 32bit integer Example 1input s 12output 2explanation 12 decode AB 1 2 l 12example 2input s 226output 3explanation 226 decode BZ 2 26 VF 22 6 BBF 2 2 6example 3input s 06output 0explanation 06 map F lead zero 6 different 06 Constraints1 slength 100s contain digit contain lead zero
2string
a valid ip address consist exactly integer separate single dot each integer 0 255 inclusive lead zerosFor example 012201 19216811 valid IP address 0011255245 1921681312 19216811 invalid IP addressesGiven stre s contain digit return possible valid ip address form insert dot s you allow reorder remove digit s you return valid IP address order Example 1input s 25525511135output 2552551113525525511135example 2input s 0000output 0000example 3input s 101023output 101023101023101023101023101023 Constraints1 slength 20s consist digit
2string
give root binary tree return inorder traversal nodes value example 1input root 1null23output 132example 2input root Output Example 3input root 1output 1 ConstraintsThe number nod tree range 0 100100 Nodeval 100 Follow Recursive solution trivial iteratively
1graph
give string s1 s2 s3 find s3 form interleave s1 s2an interleaving string s t configuration s t divide n m substring respectively that s s1 s2 snt t1 t2 tmn m 1the interleaving s1 t1 s2 t2 s3 t3 t1 s1 t2 s2 t3 s3 Note b concatenation string b example 1input s1 aabcc s2 dbbca s3 aadbbcbcacoutput trueExplanation one way obtain s3 isSplit s1 s1 aa bc c s2 s2 dbbc aInterleaving split aa dbbc bc c aadbbcbcacsince s3 obtain interleaving s1 s2 return trueexample 2input s1 aabcc s2 dbbca s3 aadbbbacccOutput falseexplanation Notice impossible interleave s2 string obtain s3example 3input s1 s2 s3 Output true constraints0 s1length s2length 1000 s3length 200s1 s2 s3 consist lowercase English letter Follow could solve os2length additional memory space
2string
give root binary tree determine valid binary search tree bsta valid BST define followsthe 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 213output trueExample 2input root 514nullnull36Output falseexplanation the root node value 5 right child value 4 ConstraintsThe number nod tree range 1 104231 Nodeval 231 1
1graph
you give root binary search tree BST value exactly nod tree swap mistake Recover tree change structure example 1input root 13nullnull2output 31nullnull2explanation 3 leave child 1 3 1 swap 1 3 make BST validExample 2input root 314nullnull2output 214nullnull3explanation 2 right subtree 3 2 3 swap 2 3 make BST valid ConstraintsThe number nod tree range 2 1000231 Nodeval 231 1 follow A solution on space pretty straightforward could devise constant o1 space solution
1graph
give root binary tree p q write function check nottwo binary tree consider structurally identical node value Example 1Input p 123 q 123output trueExample 2input p 12 q 1null2output falseexample 3input p 121 q 112output false ConstraintsThe number nod tree range 0 100104 Nodeval 104
1graph
give root binary tree check mirror ie symmetric center Example 1input root 1223443output trueExample 2input root 122null3null3output false ConstraintsThe number nod tree range 1 1000100 Nodeval 100 Follow could solve recursively iteratively
1graph
give root binary tree return level order traversal nod value ie leave right level level example 1input root 3920nullnull157Output 3920157example 2input root 1Output 1Example 3input root Output ConstraintsThe number nod tree range 0 20001000 Nodeval 1000
1graph
give root binary tree return zigzag level order traversal nodes value ie leave right right left level alternate Example 1input root 3920nullnull157Output 3209157example 2input root 1Output 1Example 3input root Output ConstraintsThe number nod tree range 0 2000100 Nodeval 100
1graph
give integer array preorder inorder preorder preorder traversal binary tree inorder inorder traversal tree construct return binary tree Example 1input preorder 3920157 inorder 9315207output 3920nullnull157example 2input preorder 1 inorder 1output 1 Constraints1 preorderlength 3000inorderlength preorderlength3000 preorderi inorderi 3000preorder inorder consist unique valueseach value inorder appear preorderpreorder guarantee preorder traversal treeinorder guarantee inorder traversal tree
0array