InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Subarray with equal occurences!


Problem Description

Given an integer array A and two integers B and C.

You need to find the number of subarrays in which the number of occurrences of B is equal to number of occurrences of C.

NOTE: Don't count empty subarrays.



Problem Constraints

1 <= |A| <= 104

1 <= A[i], B, C <= 108

B != C



Input Format

First argument is an integer array A.

Second argument is an integer B.

Third argument is an integer C.



Output Format

Return an integer denoting the number of subarrays in which the number of occurrences of B is equal to number of occurrences of C.



Example Input

Input 1:

 A = [1, 2, 1]
 B = 1
 C = 2

Input 2:

 A = {1, 2, 1}
 B = 4
 C = 6



Example Output

Output 1:

 2

Output 2:

 6



Example Explanation

Explanation 1:

 The possible sub-arrays have same equal number of occurrences of B and C are:
    1) {1, 2}, B and C have same occurrence(1).
    2) {2, 1}, B and C have same occurrence(1).

Explanation 2:

 The possible sub-arrays have same equal number of occurrences of B and C are:
    1) {1}, B and C have same occurrence(0).
    2) {2}, B and C have same occurrence(0).
    3) {1}, B and C have same occurrence(0).
    4) {1, 2}, B and C have same occurrence(0).
    5) {2, 1}, B and C have same occurrence(0).
    6) {1, 2, 1}, B and C have same occurrence(0).



NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Subarray with equal occurences! on Interview Code Editor
Sign Up
to access hints and editorial solutions for Subarray with equal occurences!

Discussion


Loading...
Click here to start solving coding interview questions