Error
|
|
---|---|
@Ibrahim Nash | 5761 |
@blackshadows | 5715 |
@akhayrutdinov | 5111 |
@mb1973 | 4989 |
@Quandray | 4944 |
@saiujwal13083 | 4506 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3516 |
@sushant_a | 3459 |
@verma_ji | 3341 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@aroranayan999 | 1115 |
@bt8816103042 | 739 |
@thealchemist627 | 456 |
@akashkale117 | 453 |
@shivanandp12345678910 | 453 |
@dalwainazism125 | 453 |
@codeantik | 448 |
@SherlockHolmes3 | 447 |
@SHOAIBVIJAPURE | 430 |
@shalinibhataniya1097 | 408 |
@ShamaKhan1 | 392 |
Complete Leaderboard |
Given an array arr[] of size N, the task is to check whether it is possible to obtain an array having distinct neighboring elements by swapping two neighboring array elements.
Example 1:
Input: N = 3, arr[] = {1, 1, 2}
Output: YES
Explanation: Swap 1 (second last element)
and 2 (last element), to obtain 1 2 1,
which has distinct neighbouring elements.
Example 2:
Input: N = 4, arr[] = {7, 7, 7, 7}
Output: NO
Explanation: We can't swap to obtain
distinct elements in neighbor .
Your Task:
You don't need to read input or print anything. You just need to complete the function distinctAdjacentElement() that takes array arr[] and its size N as input parameters and returns a boolean value denoting if distinct neighbours are possible or not.
Note: The generated output is YES or NO according to the returned value.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
2 ≤ N ≤ 106
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes