Microsoft | On-Campus Interview | Starting Index Of Subarray
Anonymous User
1394

First 10 minutes were just questions about resume and previous work experiences. Next 15 minutes were spent on the coding question and the last 5 minutes were left for the questions to the interviewer.
Coding question:
Given two integer arrays, find the first starting point of one array in the second array. Basically, second array is a subarray in the first array and you have to return the index of the starting point of the subarray. If subarray doesn't exist, then return -1.
Example:
Input:
[1,2,4,5,7,8]
[4,5]
Output: 2

Input:
[1,2,2,2,2,2,2,3]
[2,2,2,3]
Output: 4

I was able to do it in O(n* m) time complexity but please feel free to share if you have a better solution.

Comments (6)