Array Operations: Pure Array An array is called pure if it contains all positive integers (greater than or equal to 1) a
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Array Operations: Pure Array An array is called pure if it contains all positive integers (greater than or equal to 1) a
Sample Input 2 number of query Q 7 -- size of array N 5400 32 05 - array A elements 6 042307 Constraints 1 <= Q<= 100 1 <= N <= 200. 0<= A₁ <= 100000 Output Format For each query, if a pure array can be made from the given array, then print two lines. The first containing string "YES" and the second line containing the required minimum operations to convert, Otherwise, print only a single line containing the string "NO". Sample Output YES 3 NO Explanation We are only allowed to change those array elements which have value 0, so we will check if after putting appropriate values at these positions, the array becomes pure (i.e. contains only positive integers and read the same from forward and backward) or not. For query 1: We see that we can change the last 0 to 4, First 0 to 32, and middle 0 to a positive integer. Thus, it is possible to convert and the minimum operations required are Sliding
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 TL 78 18 19 20 21 ~~~ 45 222 m m m m m 22 23 N = [] def pureArray (Q,N, A): # this is default OUTPUT. You can change it. result = "" cou = 0 WNHO #write your Logic here: for i in range (Q): 24 A = [] 31 32 for j in N: if A[j] == 0: cou += 1 X = "YES" + cou else: result = x + u U = "NO" return result 25 for i in range (Q): a = [] 26 27 28 29 30 # INPUT [uncomment & modify if required] Q = int(input()) N.append(int (input())) temp = input().split() for j in range (N): a.append(temp [j]) A.append(a) 33 # OUTPUT [uncomment & modify if required] 34 print (pureArray (Q,N, A)) Output Test against ountam
1 <= N<= 0<= A₁ <= 100000 Output Format For each query, if a pure array can be made from the given array, then print two lines. The first containing string "YES" and the second line containing the required minimum operations to convert. Otherwise, print only a single line containing the string "NO". - Sample Output YES 3 NO Explanation We are only allowed to change those array elements which have value 0, so we will check if after putting appropriate values at these positions, the array becomes pure (i.e. contains only positive integers and read the same from forward and backward) or not. For query 1: We see that we can change the last 0 to 4, First 0 to 32, and middle 0 to a positive integer. Thus, it is possible to convert and the minimum operations required are the number of zeros in the array i.e. 3. Hence the output is "YES" and 3. For query 2: Here, we see that the third element from start and end are already positive integers and not equal. So, it is obvious that we can't make this array pure. Hence the output is "NO". 9 10 11 12 13 14 15 16 17 ~33333 18 19 20 21 22 23. 24 25 26 27 28 29 30 لا لا لا لا لا 31 32 WN 5 6 33 789 34 Outpu