Groupon - Jacob and Peter
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2016-08-04Added By Anonymous
Source: Link
Company: Groupon
Role: unknown
Interview Stage: unknown
Location: unknown
Year: unknown
Role: unknown
Interview Stage: unknown
Location: unknown
Year: unknown
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.
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.