27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Solutions</strong> to Chapter 6 | Brain Teasers<br />

6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut<br />

off. You are given 31 dominos, <strong>and</strong> a single domino can cover exactly two squares.<br />

Can you use <strong>the</strong> 31 dominos to cover <strong>the</strong> entire board? Prove your answer (by providing<br />

an example, or showing why it’s impossible).<br />

SOLUTION<br />

pg 60<br />

Impossible. Here’s why: The chess board initially has 32 black <strong>and</strong> 32 white squares. By removing<br />

opposite corners (which must be <strong>the</strong> same color), we’re left with 30 of one color <strong>and</strong><br />

32 of <strong>the</strong> o<strong>the</strong>r color. Let’s say, for <strong>the</strong> sake of argument, that we have 30 black <strong>and</strong> 32 white<br />

squares.<br />

When we lay down each domino, we’re taking up one white <strong>and</strong> one black square. Therefore,<br />

31 dominos will take up 31 white squares <strong>and</strong> 31 black squares exactly. On this board, however,<br />

we must have 30 black squares <strong>and</strong> 32 white squares. Hence, it is impossible.<br />

CareerCup.com<br />

1 4 4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!