Giter Site home page Giter Site logo

sagishporer / hashcode-practice-even-more-pizza Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 9.0 362 KB

Google Hash Code 2021 practice problem: "Even More Pizza". Score: 731,455,475

License: Apache License 2.0

C# 100.00%
hashcode hashcode-2021 google-hashcode google-hashcode-2021 hash-code hash-code-2021 google-hash-code-2021 hashcode-practice hash-code-practice hash-code-2021-practice

hashcode-practice-even-more-pizza's Introduction

Google Hash Code 2021 practice problem solution: Even More Pizza

Problem statement

Algorithm description:

  • Phase 1: Build a solution
  • Phase 2: Optimizations

Phase 1 - Build a solution

  1. Sort pizzas by number of ingredients.
  2. Build deliveries, first teams of 4, after that 3, after that 2:
    2.1 Select the pizza with the most ingredients.
    2.2 Select the pizza that will give the best improvement in delivery (most new ingredients, with the least overlapping ingredients).
    2.3 Repeat 2.2 until the delivery is ready.

Phase 2 - Optimization

  1. Try to swap 2 pizzas between any 2 deliveries - if it improves the score, make the swap.
  2. Try to swap 1 pizza between any 2 deliveries - if it improves the score, make the swap.
  3. Try to swap a pizza from any delivery with unused pizza - if it improves the score, make the swap.
  4. Try to move 1 pizza between 2 deliveries (# of pizza in the 2 deliveries must be -+1) - if it improves the score, make the swap.
  5. If any improvement performed in 1-4 - go to 1

Notes

  1. Phase 1 takes about 5 seconds to run.
  2. Phase 2 takes about 50 minutes to run with the current restrictions (implemented for D & E which are huge). About 1% score improvement.

Scores

Input Phase 1 Phase 1 + 2
A – Example 74 74
B – A little bit of everything 12,922 13,533
C – Many ingredients 706,624,572 712,692,751
D – Many pizzas 7,863,102 7,911,296
E – Many teams 10,789,627 10,837,821
Total 725,290,297 731,455,475

hashcode-practice-even-more-pizza's People

Contributors

sagishporer avatar waqarsaleem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.