Amazon Robotics interview question

Medium SQL question on groups and CTEs