Array Operations: Pure Array An array is called pure if it contains all positive integers (greater than or equal to 1) a

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
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

Post by answerhappygod »

Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 1
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 1 (69.08 KiB) Viewed 45 times
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 2
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 2 (56.93 KiB) Viewed 45 times
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 3
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 3 (45.24 KiB) Viewed 45 times
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 4
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 4 (74.88 KiB) Viewed 45 times
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 5
Array Operations Pure Array An Array Is Called Pure If It Contains All Positive Integers Greater Than Or Equal To 1 A 5 (74.88 KiB) Viewed 45 times
Array Operations: Pure Array An array is called pure if it contains all positive integers (greater than or equal to 1) and reads the same from forward and backward i.e., it is a palindrome. You are given an array with values ranging from 0 to 100000. You need to find if it is possible to convert the array into a pure array by performing the following operation: • If the value of the array is 0, then you can change it to any other value such that it contributes to making the array pure. If the array can be converted into the pure array, then print "YES" and the minimum number of operations required in the next line, else print "NO". Function Description In the provided code snippet, implement the provided pureArray (...) method using the variables to print Yes/No followed by the minimum number of operations required. You can write your code in the space below the phrase "WRITE YOUR LOGIC HERE". There will be multiple test cases running so the Input and Output should match exactly as provided. The base Output variable result is set to a default value of -404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line contains one integer Q denoting the number of queries. Each query contains two lines: The first line contains the number N denoting the length of the array A. The second line contains N non-negative integers denoting the elements of array 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply