 What's up guys my name is Michael and welcome to my YouTube channel today. We're doing another league code challenge. It's called array partition. I Array partition one actually given an array of two n integers your task is to group these integers into n pairs of integers say a1 b1 a2 b2 a To a n bn which makes some min a i b i for all i from one to n largest possible okay, so I'm gonna give you guys a few minutes to do this. I haven't done this yet, but I think I know how to do it So please pause the video or do something and then come back to it when you're done But yeah, I'm gonna do it right now So we want to group these integers into n pairs of integers Say a1 b1 b2 a2 b2 and we want to make the sum of minimum a1 a i b i from all i from one to n largest possible Well, what we could do is we could just sort these and then just pair the The first and second one and then the third and fourth one and the fourth and fifth one And that technically would make the sum as large as possible because then you take the If you make the which makes the sum of the minimum a1 a1 if you pair them you sort and pair the two the minimum of A1 and a1 the a minimum of these two would be as large as possible basically So yeah, well, I'll just do that right now. So in n is going to equal to nums.size Divided by two because we want that's the number of pairs we want Right to end make it in. I'm gonna loop from now. I'm gonna sort it sort nums.begin nums.end. Okay, so once I sort these I'm gonna go through my sorted array I'm gonna go Go through n this time and then I'm going to just add the smaller two So I'm actually gonna plus equal to every time because I'm gonna jump from Go through every every two of these see and what I'm gonna do is I'm gonna take the smaller one So I'm gonna add Actually, I'll take the larger one. Yeah, that would make the maximum largest So I'll just do in total plus equal in total equals zero total plus equal Nums at high. Yeah, that should that should technically work Return total submit it wrong answer. Okay. What's the problem? Let's see. What was the wrong answer? It's been put one expected for I I'll put it one. How does that possible? One four three two, so one two three four two plus four Wait a minute I saw what these one two three four How's the output wrong? Okay. Let's see. Let's run the code. Let's see. What's the output? Why the output's wrong? one four three two Okay, so output was one Which doesn't make any sense if I start zero zero zero one plus two I plus equal to two What's the size for? sizes four Okay, I should go through nums dot size All right, that should work now Yeah, let's submit it because I'm gonna I'm still going through original the original ray Let's not to go through the size of the original ray. So yeah That's basically how you would do it You know got accepted you I just sorted them and then I'm gonna assume I'm pairing the first and second and third and fourth and then I'm just gonna add The smaller of the two. Yeah, so like the minimum once a one And then plus the smaller of this Two right first the first pair every time so that's why I'm plus equal to two And I'm sorry if I had zero so zero then three so that makes you four one three. Yeah. Yeah one two three four Yeah, yeah, that's how you do this Ray com subscribe. Let's see what other people did No, yeah, well, so they did exactly what I did. Okay Where's another one what about Java solution Okay, so they did exactly what I did also. Okay, so yeah, that's how you do it ray com subscribe Hope you guys enjoy this video is a really quick one