Compute join counts and window ranks | Amazon Interview Question