Coder Social home page Coder Social logo

koldramke / santas-sleigh-makeover Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 9 KB

Two arrays are given and it must be selected from each array one value which the sum of each other provides closest values of the budget

Java 100.00%
arrays christmas java holders runners

santas-sleigh-makeover's Introduction

Santa's sleigh makeover

This code is part of the "Tech Challenge Series โ€“ Advent Calendar 2021" advanced by Blip.pt (developed by Devskiller).

This year counting down to Christmas will be even funnier and Blip will be by your side the whole time with a variety of small programming puzzles and lots of prizes!

Task description

For this Christmas Santa wants to upgrate his sleigh. He needs to improve both the sleigh runners and his magic bag holder.

There are several models of sleigh runners and magic bag holders which Santa can choose from.
The difference between the prices reflects the quality of the of the equipment.

But Santa is on a budget and he can't choose the best of both or he might need to wait to upgrade next year.

Can you help Santa optimize his purchase?

Function signature
getTotalSpent(int[] runners, int[] holders, int budget) returns int

Examples:
Santa budget b = 100 List of sleigh runners runners = [60, 80, 100]
List of magic bag holders holders = [17, 19, 21]

In this case, Santa should choose 80 runner and 19 holder because 80 + 19 = 99 because it is the closest to his budget.
Choosing the 100 runner would not let him buy a holder.
choose 80 runner and 21 holder would be over budget.
choose 60 runner and 17 holder would not be the best fit because 60 + 17 = 77 and there is leftover money that could be spent on other upgrades.

In the case that the budget isn't enough, it should return -1.

Constraints

  • Items list are between 1 and 1 000
  • Budget is between 1 and 1 000 000
  • The price of each item is in the inclusive range of the budget

santas-sleigh-makeover's People

Contributors

koldramke avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.