GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 1 May 2022

Different Subarrays Rearrange CodeChef Solution | CodeChef Problem Solution 2022

You are given an array A of N integers A1,A2,,AN. Determine if there are two permutations B and C of this array, for which the following condition is satisfied:

  • There doesn't exist a pair of integers (i,j) such that 1ijN and (i,j)(1,N), for which the subarray B[i:j] is a permutation of subarray C[i:j].

If there exist such permutations, find any of them.

Solution Click Below:-  CLICK HERE

As a reminder, B[i:j] refers to the subarray [Bi,Bi+1,,Bj]

Input Format

  • The first line of the input contains a single integer T, the number of test cases. The description of the test cases follows.


  • The first line of each test case contains a single integer N — the number of integers.
  • The second line of each test case contains N space-separated integers A1,A2,,AN.

Output Format

For each test case, if there are no such permutations B and C, output NO.

Otherwise, on the first line output YES. In the next line, output N integers B1,B2,,BN. In the next line, output N integers C1,C2,,CN.

You may print each character of YES/NO in either uppercase or lowercase (for example, the strings YESyeSYeS, and yEs will all be treated as identical).

Constraints

  • 1T100
  • 3N1000
  • 0Ai109
  • The sum of N over all test cases doesn't exceed 2000.

Sample Input 1 

3
3
1 1 2
4
19 39 19 84
6
1 2 3 1 2 3

Sample Output 1 

NO
YES
19 19 39 84 
39 84 19 19 
YES
1 1 2 2 3 3 
2 3 3 1 1 2 

Join Now for Solution:- 

No comments:

Post a Comment