Implement Optimal Bucket Batching | Amazon Interview Question