fullscreen
timer
qrcode
plickers
selector
edit
reset

Greedy Algorithms (4)

COS 320 - Algorithm Design

Greedy Algorithms (4)

Google's Foo.bar challenge

Group: Google's Foo.bar challenge

A "secret" web tool that Google uses to recruit developers.

Group: Google's Foo.bar challenge

Quantum antimatter fuel comes in small pellets, which is convenient since 
the many moving parts of the LAMBCHOP each need to be fed fuel one pellet 
at a time.  However, minions dump pellets in bulk into the fuel intake.  
You need to figure out the most efficient way to sort and shift the
pellets down to a single pellet at a time.

The fuel control mechanisms have 3 operations:
 -  Add 1 fuel pellet
 -  Remove 1 fuel pellet
 -  Divide the entire group of fuel pellets by 2 (due to the destructive
    energy released when a quantum antimatter pellet is cut in half, the 
    safety controls will only allow this to happen if there is an even
    number of pellets)

Write a function called answer(n) which takes a positive integer n as a
string and returns the minimum number of operations needed to transform
the number of pellets to 1.
×