Hi, I was asked this question in Mathworks. I was able to do a naive solution of counter but couldn't come up with an optimized approach. My solution timed out. Can someone help?