-
Notifications
You must be signed in to change notification settings - Fork 1
/
Array_Operations.py
52 lines (36 loc) · 976 Bytes
/
Array_Operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from typing import List
class Solution:
def arrayOperations(self, n : int, arr : List[int]) -> int:
# code here
if arr.count(0)==0 :
return -1
if arr.count(0)==n :
return 0
c=0
for i in range(1,len(arr)):
if arr[i-1]!=0 and arr[i]==0:
c+=1
if arr[-1]>0:
c+=1
return c
#{
# Driver Code Starts
class IntArray:
def __init__(self) -> None:
pass
def Input(self,n):
arr=[int(i) for i in input().strip().split()]#array input
return arr
def Print(self,arr):
for i in arr:
print(i,end=" ")
print()
if __name__=="__main__":
t = int(input())
for _ in range(t):
n = int(input())
arr=IntArray().Input(n)
obj = Solution()
res = obj.arrayOperations(n, arr)
print(res)
# } Driver Code Ends