SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
Google Code Jam Practice Problems

A - Big City Skyline

You've just moved to the Big City so you could start work at the newest Google office, Google BC, and the
one thing that interests you most is the beautiful skyline. You're sitting on a hillside ten miles away, looking
at the big rectangular buildings that make up the city, and you think back to your childhood.

When you were a child, you used to make toy cities out of rectangular blocks. Each building could be made
from multiple blocks, and each block could be part of multiple buildings. Looking at the skyline, you wonder:
what is the biggest possible block that could be part of the Big City's skyline?

Write a program that takes the description of the skyline as an input, and gives the area of the maximum-
area rectangle as output. This program should take less than 4 minutes to run on a 2GHz computer with
512MB of RAM, even for the biggest input size we specify.

Input:

The city is made out of rectangular buildings, all next to each other. The input will consist of an integer N,
the number of buildings, followed by a series of N number pairs wi hi, indicating the width and height of each
building in order from left to right. The buildings' heights will be less than 100,000,000, and their widths will
be less than 1000.

Easy: 0 < N < 1,000
Hard: 0 < N < 10,000,000

Output:
A single number: the area of the largest possible block. (Here’s the beautiful skyline of the Big City.)




Sample Input                          Sample Output                         Explanation
                                      51
5                                                                           The biggest block is shaded black
5 7 1 20 3 5 6 3 2 10                                                       in the figure above.


                                                                          Google Code Jam Practice Problems
                                                                             © Google Inc. - September 2007
                                                                                                        p. 1
B - Universal Search

You've just started your job at Google Moon, and you've been assigned to the universal search
project: that is, of course, the functionality that lets people search for anything in the
universe. Your starter project seems simple: find a flight path for the GCrawler (Galaxy Crawler)
that will gather stock prices from all of the galactic stock exchanges, traveling between planets
using Hyperspace Jumpgates.

The known universe contains k stock exchanges and p inhabited planets. Each planet deals with
one stock exchange, and every planet has a record of the stock prices for its exchange. Given a
list of stock exchanges, their planets, and planet<->planet jumpgate connections, find a path for
the GCrawler that contains the smallest number of jumpgates, but still passes through at least
one planet from each stock exchange before returning home.

Input:

The input will start with p, the number of planets. Next will follow p lines of the form:
planet_name stock_exchange connection1 connection2 ... connectionN

If planet A connects to planet B, then planet B also connects to planet A. Planet and stock
exchange names will contain only alphabetic characters [A-Za-z]. One of the planets will be
named GoogleMoon; that is the start and end location for the GCrawler.
Easy: 0 < p < 50, 0 < k < 5.
Hard: 0 < p < 500, 0 < k < 16.

Output:

A series of planet names, separated by spaces, describing the path the GCrawler should take.

Sample Input
5
GoogleMoon TheInternet Mars Earth
Mars EarthStocks GoogleMoon AlphaCentauriII AlphaCetiV
Earth EarthStocks GoogleMoon
AlphaCentauriII AlphaStocks Mars AlphaCetiV
AlphaCetiV AlphaStocks Mars AlphaCentauriII
Sample Output
GoogleMoon Mars AlphaCetiV Mars GoogleMoon
Explanation
The GCrawler has three stock exchanges to visit: TheInternet,
EarthStocks and AlphaStocks. It starts on GoogleMoon, which
deals with TheInternet; it then travels to Mars, which trades in
EarthStocks, then to AlphaCetiV, which deals in AlphaStocks.
Now it needs to get back home; the shortest route goes
through Mars.




                                                                    Google Code Jam Practice Problems
                                                                       © Google Inc. - September 2007
                                                                                                  p. 2

Más contenido relacionado

Destacado

Code jam japan2011 練習問題A
Code jam japan2011 練習問題ACode jam japan2011 練習問題A
Code jam japan2011 練習問題A
Kenji Koshikawa
 
Issues for people living in squatter settlements in led cs
Issues for people living in squatter settlements in led csIssues for people living in squatter settlements in led cs
Issues for people living in squatter settlements in led cs
tudorgeog
 
What are the issues for people living in squatter settlements in poorer parts...
What are the issues for people living in squatter settlements in poorer parts...What are the issues for people living in squatter settlements in poorer parts...
What are the issues for people living in squatter settlements in poorer parts...
anwonka
 
Urban problems
Urban problemsUrban problems
Urban problems
afifibs
 
Introduction to town planning
Introduction to town planningIntroduction to town planning
Introduction to town planning
ctlachu
 

Destacado (15)

Code jam japan2011 練習問題A
Code jam japan2011 練習問題ACode jam japan2011 練習問題A
Code jam japan2011 練習問題A
 
Layout plan
Layout planLayout plan
Layout plan
 
AP Environmental Science Ch 10. part 2 Grasslands and Parks Miller LITE
AP Environmental Science Ch 10. part 2 Grasslands and Parks Miller LITEAP Environmental Science Ch 10. part 2 Grasslands and Parks Miller LITE
AP Environmental Science Ch 10. part 2 Grasslands and Parks Miller LITE
 
Green public places
Green public placesGreen public places
Green public places
 
City Skyline of India
City Skyline of IndiaCity Skyline of India
City Skyline of India
 
The Skyline Operator
The Skyline OperatorThe Skyline Operator
The Skyline Operator
 
A system for solving spatial forest planning problems
A system for solving spatial forest planning problemsA system for solving spatial forest planning problems
A system for solving spatial forest planning problems
 
The skyline operator lee, woonghee
The skyline operator lee, woongheeThe skyline operator lee, woonghee
The skyline operator lee, woonghee
 
Skyline queries
Skyline queriesSkyline queries
Skyline queries
 
Issues for people living in squatter settlements in led cs
Issues for people living in squatter settlements in led csIssues for people living in squatter settlements in led cs
Issues for people living in squatter settlements in led cs
 
What are the issues for people living in squatter settlements in poorer parts...
What are the issues for people living in squatter settlements in poorer parts...What are the issues for people living in squatter settlements in poorer parts...
What are the issues for people living in squatter settlements in poorer parts...
 
Structural Geology
Structural Geology Structural Geology
Structural Geology
 
Urban problems
Urban problemsUrban problems
Urban problems
 
Introduction to town planning
Introduction to town planningIntroduction to town planning
Introduction to town planning
 
Engineering Geology (Civil Engineering Applications)
Engineering Geology (Civil Engineering Applications)Engineering Geology (Civil Engineering Applications)
Engineering Geology (Civil Engineering Applications)
 

Similar a Google Code Jam Practice

mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
David Galeano
 

Similar a Google Code Jam Practice (20)

Project seminar ppt_steelcasting
Project seminar ppt_steelcastingProject seminar ppt_steelcasting
Project seminar ppt_steelcasting
 
Class[2][29th may] [javascript]
Class[2][29th may] [javascript]Class[2][29th may] [javascript]
Class[2][29th may] [javascript]
 
DiscoGAN
DiscoGANDiscoGAN
DiscoGAN
 
Engineering + Programming portfolio
Engineering + Programming portfolioEngineering + Programming portfolio
Engineering + Programming portfolio
 
Class[6][5th aug] [three js-loaders]
Class[6][5th aug] [three js-loaders]Class[6][5th aug] [three js-loaders]
Class[6][5th aug] [three js-loaders]
 
mago3D: A brand new Geo-BIM platform on top of Cesium & World Wind
mago3D: A brand new Geo-BIM platform on top of Cesium & World Wind mago3D: A brand new Geo-BIM platform on top of Cesium & World Wind
mago3D: A brand new Geo-BIM platform on top of Cesium & World Wind
 
Summer training on matlab
Summer training on matlabSummer training on matlab
Summer training on matlab
 
Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to Vulkan
 
GDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDG Kuwait - Modern android development
GDG Kuwait - Modern android development
 
Introducing google’s mobile nets
Introducing google’s mobile netsIntroducing google’s mobile nets
Introducing google’s mobile nets
 
The Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystemThe Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystem
 
Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Copy of Copy of Untitled presentation (1).pdf
Copy of Copy of Untitled presentation (1).pdfCopy of Copy of Untitled presentation (1).pdf
Copy of Copy of Untitled presentation (1).pdf
 
Scala can do this, too
Scala can do this, tooScala can do this, too
Scala can do this, too
 
Greedy subtourcrossover.arob98
Greedy subtourcrossover.arob98Greedy subtourcrossover.arob98
Greedy subtourcrossover.arob98
 
mloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game developmentmloc.js 2014 - JavaScript and the browser as a platform for game development
mloc.js 2014 - JavaScript and the browser as a platform for game development
 
Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
Minimal Introduction to C++ - Part I
Minimal Introduction to C++ - Part IMinimal Introduction to C++ - Part I
Minimal Introduction to C++ - Part I
 

Más de guestef7fea (20)

Notes
NotesNotes
Notes
 
Blank
BlankBlank
Blank
 
Blank
BlankBlank
Blank
 
Blank
BlankBlank
Blank
 
Notes
NotesNotes
Notes
 
Blank
BlankBlank
Blank
 
Blank
BlankBlank
Blank
 
Blank
BlankBlank
Blank
 
1 How Stupid Can We Get
1 How Stupid Can We Get1 How Stupid Can We Get
1 How Stupid Can We Get
 
1 How Stupid Can We Get
1 How Stupid Can We Get1 How Stupid Can We Get
1 How Stupid Can We Get
 
Public
PublicPublic
Public
 
Private
PrivatePrivate
Private
 
Public
PublicPublic
Public
 
Private
PrivatePrivate
Private
 
Travel Club Training Presentation Final
Travel  Club  Training  Presentation FinalTravel  Club  Training  Presentation Final
Travel Club Training Presentation Final
 
Notes
NotesNotes
Notes
 
Google Code Jam Practice
Google Code Jam PracticeGoogle Code Jam Practice
Google Code Jam Practice
 
Notes
NotesNotes
Notes
 
Notes
NotesNotes
Notes
 
taking time
taking time taking time
taking time
 

Último

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Google Code Jam Practice

  • 1. Google Code Jam Practice Problems A - Big City Skyline You've just moved to the Big City so you could start work at the newest Google office, Google BC, and the one thing that interests you most is the beautiful skyline. You're sitting on a hillside ten miles away, looking at the big rectangular buildings that make up the city, and you think back to your childhood. When you were a child, you used to make toy cities out of rectangular blocks. Each building could be made from multiple blocks, and each block could be part of multiple buildings. Looking at the skyline, you wonder: what is the biggest possible block that could be part of the Big City's skyline? Write a program that takes the description of the skyline as an input, and gives the area of the maximum- area rectangle as output. This program should take less than 4 minutes to run on a 2GHz computer with 512MB of RAM, even for the biggest input size we specify. Input: The city is made out of rectangular buildings, all next to each other. The input will consist of an integer N, the number of buildings, followed by a series of N number pairs wi hi, indicating the width and height of each building in order from left to right. The buildings' heights will be less than 100,000,000, and their widths will be less than 1000. Easy: 0 < N < 1,000 Hard: 0 < N < 10,000,000 Output: A single number: the area of the largest possible block. (Here’s the beautiful skyline of the Big City.) Sample Input Sample Output Explanation 51 5 The biggest block is shaded black 5 7 1 20 3 5 6 3 2 10 in the figure above. Google Code Jam Practice Problems © Google Inc. - September 2007 p. 1
  • 2. B - Universal Search You've just started your job at Google Moon, and you've been assigned to the universal search project: that is, of course, the functionality that lets people search for anything in the universe. Your starter project seems simple: find a flight path for the GCrawler (Galaxy Crawler) that will gather stock prices from all of the galactic stock exchanges, traveling between planets using Hyperspace Jumpgates. The known universe contains k stock exchanges and p inhabited planets. Each planet deals with one stock exchange, and every planet has a record of the stock prices for its exchange. Given a list of stock exchanges, their planets, and planet<->planet jumpgate connections, find a path for the GCrawler that contains the smallest number of jumpgates, but still passes through at least one planet from each stock exchange before returning home. Input: The input will start with p, the number of planets. Next will follow p lines of the form: planet_name stock_exchange connection1 connection2 ... connectionN If planet A connects to planet B, then planet B also connects to planet A. Planet and stock exchange names will contain only alphabetic characters [A-Za-z]. One of the planets will be named GoogleMoon; that is the start and end location for the GCrawler. Easy: 0 < p < 50, 0 < k < 5. Hard: 0 < p < 500, 0 < k < 16. Output: A series of planet names, separated by spaces, describing the path the GCrawler should take. Sample Input 5 GoogleMoon TheInternet Mars Earth Mars EarthStocks GoogleMoon AlphaCentauriII AlphaCetiV Earth EarthStocks GoogleMoon AlphaCentauriII AlphaStocks Mars AlphaCetiV AlphaCetiV AlphaStocks Mars AlphaCentauriII Sample Output GoogleMoon Mars AlphaCetiV Mars GoogleMoon Explanation The GCrawler has three stock exchanges to visit: TheInternet, EarthStocks and AlphaStocks. It starts on GoogleMoon, which deals with TheInternet; it then travels to Mars, which trades in EarthStocks, then to AlphaCetiV, which deals in AlphaStocks. Now it needs to get back home; the shortest route goes through Mars. Google Code Jam Practice Problems © Google Inc. - September 2007 p. 2