Asked inSamsung Research,R&D Intern

Chocolates Distribution Problem Statement

Dr. Stephen wants to distribute chocolates fairly among K children. He has N boxes of chocolates arranged in a row, each containing a different number of chocolates. The goal is to distribute the maximum number of chocolates equally among the K children, but only by selecting consecutive boxes of chocolates.

Task:

Given N boxes of chocolates, determine the maximum number of chocolates each child can get when the chocolates must be chosen from consecutive boxes.

Example:

Input:
Boxes: [3, 2, 2, 5, 4, 1], Students: 5
Output:
2
Explanation:

Without the consecutive box constraint, each student could potentially get 3 chocolates. However, considering only consecutive boxes, the optimal selection is boxes [4, 6], where the chocolates sum to 10, allowing each student to receive 2 chocolates.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 10^5
  • 1 <= K <= 10^5
  • 0 <= boxes[i] <= 10^5
  • Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Samsung Research R&D Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter