NetApp Full Stack Engineer
Summary
I was interviewed for a Full Stack Engineer position at NetApp and was asked a coding question about finding the maximum sum of a unique subarray.
Full Experience
Round 1
Interview Question – Maximum Sum of Unique Subarray
Given an integer array nums and an integer k, write a function to identify the highest possible sum of a subarray within nums, where:
- The subarray must have exactly
kelements. - All elements in the subarray must be unique.
- If no such subarray exists, return
0.
Example 1
Input:
nums = [3, 2, 2, 3, 4, 6, 7, 7, -1]
k = 4
Output:
20
Explanation:
The valid subarray with the highest sum is:
[3, 4, 6, 7]
Its sum is:
3 + 4 + 6 + 7 = 20
Example 2
Input:
nums = [5, 5, 5, 5, 5]
k = 3
Output:
0
Explanation:
Every subarray of length 3 contains duplicate elements, so no valid subarray exists.
Additional Example
Input:
nums = [3, 2, 1, 2, 4, 6, 7, 7, -1]
k = 4
The solution should consider every contiguous subarray of length 4 and select the one with:
- exactly
4elements - no duplicate elements
- maximum sum
Interview Questions (1)
Maximum Sum of Unique Subarray
Given an integer array nums and an integer k, write a function to identify the highest possible sum of a subarray within nums such that the subarray has exactly k elements, all elements are unique, and if no such subarray exists, return 0. Includes examples and constraints as described in the interview content.