Advertisement
rajeshinternshala

Untitled

Oct 12th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. from collections import defaultdict
  2.  
  3. def getChannelRating(views):
  4.     ans = 0
  5.     m = defaultdict(int)
  6.     m[0] = 1
  7.     p = 0
  8.     pre = [0] * len(views)
  9.  
  10.     for i in range(len(views)):
  11.         p ^= views[i]
  12.  
  13.         if i >= 2:
  14.             ans += m[p]
  15.  
  16.             if pre[i - 1] == p:
  17.                 ans -= 1
  18.  
  19.         m[p] += 1
  20.         pre[i] = p
  21.  
  22.     return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement