ServiceNow Hiring | Maximum Sum of Distinct Subarrays With Length K | on campus online assessment question 2024

ServiceNow · Question · Posted Jun 2026

Problem Statement You are given an integer array nums and an integer k. Find the maximum subarray sum of all the subarrays of nums that meet the following conditions: The length of the subarray is k, and All the elements of the subarray are distinct. Return the maximum subarray sum of all the subarrays that meet the conditions. If no subarray meets the conditions, return 0. A subarray is a contiguous non-empty sequence of elements within an array. Constraints: 1 ...

The full answer & interview discussion are available to premium members.

Log in Create a free account