Comment

avatar username

my approach for problem H. RobinHood

I store all the unique elements of the array inside a temporary array (let's call it temp) and start traversing it. Let's say I am currently at an element with value $x$ and frequency $F[x]$, where $F$ is data structure used to store the frequency of elements (I used a map). The logic is as follows

  • If I delete none of the occurrences of $x$, I get $F[x]$ occurrences to keep.
  • If I decide to delete one occurrence of $x$, then I get $F[x]$ + $F[x-1]$ — $1$ elements to keep.
  • similarly if I decided to delete two occurrence of $x$ then I get $F[x]$ + $F[x-1]$ + $F[x-2]$-$2$ to keep.
  • I perform this process $min(freq, x)$ times, taking the maximum among all results.

and i do this for every unique x and at last i take the maximum stored among all the x's and output

size of array — maximum i could get

what is wrong in this? any test case where this fails ? our team got hard stuck on this, thanks in advance.

The actual rating of this user is 1324.

Original comment.

Statistics