question
stringlengths
58
4.29k
label
class label
3 classes
you give integer array num integer minK maxKA fixedbound subarray num subarray satisfie follow conditionsThe minimum value subarray equal minKThe maximum value subarray equal maxkreturn number fixedbound subarraysA subarray contiguous array Example 1input num 135275 mink 1 maxk 5output 2explanation the fixedbound subarray 135 1352example 2input num 1111 mink 1 maxk 1output 10explanation every subarray num fixedbound subarray there 10 possible subarray Constraints2 numslength 1051 numsi mink maxk 106
0array
give integer array num integer k return number subarray num great common divisor subarray elements ka subarray contiguous nonempty sequence element arrayThe great common divisor array large integer evenly divide array element Example 1input num 931263 k 3output 4explanation the subarray num 3 great common divisor subarray element 931263 931263 931263 931263example 2input num 4 k 7output 0explanation there subarray num 7 great common divisor subarray element Constraints1 numslength 10001 numsi k 109
0array
you give 0indexe array num cost consist n positive integersyou follow operation number timesincrease decrease element array num 1the cost operation ith element costiReturn minimum total cost element array num equal Example 1input num 1352 cost 23114output 8explanation we element equal 2 follow way increase 0th element time the cost 2 Decrease 1st element time the cost 3 Decrease 2nd element time the cost 1 1 1 3the total cost 2 3 3 8it show array equal small costExample 2input num 22222 cost 42813output 0explanation all element equal operation need Constraintsn numslength costlength1 n 1051 numsi costi 106
0array
you give positive integer array nums target lengthIn operation choose distinct index j 0 j numslength andset numsi numsi 2 andset numsj numsj 2two array consider similar frequency element samereturn minimum number operation require num similar target the test case generate num similar target Example 1input num 8126 target 21410output 2explanation it possible num similar target operation choose 0 j 2 num 10124 choose 1 j 2 num 10142it show 2 minimum number operation neededexample 2input num 125 target 413output 1explanation we num similar target operation choose 1 j 2 num 143example 3input num 11111 target 11111output 0explanation the array num similiar target Constraintsn numslength targetlength1 n 1051 numsi targeti 106it possible num similar target
0array
you give array equallength string word assume length string nEach string wordsi convert difference integer array differencei length n 1 differenceij wordsij1 wordsij 0 j n 2 note difference letter difference position alphabet ie position 0 b 1 z 25For example stre acb difference integer array 2 0 1 2 2 1all string word difference integer array you find stringreturn string word different difference integer array Example 1input word adcwzyabcoutput abcexplanation the difference integer array adc 3 0 2 3 3 1 the difference integer array wzy 25 22 24 25 3 1 the difference integer array abc 1 0 2 1 1 1 the odd array 1 1 return correspond string abcexample 2input word aaabobcccdddoutput bobexplanation all integer array 0 0 bob correspond 13 13 Constraints3 wordslength 100n wordsilength2 n 20wordsi consist lowercase english letter
2string
you give 0indexed array num consist positive integer represent target number line you give integ spaceyou machine destroy target seed machine numsi allow destroy target value represent numsi c space c nonnegative integer you want destroy maximum number target numsreturn minimum value numsi seed machine destroy maximum number target Example 1input num 378115 space 2output 1explanation if seed machine nums3 destroy target equal 13579 in case destroy 5 total target nums2 it impossible destroy 5 target return nums3example 2input num 135246 space 2output 1explanation seeding machine nums0 nums3 destroy 3 target it possible destroy 3 targetssince nums0 minimal integer destroy 3 target return 1example 3input num 625 space 100output 2explanation whatever initial seed select destroy 1 target the minimal seed nums1 Constraints1 numslength 1051 numsi 1091 space 109
0array
you give 0indexed array nonnegative integer num for integer num find respective second great integerthe second great integer numsi numsj thatj inumsj numsiThere exist exactly index k numsk numsi k jIf numsj second great integer consider 1for example array 1 2 4 3 second great integer 1 4 2 3 3 4 1return integer array answer answeri second great integer numsi Example 1input num 24096output 96611explanation0th index 4 integer great 2 9 second integer great 2 right 21st index 9 6 second integer great 4 right 42nd index 9 6 second integer great 0 right 03rd index there integer great 9 right second great integer consider 14th index there integer great 6 right second great integer consider 1Thus return 96611example 2input num 33output 11explanationwe return 11 integer integer great Constraints1 numslength 1050 numsi 109
0array
give integer array num positive integer return average value integer divisible 3note average n element sum n element divide n round near integer Example 1input num 136101215output 9explanation 6 12 number divisible 3 6 12 2 9example 2input num 124710output 0explanation there single number satisfie requirement return 0 Constraints1 numslength 10001 numsi 1000
0array
you give 0indexed array num size n consist nonnegative integersYou need apply n 1 operation array ith operation 0indexe apply follow ith element numsif numsi numsi 1 multiply numsi 2 set numsi 1 0 otherwise skip operationafter perform operation shift 0s end arrayfor example array 102001 shift 0s end 121000return result arraynote operation apply sequentially Example 1input num 122110output 142000explanation we follow operation 0 nums0 nums1 equal skip operation 1 nums1 nums2 equal multiply nums1 2 change nums2 0 the array 140110 2 nums2 nums3 equal skip operation 3 nums3 nums4 equal multiply nums3 2 change nums4 0 the array 140200 4 nums4 nums5 equal multiply nums4 2 change nums5 0 the array 140200after shift 0s end give array 142000example 2input num 01output 10explanation no operation apply shift 0 end Constraints2 numslength 20000 numsi 1000
0array
you give integer array num integer k find maximum subarray sum subarray num meet follow conditionsThe length subarray k andall element subarray distinctreturn maximum subarray sum subarray meet condition if subarray meet condition return 0A subarray contiguous nonempty sequence element array Example 1input num 1542999 k 3Output 15explanation the subarray num length 3 154 meet requirement sum 10 542 meet requirement sum 11 429 meet requirement sum 15 299 meet requirement element 9 repeat 999 meet requirement element 9 repeatedwe return 15 maximum subarray sum subarray meet conditionsExample 2input num 444 k 3output 0explanation the subarray num length 3 444 meet requirement element 4 repeatedwe return 0 subarray meet condition Constraints1 k numslength 1051 numsi 105
0array
you give 0indexed integer array cost costsi cost hire ith workeryou give integer k candidate we want hire exactly k worker accord follow rulesyou run k session hire exactly worker sessionin hiring session choose worker low cost candidate worker candidate worker break tie smallest indexfor example cost 327712 candidate 2 hiring session choose 4th worker low cost 327712in second hiring session choose 1st worker low cost 4th worker small index 32772 please note indexing change processif few candidate worker remain choose worker low cost Break tie small indexA worker choose oncereturn total cost hire exactly k worker Example 1input cost 17121027211208 k 3 candidate 4output 11explanation we hire 3 worker total the total cost initially 0 in hire round choose worker 17121027211208 the low cost 2 break tie small index 3 the total cost 0 2 2 in second hire round choose worker 1712107211208 the low cost 2 index 4 the total cost 2 2 4 in hire round choose worker 171210711208 the low cost 7 index 3 the total cost 4 7 11 Notice worker index 3 common workersThe total hiring cost 11example 2input cost 1241 k 3 candidate 3output 4explanation we hire 3 worker total the total cost initially 0 in hire round choose worker 1241 the low cost 1 break tie small index 0 the total cost 0 1 1 Notice worker index 1 2 common 3 worker in second hire round choose worker 241 the low cost 1 index 2 the total cost 1 1 2 in hire round candidate we choose worker remain worker 24 the low cost 2 index 0 the total cost 2 2 4the total hiring cost 4 Constraints1 costslength 1051 costsi 1051 k candidate costslength
0array
there robot factory Xaxis you give integer array robot roboti position ith robot you give 2D integer array factory factoryj positionj limitj indicate positionj position jth factory jth factory repair limitj robotsThe position robot unique the position factory unique Note robot position factory initiallyall robot initially break move direction the direction negative positive direction Xaxis when robot reach factory reach limit factory repair robot stop movingat moment set initial direction move robot your target minimize total distance travel robotsreturn minimum total distance travel robot the test case generate robot repairedNote thatall robot speedif robot direction collideif robot opposite direction meet point collide they cross otherif robot pass factory reach limit crosse existIf robot move position x position y distance move y x Example 1input robot 046 factory 2262output 4explanation as show figure the robot position 0 move positive direction it repair factory the second robot position 4 move negative direction it repair factory the robot position 6 repair second factory it need moveThe limit factory 2 fix 2 robotsthe limit second factory 2 fix 1 robotthe total distance 2 0 2 4 6 6 4 it show achieve well total distance 4example 2input robot 11 factory 2121output 2explanation as show figure the robot position 1 move positive direction it repair second factory the second robot position 1 move negative direction it repair factoryThe limit factory 1 fix 1 robotthe limit second factory 1 fix 1 robotthe total distance 2 1 2 1 2 it show achieve well total distance 2 constraints1 robotlength factorylength 100factoryjlength 2109 roboti positionj 1090 limitj robotlengththe input generate possible repair robot
0array