Increasing Decreasing ( Unofficial Editorial , Ltime 85 )

Question : LINK

Approach -

1 ) when will be answer No ?

case1 : If there is some value which occur greater than 2 times then answer is no
ex : 1 2 2 2 3 , No possible way to arrange right ?

case 2 : If the max value from array present twice , then answer is NO

ex : 1 1 2 2 3 we can rearrange as 1 2 3 2 1 , , but but let arr = 1 1 2 2 3 3 then how can we rearrange ? 1 2 3 3 2 1 As we clearly see two 3 occurs which violates the condition

Else there is always answer so how can we find , so simple ,do yourself :slight_smile:

If any doubt please ask :slight_smile:

My_Solution

https://www.codechef.com/viewsolution/34807451
CAn u find the mistake in this solution , my friend has used similar approach

Hi,
Although i wasn’t able solve the problem, i think that if the max valued element from the array is repeated twice we have to output “NO”, for 1 2 3 3 2 1 we had 3 which was repeated twice. With this approach i don’t think it violates the given terms.
If there is anything wrong please tell me…

Care to look at this ?

3 3 occur two times so how they are strictly increasing or decreasing ?

Uh Yes it does violate the given terms, it should be strictly increasing or strictly decreasing.

U logic seems to be correct, but Your code got spoiled by a little mistake.
In line 22 u wrote a break in an if condition , so it got out of the while loop

So ur further test cases won’t run.
e.g
Try on this one
2
5
2 2 1 12 12
3
2 12 1

1 Like

pls check my solution.I’m getting WA.
https://www.codechef.com/viewsolution/34812229

https://www.codechef.com/viewsolution/34771202
refer this solution

CodeChef: Practical coding for everyone

Tried your i/p and got:
NO
YES
1 12 2

But result was WA.

Yes, it violates the conditions… even i got the WA… was there any test case which has 1 2 2 3 3 as input as 1 2 3 3 2 1 as output?

No ,

Please look into this

Try this test case
1
3
1 3 3
Your code is showing Yes but the ans will be NO
also try this
1
6
1 2 3 6 6 4
and try these type of cases in which max value is repeated.

1 Like

Your code doesn’t give any output in this test case
1
3
1 5 5
and wrong output in these types of test cases
1
6
1 3 5 6 6 4

https://www.codechef.com/viewsolution/34823758
This is my modification wrt to all conditions still gives WA .
Gives correct output to the above cases you have provided

Your code is not giving any output :confused: in VScode

Try second one then maybe i messed up replying you and other guy :confused:
It’s wrong double checked

thanks for the help

I did the same thing stored every frequency in map and simultaneously checking the moment i get frequency of any element greater than 2 my answer was NO and then return. If this doesn’t happen i checked the frequency of max element of input array if it is 2 then also my answer was NO else i inserted all elements with frequency 1 in list 1 all elements with frequency 2 in list 2 then printing YES and then printing list 1 in sorted increasing order and list 2 in sorted decreasing order.

This was my solution but i was getting tle in subtask 2.only got 50pts
My solution was in java
Any help what I was doing wrong