ritesh1340

Metro Coding club

Dec 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. t=input()
  2.  
  3. for test_cases in range(t):
  4.     n=input()
  5.  
  6.     s=map(long,raw_input().split())
  7.  
  8.     if len(s)==1:
  9.         if s[0]==0:
  10.             print 1
  11.         else:
  12.             print 2
  13.  
  14.     elif len(s)==2:
  15.         if s[0]==0 and s[1]==0:
  16.             print 1
  17.         else:
  18.             print 2
  19.  
  20.     else:
  21.         count=2
  22.         sign=1
  23.  
  24.         flag=0
  25.         if s[0]!=0:
  26.             flag=1
  27.        
  28.         for i in range(1,len(s)-1):
  29.  
  30.             if s[i]!=0:
  31.                 flag=1
  32.  
  33.             if s[i]==0:
  34.                 if s[i-1]!=0:
  35.                     count+=1
  36.  
  37.             else:
  38.                 if (s[i]-s[i-1])*(s[i+1]-s[i])<0:
  39.                     if (s[i]-s[i-1])<0:
  40.                         count+=1
  41.  
  42.         if s[len(s)-1]!=0:
  43.             flag=1
  44.  
  45.         if flag==1:
  46.             print count
  47.         else:
  48.             print 1
Add Comment
Please, Sign In to add comment