SlideShare a Scribd company logo
1 of 2
Download to read offline
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

More Related Content

Viewers also liked

PresentacióN
PresentacióNPresentacióN
PresentacióNlakathy07
 
formula
formulaformula
formulaayyoub
 
Kiest u er voor om te delen?
Kiest u er voor om te delen?Kiest u er voor om te delen?
Kiest u er voor om te delen?Pierre Gorissen
 
A Todos Vosotros
A Todos VosotrosA Todos Vosotros
A Todos Vosotrosguestc513e8
 
formula mesura
formula mesuraformula mesura
formula mesuraayyoub
 
Lectie De Viata
Lectie De ViataLectie De Viata
Lectie De Viatavoxvocis
 
Landbruk På Utsira 220906
Landbruk På  Utsira 220906Landbruk På  Utsira 220906
Landbruk På Utsira 220906Atle Grimsby
 

Viewers also liked (9)

PresentacióN
PresentacióNPresentacióN
PresentacióN
 
formula
formulaformula
formula
 
Kiest u er voor om te delen?
Kiest u er voor om te delen?Kiest u er voor om te delen?
Kiest u er voor om te delen?
 
A Todos Vosotros
A Todos VosotrosA Todos Vosotros
A Todos Vosotros
 
formula mesura
formula mesuraformula mesura
formula mesura
 
HiNes IT-seksjon
HiNes IT-seksjonHiNes IT-seksjon
HiNes IT-seksjon
 
Codigo de ética
Codigo de éticaCodigo de ética
Codigo de ética
 
Lectie De Viata
Lectie De ViataLectie De Viata
Lectie De Viata
 
Landbruk På Utsira 220906
Landbruk På  Utsira 220906Landbruk På  Utsira 220906
Landbruk På Utsira 220906
 

Similar to Google Code Jam Practice

Project seminar ppt_steelcasting
Project seminar ppt_steelcastingProject seminar ppt_steelcasting
Project seminar ppt_steelcastingRudra Narayan Paul
 
Class[2][29th may] [javascript]
Class[2][29th may] [javascript]Class[2][29th may] [javascript]
Class[2][29th may] [javascript]Saajid Akram
 
Engineering + Programming portfolio
Engineering + Programming portfolioEngineering + Programming portfolio
Engineering + Programming portfolioJosephDonnelly14
 
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]Saajid Akram
 
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 SANGHEE SHIN
 
Summer training on matlab
Summer training on matlabSummer training on matlab
Summer training on matlabdangerahad
 
Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMark Kilgard
 
GDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDG Kuwait - Modern android development
GDG Kuwait - Modern android developmentGDGKuwaitGoogleDevel
 
Introducing google’s mobile nets
Introducing google’s mobile netsIntroducing google’s mobile nets
Introducing google’s mobile netsLarry Guo
 
The Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSystemThe Kokkos C++ Performance Portability EcoSystem
The Kokkos C++ Performance Portability EcoSysteminside-BigData.com
 
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).pdfjosephdonnelly2024
 
Scala can do this, too
Scala can do this, tooScala can do this, too
Scala can do this, tooHairy Fotr
 
Greedy subtourcrossover.arob98
Greedy subtourcrossover.arob98Greedy subtourcrossover.arob98
Greedy subtourcrossover.arob98Kaal Nath
 
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 developmentDavid Galeano
 
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).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
Minimal Introduction to C++ - Part I
Minimal Introduction to C++ - Part IMinimal Introduction to C++ - Part I
Minimal Introduction to C++ - Part IMichel Alves
 

Similar to 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
 

More from 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
 

Recently uploaded

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 educationjfdjdjcjdnsjd
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
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 FresherRemote DBA Services
 
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...apidays
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
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...Martijn de Jong
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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 Takeoffsammart93
 
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 Processorsdebabhi2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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.pdfsudhanshuwaghmare1
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Recently uploaded (20)

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
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
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
 
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...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
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...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

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