# Robo challange

You have got a baby Robo who wants to play with you. He gives you a challenge.

He has with him a number of coins placed horizontally from left to right. Some coins are placed with Head side up and some with Tail side up. The Robo takes one integer input at a time. For the given integer it flips the coins places at positions which is a multiple of the that integer.

The coins are assigned position as follows:

• Leftmost coins is assigned position 1.

• Coin placed next to leftmost coin is assigned position 2 and so on.

For example, if list of coins placed represented from left to right is 'HTHHHHHHHTTT' that means:

• First coin is placed with Heads up.

• Second coin with Tails up.

• Third coin with Heads up and so on...

Then if Robo is given input 4. The Robo will be flipping coins placed at 4th, 8th and 12th positions. The resulting position of coins would be 'HTHTHHHTHHTH'.

Your task is to find length of shortest sequence of integers you need to input through Robo to make him flip all coins to Tail side.

The initial arrangement of coins is:

'HTTHHTTHTHHTTHHTTTHTHHHHHTHHHTTHHHTTHTHHHTHTTHHHTTTHHHHHTTTHHHHHHTHHHTHHTTHTHTHTHTTTHHHHHHHTHHHHHHHT'

For example if initially the coins placed are as: "HHTHHT". The length of shortest sequence is 2 and the sequence could be [3, 1] or [1, 3]. Giving it 3 would make it: 'HHHHHH' and 1 would make it: "TTTTTT".

×

Problem Loading...

Note Loading...

Set Loading...