Implement K-means and solve interval/frequency tasks | Amazon Interview Question