interrupt programming

here, arduino should first detect all the pulses

How is the Arduino supposed to know that there will be no more pulses, so that it knows it has detected ALL of them?

If you can define requirements that do NOT have gaping holes, like "detect all pulses", then you will have a MUCH easier time implementing the requirements in the code.