SlideShare uma empresa Scribd logo
1 de 2
Baixar para ler 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

Mais conteúdo relacionado

Destaque (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
 

Semelhante 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
 

Semelhante 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
 

Mais 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

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

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)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
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
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
+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...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
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
 
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
 
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...
 

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