SlideShare ist ein Scribd-Unternehmen logo
1 von 2
Downloaden Sie, um offline zu lesen
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

Weitere Àhnliche Inhalte

Andere mochten auch

Code jam japan2011 ç·Žçż’ć•éĄŒA
Code jam japan2011 ç·Žçż’ć•éĄŒACode jam japan2011 ç·Žçż’ć•éĄŒA
Code jam japan2011 ç·Žçż’ć•éĄŒA
Kenji Koshikawa
 
Layout plan
Layout planLayout plan
Layout plan
angah2703
 
Skyline queries
Skyline queriesSkyline queries
Skyline queries
Victor Torras
 
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
 

Andere mochten auch (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)
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von guestef7fea

1 How Stupid Can We Get
1 How Stupid Can We Get1 How Stupid Can We Get
1 How Stupid Can We Get
guestef7fea
 
1 How Stupid Can We Get
1 How Stupid Can We Get1 How Stupid Can We Get
1 How Stupid Can We Get
guestef7fea
 
Travel Club Training Presentation Final
Travel  Club  Training  Presentation FinalTravel  Club  Training  Presentation Final
Travel Club Training Presentation Final
guestef7fea
 
Google Code Jam Practice
Google Code Jam PracticeGoogle Code Jam Practice
Google Code Jam Practice
guestef7fea
 
taking time
taking time taking time
taking time
guestef7fea
 

Mehr von 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
 

KĂŒrzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

KĂŒrzlich hochgeladen (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - 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...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 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