# Increasing Decreasing ( Unofficial Editorial , Ltime 85 )

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

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

https://www.codechef.com/viewsolution/34823082

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 ,

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 in VScode

Try second one then maybe i messed up replying you and other guy
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