Store button presses in an array and sequince it with the LEDs
Start by writing a sketch that debounces your buttons to get an accurate count of each button press. Install the Bounce2 Library available in the IDE.
Use a byte array to store the sequence of button presses (record the pin numbers).
Once the pre-set limit (sequence length) is reached, play back the sequence.
Playing back the sequence could look something like this:
const byte ledPin1 = 4;
const byte ledPin2 = 5;
const byte sequenceLength = 4;
byte sequence[sequenceLength] = {4, 5, 5, 4};

void setup(){

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);

  for(byte i = 0; i &lt; sequenceLength; i++){
    if(sequence[i] == ledPin1){
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, LOW);
    }
    else{
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, HIGH);
    }
    delay(500);
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    delay(500);
  }

}

void loop(){}

EDIT: Adding a couple of buttons using the Bounce2 library is a trivial task.
// Arduino IDE 1.8.9
// Sketch uses 1696 bytes (5%) of program storage space.
// Global variables use 30 bytes (1%) of dynamic memory,
#include &lt;Bounce2.h&gt;
const byte ledPin1 = 4;
const byte ledPin2 = 5;
const byte buttonPin1 = 8;
const byte buttonPin2 = 9;
const byte sequenceLength = 4;
byte sequence[sequenceLength];
byte counter = 0;

Bounce button1 = Bounce();
Bounce button2 = Bounce();

void setup(){

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);

  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);

  button1.attach(buttonPin1);
  button1.interval(50);
  button2.attach(buttonPin2);
  button2.interval(50);

}

void loop(){

  if(button1.update()){
    if(button1.read() == 0){
      addToSequence(ledPin1);
    }
  }

  if(button2.update()){
    if(button2.read() == 0){
      addToSequence(ledPin2);
    }
  }

  if(counter == sequenceLength){
    for(byte i = 0; i &lt; sequenceLength; i++){
      if(sequence[i] == ledPin1){
        digitalWrite(ledPin1, HIGH);
        digitalWrite(ledPin2, LOW);
      }
      else{
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, HIGH);
      }
      delay(500);
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      delay(500);
    }
    counter = 0;
  }
}

void addToSequence(byte pinNumber){
  sequence[counter] = pinNumber;
  counter++;
}