There are 4 keys and 4 locks. What is the maximum number of times you need to try the locks so as to match all 4 keys to their locks?
6 tries are needed.
If you try 3 keys on the 1st lock, you will know that the 4th key is a match. So, you only need a maximum of 3 tries for the 1st lock.
Similarly, the 2nd lock needs a maximum of 2 tries and the 3rd lock needs only 1 try. Thus, a maximum of 6 (3 + 2 + 1) tries are needed.