Maximum Sum of a Unique-Element Subarray
Updated
Problem statement
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[]) → intExamples
Example 1
nums = [4,2,4,5,6]return = 17The 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 = 8A maximum-sum distinct subarray is [5,2,1], whose sum is 8.
Example 3
nums = [0,0,0]return = 0Any one-element subarray [0] is valid and has sum 0.
Constraints
1 <= nums.length <= 10^50 <= 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