Groupon - Jacob and Peter

11527
Aug 04, 2016

Jacob and Peter have their favorite number X and Y, respectively. We are given an array with positive interger number and we need to find the longest prefix index which contain equal number of X and Y. We return -1 if there is no prefix with equal number of X and Y.

Suppose we have an array A = [7,42,5,6,42,8,7,5,3,6,7]
X = 7
Y =42
Output should be 9 as prefix will be index from 0 to 9 with equal number of X and Y.

Comments (9)