Your spec is inconsistant.
- In the first instance you discard 'EVENT1's (bar the last), until you see an 'EVENT2'.
- In the second, you keep the first instance of 'EVENT3', and discard dups until you get an 'EVENT4'.
I can see one rule that might explain that process, but better you explain when to discard or retain an earlier (near)duplicate than have me (us) guess.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.