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
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…
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
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.
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