you have a password of X digits
keep a list / queue of the last X keys pressed:
- allot x spaces to your array
- each time a key is pressed, add it to the head of the list / queue, bump everything back; what is now the x+1th keystroke is lost (expected), we only need the last-x
- each time a key is pressed, also check each element in the array against your code, in order. you could likely brute-force this with a series of nested if-statements. check the 1st digit, if it’s correct, 2nd, etc, otherwise != (false) will just skip out of the chain
i don’t think you need to be elegant here