 Hi guys. So in this video, we're going to be looking at an array problem that involves checking pairs. So it involves looking at each item in an array and comparing it to each other item in that same array. So the example problem that we're going to be using for this video is this method contains duplicates. It takes one parameter and integer array data and we want to return true if the array contains any duplicate values, false otherwise. And we're going to go about comparing each item to each other item through the use of a nested for loop. But let's go ahead and start by writing out some pseudocode for this problem. So okay, we're going to start by iterating through the array. So we'll say look at each item, we'll say we'll call each item X, look at each item X in array or in data I should say for consistency. Starting from index zero up to the second to last index. We're then going to compare each item X to each item Y. So compare each item X to each item Y in data. Starting from now, where are we going to start our second loop from? We're going to start it from the index directly after the current index of our item X in our outer loop. Because we don't need to compare X to itself and we don't need to compare X to any of the items that we've compared it to in previous iterations of the outer loop. If that sounded a bit confusing, it should make more sense when we go ahead and write out the Java below. But okay, so compare each item X to each item Y in data starting at the index directly after item X and ending at the final index. Now, when we compare each X and Y, so if X equals Y, what are we going to do? If X equals Y, then we know that the array does contain at least one duplicate, so we can immediately go ahead and return true. Now, when you look at this, you should be able to notice that this is actually an example of a validation problem. Because what we're doing is we're looking through the array and if we find any item at all that matches our criteria, then we're going to immediately go ahead and return true. We don't need to look through any more items. And then if we get to the end of the array and we haven't found any duplicates, we can go ahead and return false. So, okay, eventually our inner loop will terminate, our outer loop will terminate, so the loop terminates. And at the end, if we have never returned true, we can go ahead and return false because we know that there are no duplicates in our array. Alright, so let's go ahead and try writing this out in Java Blur. So we'll start by writing our outer loop. So we've got four into i equals zero. i is less than, so we're going up to the second to last item. So if i is less than data dot length minus one, i plus plus. And then we'll write out inner loop for int j equals, now j needs to equal the index directly after i. So i plus one, j is less than, and we're going all the way to the end of the array with j. So j is less than data dot length, j plus plus. We're then comparing the item at index i to the item at index j. So if data i equals data j, then what are we going to do? We found a duplicate, so we're going to return true. If we don't return true, the loop's just going to keep going. Eventually we'll get to the end if we have not found any duplicates, and then we can go ahead and return false. Alright, so I've written some tests down here below, so let's go ahead and run this and see if everything passes. And yes, so there you go. So that was just a quick look at how to deal with problems that involve checking pairs. Specifically, generally that's going to involve using a nested for loop such as this one. So I hope you found this helpful. Thanks for watching and have a great day. Bye.