Meena is working as a security researcher in an organization. He is given a task to create an authentication system. He invented a certain term called genesis array. He defined it as an array of integers in which maximum and minimum coincide. Alongside, he also defined a term, genesis number as the number of genesis subarrays of the original array.
Now, Meena has asked your help to test his system, given an array A of length N, you have to find the genesis number of that array.
Declare to variables counter, ans and current as 0. Traverse the given array. If A_i = current then increment the counter else reset the counter to 0. Assign the current=A_i. Increment the ans counter times in every loop.
from sys import stdin, stdout def outnl(x): stdout.write(str(x) + '\n') def outsl(x): stdout.write(str(x) + ' ') def instr(): return stdin.readline().strip() def inint(): return int(stdin.readline()) def inspsint(): return map(int, stdin.readline().strip().split()) def inlist(): return list(map(int, stdin.readline().strip().split())) for _ in range(int(input())): n=int(input()) a=inlist() ans=0 x=count=0 for i in a: if(i==x): count+=1 else: count=1 x=i ans+=count print(ans)