Microsoft | Phone | SDE 2 | Subsequence Max Product
Anonymous User
748

1 hour scheduled call with senior dev on a team (MS Teams call, no video). Couple minutes of introductions, then straight to the Codility problem

  • Given a large number of upto 100 digits, the objective is to find the subsequence of n digits with max product

ex: num = 145623 , n = 3
answer would be 120, the product of 4 x 5 x 6

I quickly came up with a O(n2) solution like this:


for(int i = 0; i < nums.Length - 1; i++) {
	int product = nums[i];
	for(int k = 1; k < n; k++) {
		product = product * nums[k];
	}
}

This solution passed test cases, but then the interviewer pushed me to find a solution with faster time complexity. I mentioned that a sliding window could be used here instead, but through my anxiety it took me longer than expected to type out a sliding window solution. Eventually got it all working, but had lots of issues with zeroes in the num string.

Comments (3)