Advertisement
rajeshinternshala

Untitled

Oct 14th, 2023
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def getChannelRating(views):
  2.     ans = 0
  3.     modd = 10 ** 9 + 7
  4.     m = {}
  5.     m[0] = 1
  6.     p = 0
  7.     pre = [0] * len(views)
  8.  
  9.     for i in range(len(views)):
  10.         p ^= views[i]
  11.  
  12.         if i >= 2:
  13.             ans += m.get(p, 0)
  14.             ans %= modd
  15.  
  16.             if views[i] == 0:
  17.                 ans -= 1
  18.  
  19.             if views[i] == views[i - 1]:
  20.                 ans -= 1
  21.  
  22.             if ans < 0:
  23.                 ans += modd
  24.  
  25.         m[p] = m.get(p, 0) + 1
  26.         pre[i] = p
  27.  
  28.     return ans
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement