google


Google Hash Code 2021 – Practice Problem 1

Even more pizza

Click here for Google Hash Code 2022 Practice Problem

[download id=”5939″]

Online Qualification Round Problem and Input Data Set

[download id=”6058″]

World Finals Problem and Input Data Set

[download id=”10690″]

Introduction

Isn’t it fun to share pizza with friends? But, sometimes you just don’t have enough time to choose what pizza to order. Wouldn’t it be nice if someone else chose for you?

In an imaginary world…

Problem description

Task

Help the imaginary pizzeria choose the pizzas to deliver to Hash Code teams. And since we want everyone to enjoy their food, let’s try to deliver to each team, as many different ingredients as we can.

Pizza

Expecting many hungry customers, the pizzeria has already prepared some pizzas with different ingredients. Each pizza can be delivered to at most one team. There can be multiple pizzas with the exact same set of ingredients.

For example , there are 5 pizzas available in the pizzeria:

Pizza 0: onion, pepper, olive
Pizza 1: mushroom, tomato, basil
Pizza 2: chicken, mushroom, pepper
Pizza 3: tomato, mushroom, basil
Pizza 4: chicken, basil

Note that Pizzas 1 and 3 have the same ingredients, even though they are mentioned in different order.

Teams

Teams of 2, 3, or 4 people all ordered pizzas. Each team ordered one pizza per team member, but did not specify what ingredients to put on the pizzas. The pizzeria might not deliver to a team (no pizzas are sent to that team). However, if the order is delivered, exactly one pizza should be available per person. For example, it is an error to send 3 pizzas to a 4-person team.

Goal

Given the description of the pizzas available, and the number of teams of 2, 3, or 4 people that have ordered, decide which pizzas to send to each of the teams. The goal is to maximize, per team, the number of different ingredients used in all their pizzas.

For example , if we deliver to a 3-person team Pizzas 0, 2 and 3, there will be 7 different ingredients (9 ingredients in total, but pepper and mushroom occur twice):

  • Pizza 0
    • onion
    • pepper
    • olive
  • Pizza 2:
    • chicken
    • mushroom
    • pepper (is already on Pizza 0)
  • Pizza 3:
    • tomato
    • mushroom (is already on Pizza 2)
    • basil

Input data set

The input data is provided as a data set file – a plain text file containing exclusively ASCII characters with lines terminated with a single ‘\n’ character (UNIX- style line endings).

File format

The first line of the input file contains the following integer numbers separated by single spaces:

  • M ( 1 ≤ M ≤ 100,000 ) – the number of pizzas available in the pizzeria
  • T2 ( 0 ≤ T2 ≤ 50,000 ) – the number of 2-person teams
  • T3 ( 0 ≤ T3 ≤ 50,000 ) – the number of 3-person teams
  • T4 ( 0 ≤ T4 ≤ 50,000 ) – the number of 4-person teams

The next M lines describe the pizzas available. Each line contains (space separated):

  • an integer I ( 1 ≤ I ≤ 10,000 ) – the number of ingredients,
  • followed by the list of I ingredients – Each ingredient consists of lowercase ASCII letters and dash (-) characters, and its length can be between 1 and 20 characters in total. Each ingredient in a pizza is different, but the same ingredient can appear on different pizzas.

Example

Input file
5 1 2 1
3 onion pepper olive
3 mushroom tomato basil
3 chicken mushroom pepper
3 tomato mushroom basil
2 chicken basil
Description
5 pizzas, 1 team of two, 2 teams of three, and 1 team of four
Pizza 0 has the given 3 ingredients
Pizza 1 has the given 3 ingredients
Pizza 2 has the given 3 ingredients
Pizza 3 has the given 3 ingredients
Pizza 2 has the given 2 ingredients

Submissions

File format

The first line of the submission file contains a number D ( 1 ≤ D ≤ T2 + T3 + T4 ), representing the number of pizza deliveries.

The following D lines contain descriptions of each delivery. Each line contains the following integer numbers separated by single spaces:

  • L ( 2 ≤ L ≤ 4 ) – the number of people in the team
  • followed by the list of pizzas, P1 … PL – the space separated indexes of the pizzas delivered to that team

Even though it’s nice to deliver pizzas to all teams, it is allowed to make fewer deliveries than the number of teams. However, making more deliveries than the number of teams is an error. It is also an error to make more deliveries to 2, 3 or 4-person teams than the corresponding number
of teams provided in the input file: the number of lines with L=N, should not be greater than TN.

Example

Submission file
2
2 1 4
3 0 2 3
Description
Pizzas are delivered to 2 teams
A 2-person team will receive Pizza 1 and Pizza 4
A 3-person team will receive Pizza 0, Pizza 2 and Pizza 3

Validation

In order for the submission to be accepted:

  • each pizza must be part of at most one order,
  • for all N-person teams, either nobody or everybody receives a pizza,
  • there are TN or less deliveries to teams of N people.

Scoring

For each delivery, the delivery score is the square of the total number of different ingredients of all the pizzas in the delivery. The total score is the sum of the scores for all deliveries.

For example , with the example input file and the example submission file above, there are

  • 4 ingredients delivered to the two-person team (mushroom, tomato, basil, chicken). The score for that team is 42 = 16
  • 7 ingredients delivered to the tree-person team. The score for that team is 72 = 49.
  • (The score is 0 for the two teams that didn’t have their order delivered)

The total score is 16 + 49 = 65 .

Note that there are multiple data sets representing separate instances of the problem. The final score for your team will be the sum of your best scores for the individual data sets.

Past editions

— From https://codingcompetitions.withgoogle.com/hashcode/archive

Hash Code started in 2014 with just 200 participants from France. In 2020, more than 100,000 participants from across Europe, the Middle East and Africa took part in the competition. You can take a look at the problems and winning teams from past editions of Hash Code below.

Past problem statements

Traffic Signaling

Hash Code 2021, Online Qualification Round
[download id=”6058″]
Given the description of a city plan and planned paths for all cars in that city, optimize the schedule of traffic lights to minimize the total amount of time spent in traffic, and help as many cars as possible reach their destination before a given deadline.

Assembling smartphones

Hash Code 2020, Final Round
[download id=”5932″]
In this problem statement, we will explore the idea of operating an automated assembly line for smart phones.
Building a smart phone is a complex process that involves assembling numerous components, including the screen, multiple cameras, microphones, speakers, a processing unit, and a storage unit.
In order to automate the building of a smart phone, we will be using robotic arms that can move around the assembly workspace performing all necessary tasks.

Book scanning

Hash Code 2020, Online Qualification Round
[download id=”5929″]
Books allow us to discover fantasy worlds and better understand the world we live in. They enable us to learn about everything from photography to compilers… and of course a good book is a great way to relax!
Google Books is a project that embraces the value books bring to our daily lives. It aspires to bring the world’s books online and make them accessible to everyone. In the last 15 years, Google Books has collected digital copies of 40 million books in more than 400 languages , partly by scanning books from libraries and publishers all around the world.
In this competition problem, we will explore the challenges of setting up a scanning process for millions of books stored in libraries around the world and having them scanned at a scanning facility.

Compiling Google

Hash Code 2019, Final Round
[download id=”5927″]
Google has a large codebase, containing billions of lines of code across millions of source files. From these source files, many more compiled files are produced, and some compiled files are then used to produce further compiled files, and so on.
Given then huge number of files, compiling them on a single server would take a long time. To speed it up, Google distributes the compilation steps across multiple servers.
In this problem, we will explore how to effectively use multiple compilation servers to optimize compilation time.

Photo slideshow

Hash Code 2019, Online Qualification Round
[download id=”5925″]
As the saying goes, “a picture is worth a thousand words.” We agree – photos are an important part of contemporary digital and cultural life. Approximately 2.5 billion people around the world carry a camera – in the form of a smart phone – in their pocket every day. We tend to make good use of it, too, taking more photos than ever (back in 2017, Google Photos announced it was backing up more than 1.2 billion photos and videos per day).
The rise of digital photography creates an interesting challenge: what should we do with all of these photos? In this competition problem, we will explore the idea of composing a slideshow out of a photo collection.

City Plan

Hash Code 2018, Final Round
[download id=”5921″]
The population of the world is growing and becoming increasingly concentrated in cities. According to the World Bank, global urbanization (the percentage of the world’s population that lives in cities) crossed 50% in 2008 and reached 54% in 2016.
The growth of urban areas creates interesting architectural challenges. How can city planners make efficient use of urban space? How should residential needs be balanced with access to public utilities, such as schools and parks?

Self-driving rides

Hash Code 2018, Online Qualification Round
[download id=”5917″]
Millions of people commute by car every day; for example, to school or to their workplace.
Self-driving vehicles are an exciting development for transportation. They aim to make traveling by car safer and more available while also saving commuters time.
In this competition problem, we’ll be looking at how a fleet of self-driving vehicles can efficiently get commuters to their destinations in a simulated city.

Router placement

Hash Code 2017, Final Round
[download id=”4175″]
Who doesn’t love wireless Internet? Millions of people rely on it for productivity and fun in countless cafes, railway stations and public areas of all sorts. For many institutions, ensuring wireless Internet access is now almost as important a feature of building facilities as the access to water and electricity. Typically, buildings are connected to the Internet using a fiber backbone. In order to provide wireless Internet access, wireless routers are placed around the building and connected using fiber cables to the backbone. The larger and more complex the building, the harder it is to pick router locations and decide how to lay down the connecting cables.

Streaming videos

Hash Code 2017, Online Qualification Round
[download id=”4178″]
Have you ever wondered what happens behind the scenes when you watch a YouTube video? As more and more people watch online videos (and as the size of these videos increases), it is critical that video-serving infrastructure is optimized to handle requests reliably and quickly. This typically involves putting in place cache servers, which store copies of popular videos. When a user request for a particular video arrives, it can be handled by a cache server close to the user, rather than by a remote data center thousands of kilometers away. Given a description of cache servers, network endpoints and videos, along with predicted requests for individual videos, decide which videos to put in which cache server in order to minimize the average waiting time for all requests.

Schedule Satellite Operations

Hash Code 2016, Final Round
[download id=”2596″]A satellite equipped with a high-resolution camera can be an excellent source of geo imagery. While harder to deploy than a plane or a Street View car, a satellite — once launched — provides a continuous stream of fresh data. Terra Bella is a division within Google that deploys and manages high-resolution imaging satellites in order to capture rapidly-updated imagery and analyze them for commercial customers. With a growing constellation of satellites and a constant need for fresh imagery, distributing the work between the satellites is a major challenge. Given a set of imaging satellites and a list of image collections ordered by customers, schedule satellite operations so that the total value of delivered image collections is as high as possible.

Optimize Drone Deliveries

Hash Code 2016, Online Qualification Round
[download id=”2595″]
The Internet has profoundly changed the way we buy things, but the online shopping of today is likely not the end of that change; after each purchase we still need to wait multiple days for physical goods to be carried to our doorstep. Given a fleet of drones, a list of customer orders and availability of the individual products in warehouses, schedule the drone operations so that the orders are completed as soon as possible.

Route Loon Balloons

Hash Code 2015, Final Round
[download id=”2594″]
Project Loon aims to bring universal Internet access using a fleet of high altitude balloons equipped with LTE transmitters. Circulating around the world, Loon balloons deliver Internet access in areas that lack conventional means of Internet connectivity. Given the wind data at different altitudes, plan altitude adjustments for a fleet of balloons to provide Internet coverage to select locations.

Optimize a Data Center

Hash Code 2015, Online Qualification Round
[download id=”2593″]
For over ten years, Google has been building data centers of its own design, deploying thousands of machines in locations around the globe. In each of these of locations, batteries of servers are at work around the clock, running services we use every day, from Google Search and YouTube to the Judge System of Hash Code. Given a schema of a data center and a list of available servers, your task is to optimize the layout of the data center to maximize its availability.

Street View Routing

Hash Code 2014, Final Round
[download id=”2592″]
The Street View imagery available in Google Maps is captured using specialized vehicles called Street View cars. These cars carry multiple cameras capturing pictures as the car moves around a city. Capturing the imagery of a city poses an optimization problem: the fleet of cars is available for a limited amount of time and we want to cover as much of the city streets as possible.


Notes on how to connect from an external machine to a docker database in Google Compute Engine

A) Create a firewall rule in your VPC Network that allows you to connect to your database from outside the network: https://console.cloud.google.com/networking/firewalls/list

B) From your remote machine repair your database using mysqlcheck.

On Fedora you can install it by installing the MariaDB package as follows:

sudo dnf install mariadb -y;

The following command will automatically repair all databases and tables in that instance of MySQL, where of course the user has access:

mysqlcheck --host 45.37.15.225 --port 33061 --user admin --all-databases --auto-repair --password;

C) Edit the new firewall rule and either disable it or delete it for security.


Google Hash Code 2018 – Results of the Hubs we Organized

Online Qualification Round

Position in Merged Ranking Position in Local Ranking Team Hub Score
1 1 Coffee Transistors Greece / NTUA ECE 49196020
2 2 Entropy Sources Greece / NTUA ECE 49051760
3 3 Veni Vidi Vsync Greece / NTUA ECE 46694239
4 1 Happy Trolls Cyprus / Cyprus University of Technology 45615170
5 4 lambdatron Greece / NTUA ECE 41908173
6 5 cuckooHashers Greece / NTUA ECE 41891579
7 2 Halloumium Cyprus / Cyprus University of Technology 41451768
8 1 Cheesy Coders Cyprus / University of Cyprus 39960712
9 6 NTUAwannaCODE Greece / NTUA ECE 39264060
10 2 MIP-MAP Cyprus / University of Cyprus 39013961
11 3 iPemberMen Cyprus / Cyprus University of Technology 37970348
12 4 UndefinedIsNotAFunction Cyprus / Cyprus University of Technology 34840916
13 7 111 Greece / NTUA ECE 33623110
14 8 Bits Plz Greece / NTUA ECE 33048131
15 9 #include<wraio_prama.h> Greece / NTUA ECE 31335747
16 3 #Patates Antinaxtes – XM Cyprus / University of Cyprus 30789367
17 10 Bill^2 Greece / NTUA ECE 30224719
18 11 λambda Greece / NTUA ECE 30209240
19 12 ntua67P Greece / NTUA ECE 18527523
20 13 Milwaukee Bugs Greece / NTUA ECE 14469721
21 14 DeathRow Greece / NTUA ECE 14167166
22 4 Lab_Rats Cyprus / University of Cyprus 12074631
23 15 ReadX Greece / NTUA ECE 11868571
24 16 XM Athens #1 Greece / NTUA ECE 10122968
25 17 Ojama Geeks Greece / NTUA ECE 8480600
26 5 FourCats Cyprus / Cyprus University of Technology 8050139
27 18 Tea Debuggers Greece / NTUA ECE 6646478
28 19 gargaNTUAns Greece / NTUA ECE 1942966
29 20 Rocket 🚀 Greece / NTUA ECE 1767702
30 21 Positive Feedback Greece / NTUA ECE 586021
31 5 PC for ProCrastination Cyprus / University of Cyprus 458402
32 22 I hmmy. U ece? Greece / NTUA ECE 174687
33 6 CodeLovers Cyprus / University of Cyprus 10
34 7 miou-miou Cyprus / University of Cyprus 10
35 23 Googlee Greece / NTUA ECE 10
36 24 Coding freaks Greece / NTUA ECE 10

Practice Problem for Google Hash Code 2018

[2021] Click here for Google Hash Code 2021 – Practice Problem

Happy new year people!!

Google released a practice problem for Google Hash Code 2018!

Please do not forget to register!

[download id=”4172″]

[download id=”4182″]

Submission deadline: Thursday, Mar 1, 19:00 Cyprus time (18:00 CET)

Pizza

Practice Problem for Hash Code

Introduction

Did you know that at any given time, someone is cutting pizza somewhere around the world? The decision about how to cut the pizza sometimes is easy, but sometimes it’s really hard: you want just the right amount of tomatoes and mushrooms on each slice. If only there was a way to solve this problem using technology…

Problem description

Pizza

The pizza is represented as a rectangular, 2-dimensional grid of R rows and C columns. The cells within the grid are referenced using a pair of 0-based coordinates [r, c] , denoting respectively the row and the column of the cell.

Each cell of the pizza contains either:

  • mushroom, represented in the input file as M ; or
  • tomato, represented in the input file as T

Slice

A slice of pizza is a rectangular section of the pizza delimited by two rows and two columns, without holes.
The slices we want to cut out must contain at least L cells of each ingredient (that is, at least L cells of mushroom and at least L cells of tomato) and at most H cells of any kind in total – surprising as it is, there is such a thing as too much pizza in one slice.

The slices being cut out cannot overlap. The slices being cut do not need to cover the entire pizza.

Goal

The goal is to cut correct slices out of the pizza maximizing the total number of cells in all slices.

Input data set

The input data is provided as a data set file – a plain text file containing exclusively ASCII characters with lines terminated with a single \n character at the end of each line (UNIX- style line endings).

File format

The file consists of:

  • one line containing the following natural numbers separated by single spaces:
    • R (1 ≤ R ≤ 1000) is the number of rows,
    • C (1 ≤ C ≤ 1000) is the number of columns,
    • L (1 ≤ L ≤ 1000) is the minimum number of each ingredient cells in a slice,
    • H (1 ≤ H ≤ 1000) is the maximum total number of cells of a slice
  • R lines describing the rows of the pizza (one after another). Each of these lines contains C
    characters describing the ingredients in the cells of the row (one cell after another). Each character is either M (for mushroom) or T (for tomato).

Example Input File

3 5 1 6
TTTTT
TMMMT
TTTTT

3 rows, 5 columns, min 1 ingredient per slice, max 6 cells per slice

Submissions

File format

The file must consist of:

  • one line containing a single natural number S (0 ≤ S ≤ R × C) , representing the total number of slices to be cut,
  • U lines describing the slices. Each of these lines must contain the following natural numbers
    separated by single spaces:

    • r1 , c1 , r2 , c2 (0 ≤ r1, r2 < R, 0 ≤ c1, c2 < C)  describe a slice of pizza delimited by the rows r1 and r2 and the columns c1 and c2 , including the cells of the delimiting rows and columns. The rows ( r1 and r2 ) can be given in any order. The columns ( c1 and c2 ) can be given in any order too.

Example

3
0 0 2 1
0 2 2 2
0 3 2 4

Example description

3 slices.
First slice between rows (0,2) and columns (0,1).
Second slice between rows (0,2) and columns (2,2).
Third slice between rows (0,2) and columns (3,4).

Slices described in the example submission file marked in green, orange and purple.

Validation

For the solution to be accepted:

  • the format of the file must match the description above,
  • each cell of the pizza must be included in at most one slice,
  • each slice must contain at least L cells of mushroom,
  • each slice must contain at least L cells of tomato,
  • total area of each slice must be at most H

Scoring

The submission gets a score equal to the total number of cells in all slices.

Note that there are multiple data sets representing separate instances of the problem. The final
score for your team is the sum of your best scores on the individual data sets.

Scoring example

The example submission file given above cuts the slices of 6, 3 and 6 cells, earning 6 + 3 + 6 = 15 points.

Past editions

— From https://hashcode.withgoogle.com/past_editions.html

Hash Code started in 2014 with just 200 participants from France. In 2017, more than 26,000 participants from across Europe, the Middle East and Africa took part in the competition. You can take a look at the problems and winning teams from past editions of Hash Code below.

Past problem statements

Router placement

Hash Code 2017, Final Round
[download id=”4175″]
Who doesn’t love wireless Internet? Millions of people rely on it for productivity and fun in countless cafes, railway stations and public areas of all sorts. For many institutions, ensuring wireless Internet access is now almost as important a feature of building facilities as the access to water and electricity. Typically, buildings are connected to the Internet using a fiber backbone. In order to provide wireless Internet access, wireless routers are placed around the building and connected using fiber cables to the backbone. The larger and more complex the building, the harder it is to pick router locations and decide how to lay down the connecting cables.

Streaming videos

Hash Code 2017, Online Qualification Round
[download id=”4178″]
Have you ever wondered what happens behind the scenes when you watch a YouTube video? As more and more people watch online videos (and as the size of these videos increases), it is critical that video-serving infrastructure is optimized to handle requests reliably and quickly. This typically involves putting in place cache servers, which store copies of popular videos. When a user request for a particular video arrives, it can be handled by a cache server close to the user, rather than by a remote data center thousands of kilometers away. Given a description of cache servers, network endpoints and videos, along with predicted requests for individual videos, decide which videos to put in which cache server in order to minimize the average waiting time for all requests.

Schedule Satellite Operations

Hash Code 2016, Final Round
[download id=”2596″]
A satellite equipped with a high-resolution camera can be an excellent source of geo imagery. While harder to deploy than a plane or a Street View car, a satellite — once launched — provides a continuous stream of fresh data. Terra Bella is a division within Google that deploys and manages high-resolution imaging satellites in order to capture rapidly-updated imagery and analyze them for commercial customers. With a growing constellation of satellites and a constant need for fresh imagery, distributing the work between the satellites is a major challenge. Given a set of imaging satellites and a list of image collections ordered by customers, schedule satellite operations so that the total value of delivered image collections is as high as possible.

Optimize Drone Deliveries

Hash Code 2016, Online Qualification Round
[download id=”2595″]
The Internet has profoundly changed the way we buy things, but the online shopping of today is likely not the end of that change; after each purchase we still need to wait multiple days for physical goods to be carried to our doorstep. Given a fleet of drones, a list of customer orders and availability of the individual products in warehouses, schedule the drone operations so that the orders are completed as soon as possible.

Route Loon Balloons

Hash Code 2015, Final Round
[download id=”2594″]
Project Loon aims to bring universal Internet access using a fleet of high altitude balloons equipped with LTE transmitters. Circulating around the world, Loon balloons deliver Internet access in areas that lack conventional means of Internet connectivity. Given the wind data at different altitudes, plan altitude adjustments for a fleet of balloons to provide Internet coverage to select locations.

Optimize a Data Center

Hash Code 2015, Online Qualification Round
[download id=”2593″]
For over ten years, Google has been building data centers of its own design, deploying thousands of machines in locations around the globe. In each of these of locations, batteries of servers are at work around the clock, running services we use every day, from Google Search and YouTube to the Judge System of Hash Code. Given a schema of a data center and a list of available servers, your task is to optimize the layout of the data center to maximize its availability.

Street View Routing

Hash Code 2014, Final Round
[download id=”2592″]
The Street View imagery available in Google Maps is captured using specialized vehicles called Street View cars. These cars carry multiple cameras capturing pictures as the car moves around a city. Capturing the imagery of a city poses an optimization problem: the fleet of cars is available for a limited amount of time and we want to cover as much of the city streets as possible.

[2021] Click here for Google Hash Code 2021 – Practice Problem