FastPrepMaximum Sum of a Unique-Element Subarray
Problems/Maximum Sum of a Unique-Element Subarray

Maximum Sum of a Unique-Element Subarray

Tekion logoTekion● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Tekion onsite interview. The source gives the goal and the rule that inputs are non-negative. It does not give the exact function signature, examples, or number limits. Our version is about 95% the same as the reported question.

Given a non-empty integer array nums containing only non-negative values, return the maximum sum of a contiguous subarray whose elements are all distinct.

Function

maximumUniqueSubarraySum(nums: int[]) → int

Examples

Example 1

nums = [4,2,4,5,6]return = 17

The subarray [2,4,5,6] has distinct values and sum 17, which is maximal.

Example 2

nums = [5,2,1,2,5,2,1,2,5]return = 8

A maximum-sum distinct subarray is [5,2,1], whose sum is 8.

Example 3

nums = [0,0,0]return = 0

Any one-element subarray [0] is valid and has sum 0.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^4
  • The answer fits in a 32-bit signed integer.

More Tekion interview questions

  • Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
  • Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
  • Koko Eating BananasONSITE INTERVIEW · Seen Sep 2026
  • Number of IslandsONSITE INTERVIEW · Seen Jul 2026
  • Minimum Size Subarray Sum With NegativesONSITE INTERVIEW · Seen Jul 2026
  • Set Matrix ZeroesONSITE INTERVIEW · Seen Jul 2026
  • Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
  • Dungeon GamePHONE SCREEN · Seen Sep 2026
  • IPOPHONE SCREEN · Seen Sep 2026
  • Coin Game From The EndsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • High-Traffic IPs in a Sliding WindowGoogle · ONSITE INTERVIEWGoogle interview questions
  • Longest Subarray with K Distinct ValuesAmazon · ONSITE INTERVIEW
  • Count Equal Code Pairs Within Distance KInfosys · ONSITE INTERVIEWInfosys interview questions
  • Longest Subarray with At Most Two Distinct ValuesMoody's Investors Service · ONSITE INTERVIEW
  • Sliding Window: Target Containment and Most-Repeated WindowRoblox · ONSITE INTERVIEWRoblox interview questions
  • Invalid Transactions in Time OrderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Duplicate Transactions Within 60 SecondsCapital One · ONSITE INTERVIEWCapital One interview questions
  • Sliding Window MedianNotion · ONSITE INTERVIEWNotion interview questions
All Tekion interview questionsSee Tekion hiring insights
Saved
class Solution {
    public int maximumUniqueSubarraySum(int[] nums) {
        // write your code here
    }
}
Checking account…