 What's up guys, Mike the Codi here. Today we're gonna go over ambiguous permutations. This is permute two ambiguous permutations. Okay, a permutation is just an ordering of the numbers from one to n. So like here we have one, two, three, four, five, but when n is equal to five, a permutation might look like two, three, four, five, one. And it's basically just an ordering of the numbers from one to five of n, okay? All right, now this is the difference. Now the inverse permutation, right, is now you inverse it. Basically the ith element now becomes the position of the ith integer in the permutation. So in this case we have two, three, four, five, one. Now we have five, one, two, three, four. And why is this the case? Well I'll show you guys why is this the case. So let's sketch a book, okay? Excuse me, ah. I just burped really hard. All right, two, three, four, five, one. Right, this is the thing. Now the ith number is now the ith position. So when we change this, let's look at this. We have, let's pretend we're indexing it from one, two, three, four, five, okay? So what does that mean? Well, now the ith number is now to become the ith position, right? So here in this case we have two, three, four, five, one. So now one's position, I don't know, two's position is gonna be one now. So in our new array, the second position is gonna be one. Okay? All right, here. Now we have three. So now in our new array the third position is gonna be two. So this is one, two, three. Three third position is gonna be two, okay? Now four, the fourth position is gonna be three. So one, two, three, four. All right, the fourth position here is gonna be three. So we put that three. Five, all right, so now five, what is five? Fifth position is gonna have the number four. So in one, two, three, four, five, here's the fifth position, it's gonna have number four. Now here, what is this value? All right, one. Now the first position is gonna have the number five. So now we're gonna have the first position is gonna have number five. So now our new array, inverse, is now gonna equal to five, one, two, three, four. Five, one, two, three, four. All right, and that's where this comes in. Five, one, two, three, four. See? See that's the inverse permutation. So now I showed you guys how to get the inverse permutation. So now an ambiguous permutation is that the inverse is exactly the same thing as the original permutation. So here, two, one, four, three, two is ambiguous because the inverse is the exact same thing. So now all we have to do is write a program that detects if a given permutation is ambiguous or not. So what does that mean? That means that our ambiguous permutation, it means that if we do the inverse, it's gonna equal exactly as our original number, our original array permutation. So that's basically what we have to do, right? So we read a number of test cases, we read an array. Then we're just gonna get the inverse of the array and then we check if it's equal or not. So that's all you have to do. Okay, so how do you get the inverse of the array? It's pretty simple actually. I already showed you guys how to do it. So I'll just tell you the guys the code. It's not hard at all, right? All right, so let's go down here and I'll show you guys the code right here. Okay, so, all right, before we do anything, we gotta read a number of N. N is the number of numbers in our array, okay? That's what we have to do. We have to read an N. They said to close the program when N is equal to zero because I don't know why, but basically end the program if N is equal to zero. So what I did here is I had to do a do while loop and it's not equal to zero. That's just because when N does equal to zero, that happens, but you could do a while loop, it doesn't really matter. But yeah, I read an N and I do, now check if N is equal to zero, then I break. So that ends the program and then it'll just return to zero because it breaks out this loop. Okay, so then how do I do this? Well, I have an array called R and I create it as a vector and I just have the values of, it's gonna have the size of N, okay? Then I have R2 that's equal to vector and it also has size of N. R2 represents the inverse. That's what it represents, an inverse array. Remember, we have to set our inverse array and then we have to create our original array, okay? So how do I read this? Well, what I'm gonna do is I'm gonna read in every single value in the first array, R, right? I gotta read in my original value of our first array. Now I need to set the inverse, now how do I do that? Okay, so because remember, we are indexing by one, right? Originally we're, in the problem statement, we're indexing by one, but our code, remember, arrays are indexed by zero though. So what does that do? Basically, if the ith position is now the ith element, or the ith number is the ith position, right? Here, what you have to do is you have to subtract one from what you just read, from the original number, original array that you just read. And that'll be your position value. And now once you have your position value of your inverse array, you just set that R2, which is our inverse array, at that position value of RI minus one is gonna equal to I plus one, okay? That's gonna equal to I plus one. I plus one represents the new value of the new index that we have. Remember, because we're indexing from zero, we gotta do e to the set of I plus one, right? Because that actually represents it. Otherwise it'll set the value to be, we go back to the sketchbook. Otherwise it'll set the value to be equal to 40123, which is not what we want. That's not what we want, okay? So yeah, that's why we have to do it for I plus one, okay? So that's our current, I remember I's our current index, so that's why we do that. All right, now once we have our original array and we have our inverse array, we need to check if they're equal to the other. So to that, I just do R is equal equal to R2. This actually in C plus plus is actually does check if these elements are equal. So yeah, you don't have to do much else. I know in Java, you have to like write your own equals function, yada, yada, yada. But in C plus plus, you don't have to. So that's a good part about it. I could just use equals equals. So yeah, I just do R is equal equal. If R is equal equal to R2, is R equal equal to the R inverse? And if it is, then I just print out ambiguous because that means that it's ambiguous, right? That means our inverse is equal to the original array. So that's why we have ambiguous. Otherwise I print out not ambiguous, okay? So that's pretty much the gist of this. At the end, it would be just while while n is i equals zero. Yeah, at the end, you just return zero. All right, so that's pretty much the gist of this code. Rate, com, subscribe. I'll check you guys later, peace.