1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fill the time slot with the best match

Discussion in 'Computer Science' started by RAS, Oct 8, 2018.

  1. RAS

    RAS Guest

    If I have the following array: pieces = {35,15,20,25,30,10} and the time slot is 80 minutes. How do I do the following:
    1. Fill the time slot with any pieces for the perfect fit. (In our case: 30,35,15 or 15,25,30,10 etc.) 2. Fill the time slot with the best fit possible with deviation: (Let's say our time slot is 103 minutes and the deviation is +/-20 minutes. So, we are looking for the best fit anywhere in the 83-123 minute range.
    3. Is there any optimizations that can be done if pieces array is sorted?

    I'm looking for basic CS algorithms and strategies for optimizing runtime or space. I'm not looking for a specific solution to my problem. Instead, I'm interested in the CS topics I need to look into.

    I'm able to solve the simplest version of this problem: Find out if 2 pieces for the time slot and return true. Solution: Loop through the array. Create hashtable and check if hashtable contains timeslot-pieces if yes, then return true, if no, then add to hashtable.

    Login To add answer/comment

Share This Page