Java: Fitting Shelves Problem

Level : Advanced
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:40:00

Lab Details

Problem Statement:

Given length of wall w and shelves of two lengths m and n, find the number of each type of shelf

to be used and the remaining empty space in the optimal solution so that the empty space is

minimum. The larger of the two shelves is cheaper so it is preferred. However cost is secondary

and first priority is to minimize empty space on wall.

Example

Input:

w = 24 m = 3 n = 5

Output:

3 3 0
We use three units of both shelves
and 0 space is left.
3 * 3 + 3 * 5 = 24
So empty space = 24 - 24 = 0
Another solution could have been 8 0 0
but since the larger shelf of length 5
is cheaper the former will be the answer.
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this