Company: Rubrik SE Intern_2nov
Difficulty: medium
Count Stable Signal Segments An audio engineer analyses a digital recording for forensic purposes. The recording arrives as a stream of N non-negative amplitude samples S[1], S[2], ..., S[N] . A signal segment is any contiguous block of samples S[l], S[l+1], ..., S[r] with l <= r . A single sample is itself a segment. For a segment the engineer computes an Integrity Checksum : the bitwise XOR of the two boundary samples , that is C = S[l] XOR S[r] . The segment is called stable when that checksum is not an outlier for the segment — its value must lie inclusively between the smallest and the largest sample of that same segment: min(S[l], S[l+1], ..., S[r]) <= S[l] XOR S[r] <= max(S[l], S[l+1], ..., S[r]) Count the stable segments of the stream. Input Format The first line contains a single integer N , the number of amplitude samples. The second line contains N space-separated non-negative integers S[1] ... S[N] . Output Format Print a single integer — the number of stable signa