30 Day Risk-Free Guarantee:
100% money back if you're unsatisfied.
Book (308 Pages):
  • 150 Programming Interview Questions and Solutions
  • Five Proven Approaches to Solving Tough Algorithm Questions
  • Ten Mistakes Candidates Make -- And How to Avoid Them
  • Steps to Prepare for Behavioral and Technical Questions
  • Interview War Stories: A View from the Interviewer's Side
  • Book Preview and More Info

Video (One Hour):
  • Watch CareerCup's founder perform a totally unscripted technical interview of a candidate.
  • Overview of what interviewers look for in software engineering jobs.
  • Technical questions with white-boarding coding where the candidate does well - and struggles.
  • Interviewer reviews with what went well and poorly.
  • Video Preview and More Info

Resume Review (24 - 48hr)
  • Get your resume reviewed by a trained engineering interviewer. More Info
All Products / Services


Express Prep Package (Book)
$29.99 for e-book | $32.45 for paperback
Buy E-Book Buy on Amazon


Standard Prep Package (E-Book & Video)
Emailed Instantly | $39.99
Buy Standard

Elite Prep Package (E-Book, Video & Resume)
Emailed Instantly | $99.99
Buy Elite
 



There is a blank disc( like a CD). You are given two colors of paint (black and white) . A sensor can recognize the color painted on the disc and produce an output. Paint the disc in a way such that you can find the direction of rotation by looking at the output.

17


Toxic on August 27, 2007 |Edit | Edit

paint like BWBWWBWWWB ......

how to generate two or more W ???
Sol : After painting by W leave some space without paint. Again paint with W.

Kiran on September 13, 2007 |Edit | Edit

I think this solution is correct.

Is there any other solution?

VP on August 27, 2007 |Edit | Edit

Consider 8 sectors on the disk. Paint 4 consecutive sectors with one paint, say White. Then paint one adjacent sector with Black paint. Then the next adjacent sector to this one with White paint and the remaining two sectors with Black paint.

So the disk now looks like ....W W W W B W B B... in a circular fashion.

Once you can see a sequence having 4 consecutive whites, you can tell which direction the disk is spinning.

After 4 whites, if you get one black and then one white, it is spinning in the clockwise direction.

After 4 whites, if you get 2 blacks and one white, it is spinning in the anti-clockwise direction.

Anonymous on August 27, 2007 |Edit | Edit

Oops ! I have correction in the last two lines in my answer:
So the disk now looks like ....W W W W B W B B... in a circular clockwise fashion.

I meant After 4 whites, if you get one black and then one white, it is spinning in the ANTI-clockwise direction.

After 4 whites, if you get 2 blacks and one white, it is spinning in the Clockwise direction.

ck on September 06, 2007 |Edit | Edit

I dont know but I assume to color an arrow like structure having a tail and a head. Color the head ">" in black and tail ">" in white. Now while the CD is revolving, if the tail follows head its Clockwise and if Head follows Tail its anti-clockwise.

ck on September 06, 2007 |Edit | Edit

changing the icons like Head will be like a tilted triangle and tail like an greater than sign ">"

vikas on September 08, 2007 |Edit | Edit

hi ck
m sorry .... i think your answer is not correct because how would a sensor come to know whether color sign is > or <. sensor would give just give output same in both the cases.
VP's answer would work definitely.

mathena on September 10, 2007 |Edit | Edit

I've verified that WWBBBWBW is one of the correct answer.
If we use binary, the equivalent question is:
" find an eight digital binary string where the circular left shift and the circular left shift for the inverse string are different."

This brings me to think:
" Is there an invariant while doing the left shifting? (no matter how we do circular left shift on this string, we can apply some logical operation to that binary string and get an invariant) while inverting that string changes this invariant? "

ram on October 08, 2007 |Edit | Edit

I have another idea to add

you can have painting pattern like this.
B W B&W
the last one is the mix of black and white.Even if the sensor cant sense that color,the direction can be found.
If clock wise B W _ B W _
if anti clock wise W B _ W B _
Is this ok?

Jack on December 13, 2007 |Edit | Edit

Assign uniques codes to clockwise and counter-clockwise. Whichever one appears will indicate direction of spin.

This problem is analogous to finding Endianess.

Anonymous on March 12, 2008 |Edit | Edit

I got this question in cisco....

paint with white and black each color is painted only once...

say u split the cd into 8 sectors.... pain the first sector white and second sector black...
if it is rotating clockwise... u will see the white first and then black... if it is anticlockwise... u will see black with an interval of 6 sectors and then u will see white...
I know i have not explained my solution clearly.. but i guess u guys are intelligent enough to understand.

Anonymous on April 13, 2008 |Edit | Edit

may be we can have a sequence like bwbwwbwwwbwwwwbwwwww.......
so if see W's increasing then we can have it as one direction
and if we see them decreasing then another direction

Anonymous on April 28, 2008 |Edit | Edit

IMHO VPs answer is the best one and simple to understand as well...thanx vp..

Anonymous on May 28, 2008 |Edit | Edit

One possible solution can be WBBWWWB with the most optimised approach.
Please validate, if posible...

Cheers!!

jobseeker on November 01, 2008 |Edit | Edit

Blanks are unnecessary. I found that the easiest way is to paint it as BWBWWB.
If the sensor detect BWWBWB or BWBBWW, the CD runs the opposite direction.

jobgiver on July 17, 2009 |Edit | Edit

i think this is the simplest solution...

fromAmazon on July 17, 2009 |Edit | Edit

hey you two guys rock buddy...awesome answers..
jobseeker and jobgiver, both of you are selected for the position of SE@Amazon,NY...just mail me your bio : katherine.ny@amazone.com

Add a Text Comment | Add Runnable Code
Name:
Comment:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.








Amazon (1033)Bloomberg LP (403)Qualcomm (117)Adobe (88)Goldman Sachs (78)NetApp (49)IBM (43)Morgan Stanley (33)CapitalIQ (30)Sophos (25)Achieve Internet (23)Electronic Arts (19)Motorola (18)Research In Motion (17)Flipkart (16)
Microsoft (867)Google (141)NVIDIA (98)Yahoo (82)Epic Systems (69)Expedia (47)VMWare Inc (43)Apple (32)Cisco Systems (28)Facebook (23)Infosys (22)Agilent Technologies (19)Sage Software (17)Deshaw Inc (16)FlexTrade (15)
More Companies »
Software Engineer / Dev... (1062)Financial Software Deve... (170)Testing / Quality Assur... (56)Analyst (35)Virus Researcher (25)Field Sales (15)Developer Program Engin... (9)Front-end Software Engi... (6)MyJoB (5)area sales manager (4)Assistant (3)Cabin crew (2)Accountant (1)personnel (1)Intern (1)
Software Engineer in Te... (288)Program Manager (65)Development Support Eng... (47)INTERN(MSIDC) (28)Web Developer (18)System Administrator (10)Consultant (10)Production Engineer (5)Associate Technology L2 (5)AcquireKnowledge (4)Product Security Engine... (3)Solutions Architect (2)Gamer (1)mts (1)Fresh graduate interview (0)
More Job Titles »
Algorithm (1073)Terminology & Trivia (294)C (166)Object Oriented Design (159)Java (121)Testing (114)Arrays (101)Operating System (78)Database (70)Linked List (62)String Manipulation (56)Networking / Web / Inte... (44)Threads (36)Linux Kernel (33)PHP (22)
Coding (511)C++ (204)Behavioral (159)Data Structures (155)Experience (116)Brain Teasers (111)Computer Architecture &... (79)General Questions and C... (73)Trees and Graphs (69)Math & Computation (57)Application / UI Design (45)Ideas (38)System Design (35)Puzzles (30)Bit Manipulation (20)
More Topics »
CareerCup Official Interview Book Daily Questions Requests for Help Mock Interviews Video for Cracking the Coding Interview Job Placement Service CareerCup Blog
My Profile Edit Profile & Email Settings Sign Out