Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save inoyatov/4b717001421be9717896cbd6acb3e624 to your computer and use it in GitHub Desktop.
Save inoyatov/4b717001421be9717896cbd6acb3e624 to your computer and use it in GitHub Desktop.
#!/bin/python3
# https://www.hackerrank.com/contests/w34/challenges/same-occurrence
import sys
from collections import Counter
def query(x, y, arr):
l = len(arr)
counter = 0
for i in range(l, 0, -1):
for j in range(0, i):
c = Counter(arr[j:i])
if x in c and y in c and c[x] == c[y]:
counter += 1
elif x not in c and y not in c:
counter += 1
return counter
if __name__ == "__main__":
n, q = input().strip().split(' ')
n, q = [int(n), int(q)]
arr = list(map(int, input().strip().split(' ')))
for a0 in range(q):
x, y = input().strip().split(' ')
x, y = [int(x), int(y)]
print(query(x, y, arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment