Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

A person makes a circular cake and want to put cherries on it so that adjacent cherries dont have same colour.He has unlimited supply of cherries of K ≤ 10 different colors.Each color is denoted by the digit from the set {0, 1, ..., K – 1}. Different colors are denoted by different digits. Some of the cherries are already placed and the he wants you to place cherries in the remaining positions. He understands that there can be many such arrangements, so in the case when the answer is not unique he asks you to find the lexicographically smallest one.

  • The cherries at the first and the last positions are adjacent to each other.
  • In the case N = 1 any arrangement is valid as long as the color used for the only cherry of this arrangement is less than K.
  • Initial arrangement can be already invalid

eg: k=2 and string for cherrie ?0 ans is 10

k=4 and string for cherrie ????? ans is 01012

i have written the code http://ideone.com/RvcVl but missing some tricky case

share|improve this question
I believe this should be on stackoverflow –  Belgi Jun 7 '12 at 17:19
Um, what was the question? (Both: (a) what particular information about cherry distribution are you trying to find? You have described a situation and some restrictions, but not an actual question about the situation that one can answer. And : (b) what is the question you want us to answer?) –  Henning Makholm Jun 7 '12 at 18:19
@HenningMakholm a)for given k(the number colours of cherrie available) and string for cherries we have to fill the gap left eg: k=2 string for cherrie ??1? ans is 1010 b)actually i have written the code but its not getting accepted,i think there is some case i am missing. –  user1380904 Jun 7 '12 at 18:33
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.