Used a similar approach to the solution provided. My solution seems simpler, but it's probably not quite as robust for edge cases if the input dataset was different. Starting to get a better feel for the multi-row formula tool.
Wow! This was a bit difficult.
Here's my solution