You are not logged in. Please login at to post your questions!


MIXCOLOR: Help in test cases

I am solving MIXCOLOR but it is showing WA.. Can you tell me which test cases it is failing?

Here is my implementation: link text

asked 17 Mar '18, 16:21

montycs's gravatar image

accept rate: 0%

edited 19 Mar '18, 13:55

Your code failed for this test case I tried: 1 1 3 5. Your code gives output 3 but the correct output is 1. It fails when a[i] + max becomes greater than a[i+1].


answered 18 Mar '18, 19:52

anshul99's gravatar image

accept rate: 33%

edited 18 Mar '18, 21:25

I changed my code to a[i] == a[i - 1], it passes your test case but still fails many.. please help again ..

(19 Mar '18, 13:46) montycs0★

U need to make changes in a[i-1] not in a[i] and after that u will get write verdict. i have made changes in ur solution and it has passed all the test cases


answered 20 Mar '18, 17:21

gyanendra371's gravatar image

accept rate: 33%

pls up vote

(20 Mar '18, 17:21) gyanendra3713★

otherwise it will fail on all the test cases in which no are reapeated more than twice.

(20 Mar '18, 17:23) gyanendra3713★

Here is my approach, suppose any color has count equal to 1, for example consider the test case -


1 2 3 4 5

In such a case, the number of colors are 5 and each color has a count of 1, there is NO need of mixing and your output should be ZERO. But, suppose if any color has count more than 1, for example consider the test case -


2 2 2

here the number of colors is 3 and only 1 type of color exists which has count=3, here you need minimum 2 mixing operations to make them distinct.. so for each color which has a count > 1, you need (count-1) mixing operations to make it distinct.

You can check my code here


answered 19 Mar '18, 14:06

brijwasi1995's gravatar image

accept rate: 11%

I know you all are doing correct but it can be done more easily:

Take all inputs in set say 'A'

Then print answer = #of inputs - #of elements in set 'A'


answered 20 Mar '18, 17:58

mohit_yadav389's gravatar image

accept rate: 25%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 17 Mar '18, 16:21

question was seen: 275 times

last updated: 20 Mar '18, 17:58