Feature #7: Optimize Delivery Cost

Implementing the "Optimize Delivery Cost" feature for our "Amazon" project.

Description

In addition to other important tasks, Amazon’s logistic division is responsible for delivering packages. They have partnered with many delivery services so that the orders can reach customers quickly. One of the carrier companies has pricing criteria; we want to use that criteria to our advantage so that we can deliver maximum packages at minimum cost. This carrier is willing to send one or more trucks for deliveries as needed, but they charge in increments of kk lbs. The vendor has different size truck (in increments of kk lbs) available. Anything below kk lbs costs $10. Whereas, anything between kk and 2k2k lbs costs $20 and so on. If we ship anything less than nkn∗k lbs, where nn is a natural number, we are not fully utilizing the money we’re spending. So, we want to fully utilize the cost.

Your task is to write a program that looks at the current lineup of the packages and determines if we can fully utilize the cost by delivering n number of packages from the lineup; n is greater than or equal to 2. One thing to note is that the packages are arranged so that adjacent packages are to be delivered to near locations. So, we always want adjacent packages to be delivered together. Therefore, the chosen n packages should appear back to back in the lineup.

Consider an example where the weights of the packages are given to you in the form of an array, [11, 42, 54, 44, 49, 26], and the value of k is 10. Now, we need to check if we can efficiently load and utilize the delivery contractor given the packages in the delivery dock. The example should return True because the mentioned condition is satisfied.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.