 What's up guys, this is a I'm doing a contest of 687 This is this is actually a different time zone for me. It's actually late at night So I'm actually has more have more energy than doing it early in the morning And only it's like eight or nine in the morning. I just don't have the energy to do it So I just go back to bed, but now this is late at night. So Yeah, we have 10 minutes in before before I actually do these problems and hopefully I could get green Hopefully I could get green Let me let me pull up the Visual studio I was doing some homework. I was doing algorithms homework Proof and be completeness homework before I was doing this. So yeah So that's actually a good way to get the head in the game and try to solve these problems Yeah, let's let's see. Let's see how we do on this contest and then we're gonna Be on our way. Hopefully I get to hopefully I get to green this contest So I'm not 100% sure if I can the green is very Getting the green is pretty difficult You got to get our pencil and paper To do this problem and see if we could Do it Yeah, I'm not gonna get my tablet to record would writing on the thing I think I Think I'd do better when I have like a pen and paper. She's like solving solving the problems But yeah, this is the vision to based on a techno cup elimination round Techno cup a little in the elimination round. I think that has to do with them That's not as you soccer. I don't know. It's for like high school students. I think I don't know. I don't know It's kind of like a co-chef co-chef is similar to high school students. Also But yeah, let me actually close all my tabs Because NP completeness is not something that we are doing right here get rid of NP completeness, okay? And then I'm gonna do this contest and then I'm going to Yeah, I'm gonna try to figure out grind out some of homework problems after this But yeah, actually, I'm gonna go to bed after after finish the contest. So yeah There was another contest of ad coder and I did not actually get to do that problem There was that 7 a.m. In the morning like I didn't have energy to wake up but Yeah, maybe maybe next time I'll Saturday Saturday, what is that? Oh this Saturday, okay? Maybe this Saturday this Saturday. I'll I'll try to do the ad coder contest, but yeah Anyhow, it's only seven minutes and then we'll start Um Yeah, I think hopefully the first problem might be just be um This is another problem. I was doing I was doing um, what do you call it? What do you call it? Uh? Okay, I was doing a I was doing an ad hoc problem. I got it submitted. Yeah, that was that was good okay, so basically from my point of view of doing these contests I Realized the first problem or second problem is probably either ad hoc or greedy or is a number theory Okay, so if we were able to do either of the first two pretty fast then um, maybe we'll be able to get the green I don't know but For me is like getting the second problem Right is tough for me. I don't know. It's like this the first problem is like easy for me The second one is hard Like I could tripped up on the second one and then I just end up not solving it because like if No, it's not I it's not like I'm not solving. It's like I just don't I just don't I just give up Okay, that's the thing about these problems Some people don't even do this like some people just go directly to see and then if they solve it They're like hey yippity-doodle, you know, and then they're already specialist That's what does that look that some of the some of the people there And they don't even deal with the ad hoc or the number theory of one and two or the greedy so I Don't know Maybe we should do that strategy instead. Just like salt, which is go through one tooth ABC and just Maybe maybe it's better to solve C first see if you could solve C and then do a and B But I don't know that's that's kind of it is that is kind of more difficult, but I don't know I Don't know but Speed speed is important I think I've gotten better at it like Getting faster at typing typing speed and like trying to solve a fast So I think I could do that, but I don't know it. I'm actually not sure if Not a hundred percent sure if we could do this. So, um, normally there's test cases, right? So If it's like n and x then let's do that some people have like templates that they do before they start the contest so they like do They have like inputs already pre-planned so they know they had they just have to do just parse it Me maybe maybe we should maybe I should do like some people have like Inbuilt macros in order to type faster. Maybe we should do that So I already have this part for to make fast IO But I have not increased typing speed. So Some people do it. So the some people do like rep the type and rep and then boom, you don't have to do that much But uh, yeah, those guys are They really take these contests seriously try to try to solve it as fast as possible. I know like um, I don't know I'm trying to take like I'm trying to for like I'm watching other I watch other youtubers who are also competitive programmers So like a second threat and calling and they they give their Your ideas how to improve. So I'm trying to improve also Um, so I'm just trying to take part as as many virtual contests also absolving I did not absolve the ad coder the other ad coder contest ad coder is more about like math thinking Then I realize like if you go to ad coder and go to like their problems Especially math and thinking Like uh, this this problem is does mostly just the c problem. This was definitely just math Uh, yeah, this is definitely math. You have to be able to like count but um Yeah, this is definitely math. Uh, how you you need a minimum of a piece moves through for a piece a to reach piece b Yeah, that's That's just math, but um Yeah, I don't know Don't know, um Increment of coins. I think this was also math. Oh, this is Oh crap. This was this is this probability. Okay crap. Okay. Yeah ad code is mostly math, but uh being good at math It might be better to do more ad coder contests to get better at math actually I don't know. So I feel like code forces is mostly um ad hoc In greedy ad coder contests are mostly mathematical and then um What was it? What was the other code chef is mostly data structures when I realize I think that's Like if you do any of the code chef problems They're mostly data structures, so Yeah, maybe it's better Like each site has it's like pros and cons and I think I know um Top coder is mostly dynamic programming. Like I I I've I've seen like a lot of the problems on top code I did not do the srm of top coder because I was just so tired That day Actually, that wasn't that that was in the That was in the um night time not not night time I forgot. What was it? I'm almost green on top coder. So that's something but Other times I did not Ah crap the next round is in 1229 hours. So that's way later. I didn't even register but anyway Last active match I didn't get to do do it um Yeah But like the thing is like I don't know Problem-based training error. They don't even have this Most people who do top coded aren't like uh They use other platforms to do it You can't even use if you got to use the actual applet to download That's how ugly the ui is Like look at this. Okay. This is really I don't know man It's fucking crazy crazy crazy. It's not even data science. Like it's not machine learning I don't know why they say data science. It's not even like it's just algorithms. Okay. Oh look 250 250 easy and equation. This is easy medium hard Do these numbers mean anything on top coder? I mean the the Color scheme. Is there a way to sort it by Easy, okay. I don't know I have no idea Yeah, we got to start this contest now. All right time to shut up and then try to actually do these problems One more they can move to Jason left top right bottom. Okay As long as the target cells inside the prison they could be done or they could choose to stay Prison wants no mental no acceptance it takes so that every person can arrive at cr Rc if they move optimally, what do they start at? Wait, what? Three five let's try three five There's n times m prisoners Oh There's also n times n prisoners 15 prisoners One in each cell each cell It's 20 20 3 4 4 4 Then you see something 10 by 2 Hold up. How do you get to this? How do you get to 6? Okay, that's not right. 3 5 4 Why is 3 5 4? Now you can hear that sound right c minus m minus c minus 1 Wait max to 4 minus 1 Shit this is hard 3 5 2 Okay, we should still have to we should still code it though minus r minus Come on 17 6 9. That's not right Um in here 9 5 5 That's not right. I also minus r plus m minus c That's what I was originally. I was thinking That gives you I'd see n minus r 2 2 that's not right Why is it 2? You have to do max r is equal to 2 C the c is equal to 4 4 4 minus so 5 minus 2 Fuck my life 5 3 minus 2 is 1 so 5 minus 1 is 4 5 minus 4 is 1 so that's 2 Okay, um Let's see 3 minus 2 is 1 max of 1 and 4 is 4 plus Minimum of 5 minus 4 1 1 That would give you Don't give you 5 that's not right This is not right Maybe it's not min You need to get 3 here Oh wait Not c it's n Wait n minus r n is 3 n minus r and max n is 3 minus n with n m minus c with m I think Why aren't you working? 19 4 is 11 last one is fudge Why is it not working? 10 2 5 1 n is 10 r is 5 m is 2 c is 1 minus r is 10 should be 6 Is it min 5 plus n minus n minus n is 10 so this is 5 4 this is 10 this is 10 should be min 10 is 4 wait 4 4 plus what's the min of n minus 2 minus 1 is 1 min of 4 plus 1 is 5 oh wait should be min I think this is 1 why isn't this copying 18 2 and 6 18 4 and 6 damn ok 3 5 2 4 multiply that would be 100 10 minus 6 plus 20 no 15 minus 2 that doesn't make any sense either hmm it's gonna take me a while to solve this problem 3 5 2 4 3 minus 2 is 1 9 minus 4 why is it 5 why is it 6 why is it 4 it takes 4 seconds why is it 4 it's because 2 and 4 are between 3 and 5 no wait 5 5 and 1 are both between it also hmm I don't know it's really difficult this is a really difficult problem 4 minus 3 3 minus 2 3 minus 2 is 1 1 plus 5 minus 4 4 5 minus 4 is 1 alright 3 minus 5 is 2 2 minus 4 is 2 4 nah that'll give you 0 wait 10 times 10 plus 10 is 20 20 minus 2 is 18 3 plus 5 is 8 8 minus 2 plus 4 is 6 it's 2 now that's not right 20 minus 6 14 that's not right hmm 10 maximum 4 seconds 10 minus 5 damn this is really that's all this problem before 10 minus 5 take 5 3 seconds plus 1 is 4 3 seconds plus 1 is 4 that's because 4 minus 1 is 3 plus 5 minus 4 3 plus 1 is 4 yeah 4 let's see why does it not work for this 10 minus 1 here 5 minus 1 5 minus 1 is 4 plus 4 plus 5 is 9 that's not right I'm not getting something 3, 4, 5, 6 it's because 10, 2 10, 2 3 minus 3 plus 1 is 4 3 plus 1 is 4, 1, 2, 3 1, 2, 3, 4 4 it's because 1, 1 oh I think I got it, okay I think I got it, okay n minus r plus c minus 3 minus 1 is 3 minus 1 is 1, 1 2 minus 1 is 1 plus 4 minus 1 is 3 r minus 1 plus r is 2 c minus 1 I think this is minimum, I think this would work 5, that's not right 2, 4 maybe max, maybe it's max maybe max 18, 4, 6, yeah I think this is right hopefully this is right 18, 4, 6, yeah hopefully this is right I don't know though, it just took a while dang wrong answer pretest 2 what am I doing wrong? what if it's 1, 1, 1, 1 that's a problem, okay hold up what is this? can they both be equal? I think they can would it really take 0? yeah it wouldn't take that much if there's one cell hmm one cell can you get to 0? that's a big question wait can you move diagonal? oh no you can't you can't move diagonal wait you can't move diagonal it's just okay I didn't read that correctly it would be 1, 2, 3, 4 3, 5 you have to add 1 n minus 5 is 5 plus 1 is 6 10, 10, 1, 1 maybe you have to add 1 1, 1, 1, 2, 3, 4 4 minus 1, 1, 2, 3 is 3 you need to add by so 4 minus 1 is 3 you need to add by 2, 2 minus 1 2 minus 1 is plus 10 minus 5 is 5 so 1, 2, 3, 4, 5 10 minus 5 is 5 plus 2 minus 1 is 5 plus 1 is 6 6 yeah but you also have to count 1, 1, 1, 2, 3, 4 5 minus 1 is 4 plus 1 minus 1 is 0 I don't know what I'm doing wrong I really don't know what I'm doing wrong what if we have a square let's think of different statements 3 by 3 let's say you're in the center so if it's 3 by 3 so if it's 3 by 3 it's n is equal to 3 n is equal to 3 r is equal to let's say you're in the center 1, 2, 3 r is equal to 2, 2 3, 3, 2, 2 3, 3 3, 3, 2, 2 2 is that right? 1, 2, 1, 2 1, 2, 1, 2 1, 2 yeah that is right um let's try a different one I should be able to solve this what am I getting wrong on pre-test 2 hmmm see how many people so many people got it wrong we should be able to solve the first problem at least okay we'll keep trying 1, 2, 3, 4 1, 2, 3, 4 so let's say it's 4, 4 alright 4, 4, 2, 2 should answer should be 4 okay that is right um what scenario does this not work top top left let's say it was top left 2, 3 1, 2 3, 4 1, 2, 4, 5 2, 3, 4, 5 6 6 wait 1, 2, 3, 4, 5 6 and so it would be 6 if it's in 4, 4, 1 4, 4, 1, 4 4, 4, 1, 4 4, 4, 1, 4 4 gives you 3 wait hold up that's not right 4, 4, 1, 4 should give you 3 wait that's not right ah you gotta think of the bottom left bottom right top right top left so we we did bottom right we also have to do bottom left and I think we also have to do top right I think yeah so bottom left okay um should be 6 okay uh let's see so we would have to do um so the answer is 4, 1 so we have to check n, n1 n is equal to 4 n is equal to 4 we need to check 4, 1 4 minus r1 so r is equal to 1c is equal to 4 we need to check 4 minus 1 is 3 plus 1 minus 4 is uh I mean 4 minus 1 4 minus 1 is n minus n minus 1 plus c minus c is 4 1 minus c abs of 1 minus c so max of abs hold up max of we also have to check 4 minus n minus 1 plus 1 minus c this has to be abs so this is n is 1 n wait okay what the hell okay uh n is this row r is 1 so n 4, 1 is uh n 1 yeah so this is gonna be distance between uh yeah yeah this should be right or it should be c minus 1 c minus 1 should be c minus 1 actually maybe it makes for a certain sense c minus 1 n minus 1 so n is 4 minus 1, 1, 2, 3 c minus 1 4 minus 1, 2, 3 so those would give you 6 okay uh let's see let's see the test case 4, 4, 1, 4 r is 1 c is 4 6 okay that's right let's try the other cases 10, 10, 1, 1 18 that right 3, 5 2, 4 5 ah damn why is it 5 10, 2, 5, 1 that's not right uh okay uh let's see maybe it's minimum 1, 2, 3, 4 3, 1, 3 minus 3 minus 2 3 minus 2 is 1 3 minus 2 is 1 plus 4 minus 2 4 minus 4 minus 1 r is 2 c is 4 c minus 1 n minus 4, 1, 1, 4 so the point of n I don't think it's n minus 1 c minus 1 it's n is 4 okay right n is equal to 4 n is equal to 1 no, no, no point this is point 2 is 1 c is equal to 4 so it would be c minus 1 plus n minus r let's see uh let's try for 4 4, 1, 4, 6 that's right let's try 10, 10, 1, 1 18 that's right let's see let's try the other one 3, 5, 2, 4 4 that's right 10, 2, 5, 1 6 is right okay let's think of other scenarios because I'm not 100% sure if this is right so we thought of bottom left bottom right and we did top left about top right do we think about top right yeah okay let's say it was here 4, 4 and then 4, 1 4, 4 and then 4, 1 let's see 4, 4 4, 4, 4, 1 that's not right it should be 6 so we have to think of top right also 1, 4 so that's what is 1, 4 top right is 1, 4 so that's 1 and then c, 1, c so your point is 1, c and then you're you're 1, c and then you're you're the one you're going to is 4, 1 so that's n c is equal to 1, c is equal to 4 oh no the point is not 1c the point is 1 1m okay so we're going to do 1, 4 so we're going to do 1 minus 1 no what we're going to do is we're going to do 1, 4 okay so rc is 1, 4 not rc what the fuck am I doing r is equal to 1 c is equal to 4 no rc is 4, 1 r is equal to 4, c is equal to 1 and you need to subtract with 1m so you guys do r minus 1 r which is 4 minus 1 plus m minus 1 wait what did I do no r minus n minus r 1 1, 4 n minus r n minus r plus c minus 1 what did I do that's not right n minus r we need to do 1, 4 and then 4, 1 we could do this 1, 4, 4, 1 and then m is 4 r minus 1 plus m minus c that's what it is max r minus 1 plus m minus c I think this is right why is this not right what the hell just happened what happened what the hell just happened oh close parentheses we don't need this yeah that works this should work let's try 4 and then 4, 1 6, yeah that's right let's try the other cases again 10, 10, 1, 1 18, right 3, 5, 2, 4 4, yeah 10, 2, 5, 1 6, I think that's right I think this is actually right I could be wrong though yes okay worth that's right that took a while but I got it, let's lock it okay let's try b there's a street with n houses in a line number from 1 to n the house i is painted with color c i street is considered beautiful if all houses are painted the same color the painter is in charge of the street beautiful the capacity is determined by k what can tom do you could do 2 steps we have managers l and r where it's between 1 and n and l minus r minus l plus 1 is equal to k okay so the we could basically pick a subset of the array of size k and then what do we do for each house between the subsets you could paint it any color you want and ignore it or ignore it or let it keep its current color you want to ignore it, ignore it it takes to repaint the street so it becomes beautiful okay we should be able to do this so you want to paint them initially the house c i street is beautiful if they're all painted the same color oh okay okay sounds like a prefix some problem okay so here you could do what can you do same day we have an hour left maybe we could solve b yeah so i did solve a so that's good let's try to solve b if we solve b maybe we'll get to division not division 1 dang how many people to solve b dang if you solve 1 in 10 minutes you're already 3000 okay we gotta solve b okay uh read and read and okay so let's read and okay and then read in the number um yeah we could do this we could do this this is so easy this is um this is not easy what if I do I'm bullshitting myself right now okay so c i represents the color the house currently painted on okay so I'll just call this c now let's see what are we gonna do what can we do guys what can we do the minimum days he needs to make it the street beautiful for each test case okay so it's what is the color okay so here we could every two so pretend to every two you can make paint them the same color okay uh every two you can paint them the same so these you can make them two it was the number of days one one day you could pick two right you can use different colors to paint the same same house wait in one day you could do the okay okay so it should be three operations the first one three yeah okay um one two three four five six six takes six because you need to make them all to seven or I'll make them all one you try to make them all one okay um here uh let's see we have one three three three two okay so it's better if we find the maximum number of occurrences so that will be the color to make it right so um while we're doing this we should find the maximum number of occurrences uh so let's do um basically find the mode that's what we need to okay and now I'm going to loop through the this map of occurrences to find the mode if mode is equal to max of x okay um we need the number not the max of occurrences we need to um okay so if mode if x is greater than mode what can I do this oh second is greater than mode uh x dot second mode um mode is going to equal to x dot first now that doesn't make any sense okay look uh mode mode um mode occur okay that's the same thing as make them i think this would give us the mode uh sanity check because the mode is going to be the one that we have to color mode is one one two three four five one two three four five no that's not right one two three four five one two three four five oh no it's the maximum number wait yeah yeah use the mode definitely use the mode okay uh one two three mode is one uh yeah that's because one is okay uh here mode is three one two three four five six yeah mode is three okay so we just need to do one and then one two three every three okay um so yeah uh so now we just have to go through the array and go through for every k um okay um basically for every every value that is not the mode we're going to color the mode right um basically every k times we only could do a k time so we need to start over every time so here would be one two two so this would be one operation and this would be one okay so um okay um maybe you could do it mathematically we just need to count how many values are not equal to the mode that contiguous values are not equal to mode that are uh every size of k5 okay so we could just keep looping it once starting from the beginning to the end and then um for everyone that is not a mode we're going to add one and then do that k times I think so okay I think that would work okay so let's um let's start this okay uh so this is the mode okay so we have the mode mode is one two three four five wait no wait one two three yeah that'll work that'll work okay okay um okay so okay loop through it uh if the value in j is equal to i okay um if the value of uh a at j is not equal to the mode um what we're going to do is uh c c c we're going to keep adding by one um c plus plus no j j plus plus and if we have to do this like j to up to k times right uh basically uh uh j is less than i plus k yeah so sorry i i plus k and uh this has to be less than n crap um minimum less than n yeah okay minimum i plus k of n um yeah and then what we're going to do is we're going to increase j plus plus and then um this should be a while loop so every k times um actually this is not a good idea okay but fuck okay we need to count count is equal to zero and j is less than um end okay uh well it's not equal to mode and to the end uh what we're going to do is we're going to do j plus plus but then we also have to do count plus plus um if the count is equal to k count set to zero and then we need to increment the operations so the total operations let's have a variable total op total ops plus plus so that'll be one iteration every time you do a k it's a count you can zero total ops plus plus um at the end we need to set i is equal to j at the end here we need to see out uh total ops so this is uh this is a oh time complexity uh let's actually set the c of j equal to the mode actually sanity check um yeah this should work this algorithm should work dammit okay uh shit okay why is it one shouldn't be one answer should not be one something's not right okay here uh let's look at the first one answer should be three okay three ten two one one one two two one one one two two two one count zero i j what oh yeah it's not equal to mode not equal to mode okay now it is equal to mode okay um we're starting at here two we gotta go twice so make it three count is one two count is not k yet count is now crap uh crap okay um we gotta put this at the end if the count is equal to k then we can count it back to zero okay we gotta do this we really gotta do this uh let's see how many what time is it 45 minutes left okay total ops was two one no one two oh you gotta keep going though crap if the count is not zero at the end we still have to add it though so add two two two two something's not right at here so the first part we were able to get this one this one we have to get one we have to add another one while there's one there's while they're the they're all equal to one they're all equal to one total ops then add one let's try it again this is not a hard problem I should be able to get this it's just hard to implement okay count is zero okay c is um one one okay so these doesn't affect it uh okay so here we're gonna set two to be one j plus plus so i equal to now we're gonna set c of three equal to one j plus plus count now is two so count equal to zero total ops plus plus so that was one operation okay now we are at no okay uh we have to get way until i is seven okay okay so now i is i is six okay make it one j plus plus okay count plus plus uh seven j plus plus count plus plus count should be equal to k uh yeah count is equal to k count should be 0 ops plus plus ah crap okay we have to check if count is still greater than zero then count half to plus plus you might be able to do this mathematically uh okay three six two should be that's what you should give us okay we're getting out of bounds okay um so the first one is three that's right okay let's try seven one seven one c one seven one one two three four five six seven one seven one one two three four five six seven total j plus plus node plus plus j plus plus count equals equal to zero okay count plus plus one j is equal to mode zero total is four two j is mode three four five six j is less than n though what j is less than n wait that actually doesn't make any sense okay let's try again oh it's not evaluating the first part fuck okay I think I got why I got why uh it's not evaluating the first part first we have to swap these c plus plus is being stupid six two three six two I think this is right this should give me the right answer wrong answer and pretest two how what if they're all ones it's a big quote good question two two oh what if the mode is not maybe the mode is not right here let's just try to think of an example where the mode doesn't mode wouldn't work what if the mode is not right fuck the mode is not right I spent too much time on the first question I spent way too long on the first question uh okay what if you had like alternating twos it's like one one one one two oh yeah okay two two two one two two two one two two two one one okay if you use mode oh three two three four five one two one two fuck okay give me give me a scenario when you have the contiguous value is not the mode so two is not the mode so two two two two and then the mode here is um okay three three three three three three three so the mode is four six three okay I got three one two two two three one three the mode is three so if you make this in three it would take one and the k let's say the k operation is three it would take you one two it would take you one one operation two operations three operations but if you don't make k it would be make it two one operation two operations three operations three what's k it's 2 it's k equal one yeah that would be better one operation two operation three operation four operation five six operation it would be six but uh take your second operation but if you make it 3 you one operation two operation three operation four operation five operation fuck that's not right Does the mode always work? What if you have the same mode? I'll take you... You make it 3 I'll take you 1, 2, 3, 4, 5, 6, 7 If it was 2 I'll take you 1, 2, 3, 4, 5 Fudge kicks! What does my thing give me? 9 and let's say K is 1 1, 2, 3, 4, 5, 6, 7, 8, 9 3, 2, 2, 2, 3, 1, 3, 3 It gives me 5 That's only because 2 is smaller What if it was 3? If 2 is in 3, then it's rockin' 2, 2, 3, 3, 2, 3, 2, 1, 2, 2 2, 3, 9, 1, 2, 3, 3, 3, 1, 2, 2 What just happened? 1, 2, 3, 4, 5, 6, 7, 8 1, 2, 3, 4, 5, 6, 7, 8 What? I left the 1 1, 2, 3, 4, 5, 6, 7, 8, 9 2, 3, 3, 3, 3, 2 1, 2, 2, 2, 5 Fudge 1, 9, 1, 2, 3, 3 3, 3, 2, 1, 2, 2 It's appearing to 2 That's because the mode is 2 1, make it 1 This is really difficult I'm not gonna lie, this is actually really fucking difficult 9, 2, 3, 3, 3, 3, 2, 1, 2 This is really difficult 1, 2, make the 3's 1's and make the 2's You want the continuous sum to be I don't think you want it to be the mode I need a better case 2, 1, 2, 1, 3, 3, 3 It's not right Mode is still the best answer Mode is still the best answer So what is my answer? Why is my not right? 1, 5, 6, 7 Let's try this 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 Let's try this 12 1, 1, 2, 1, 2, 1, 3, 3, 3, 3, 1, 1 Answer is 7 Oh, answer is 7 We got something 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 1, 2, 1, 2, 1, 3, 3, 3, 3, 1, 1 Okay So mode is 1 So we ignore these two Okay Now we get to 2 Change it to 1 Count plus plus Count is 0 Takes 1 operation Here This one is 1 So we don't do anything What is J? J is 4 What's the mode? Mode is 1 Why is it still including this? Oh no J is not equal to mode Let's try this again 1, 12, 1, 1, 2, 1, 3, 3, 3, 3, 1, 1 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 Okay Skip We got 3 J is equal to 2, 0, 1, 2 Count Okay, total up plus plus Okay So now this is 1 This one should skip J is 4 1, 2 Oh, here Oh, oh, oh never mind Okay, never mind I got it I understand why they did that I is equal to J Okay, I understand why they did that 2 is 2 No, we're at 6 and 7 3, 5 1, 2 1, 2, 3, 4, 5, 6 Oh, wait 1, 2, 3, 4, 5, 6 Wait, what? Oh, it is 6 1, 2, 3, 4, 5, 6 Crap I didn't find a counter example It is 6 Damn I don't know why this is not working Man, this really sucks This is so difficult This is super difficult Mm-hmm Algorithms K minus D Yeah, I have no idea I don't know why my code is not working What scenario does this not work? That's because the mode is in the beginning and the end What if I have... What if the mode is not in the end? Okay, 1, 2, 3, 4, 5 1, 1, 1, 1, 1, 3, 2, 3, 2, 3, 2, 3 1, 1, 1, 1, 1, 1, 3, 2, 3, 2, 3, 2, 3, 2, 3 Okay, let's try that. What does that give us? Should give us 1, 2, 3, 4 Should give us 4 1, that's right, shit Okay, what if K was 3? Okay, let's try varying the K What if K was 3? Or What if mode is in the middle? Yeah, what if mode is in the middle? 1, 9 1, 2, 3, 4, 5, 6, 7, 8, 9 3, 3 1, 2, 3, 4, 5, 3, 3 It's still 4, damn That's not good Oh, shit Okay, okay, let K equal to 2 Answer should be 2 3, 3 1, 3, 3 Yeah, that's right, shit Okay, let's try again 1, 9 2, 1, 2, 3, 4, 5 3, 3, 3, 3 It is 2, shit Okay, what if it was 4? What if K is 5? Wait, can K be 5? Hold up Can your K be greater than It could be, actually It's gonna be 0 or no But if your K was What if you had 1, 9 Okay, 10 11, okay Let's try 5 K is 3 And you have 1, 2, 1, 2, 1 Okay, how would it be? 2, 1, 2 That's right, shit, that's right Fuck 1, 2, 2, 2, 1 1, 2, 2, 2, 2, 1 Let's see that 2 1, 1, 1, 2 Oh, shit Oh no, that's right Fuck, how are we gonna get something that's No, wait Oh no, wait Interest 2, 1, operation Wouldn't it be better if we use 1 operation? Oh, I just found a counter example I think I just found a counter example Okay Don't use a mode Use a maximum contiguous value Or you could use Find the maximum contiguous value Use the maximum contiguous and Use the mode Because if you use the maximum contiguous value Change it to 2s Right, if you change it to 2s instead You could just use 1 operation To make this Because either the mode is 1 Or take it 3 That's the contiguous value Use the maximum contiguous value How much time do we have left? Jesus Christ, there's no way I could figure this out But I think using Maximum contiguous value would actually work The best It's like 3, 3, 3, 3 Sort it? I like sorting would work Can you? 2, 5, 2s and then 5, 1s Sorting is just gonna get you the same thing You need to find the maximum contiguous value So it's like 2s Graph first You have to paint those first So if it's like 2, 2, 2, 2 Paint those first So the ones with the Contiguous occurrence Do that one first I guess Create like a graph Where each of the ones Represents So this one will represent 2 This one is gonna be 2 is gonna have 2 occurrences And this one, we're gonna have another 2 2 occurrences of it This 2 is gonna have 3 occurrences This one is gonna have 1 So we could do that way Yeah, we could do that way But Then the one with the maximum value Maximum contiguous value Is gonna be the one that You gotta change it first So the 2s Change it first So 3 divided by 2 That would be 3 divided by 3 is 1 Make all these ones I don't know, I can't figure it out This in like 10 minutes Alright Write a comment, subscribe guys I only solved one problem again I took too long on the first problem Hope you guys enjoy this video I'll check you guys later, peace Thanks for watching