Skip to content

Nedbank Mock: Optimizing Resource Allocation (Q70) #46

@sudosf

Description

@sudosf

Problem

Given array arr of size n and integer k, find the maximum sum subarray of exactly length k where all elements are distinct. Return -1 if none exists.

Source

Nedbank VAS HackerRank Assessment - Q70
Tags: Easy, Greedy, Sliding Window, Arrays

References

Constraints

  • 1 <= k <= n <= 2 * 10^5
  • 1 <= arr[i] <= 10^9

Example

n=6, k=3, arr=[1,2,3,7,3,5]
Output: 15  // [7,3,5]

Approach Hints

  • Fixed-size window of length k
  • Which data structure tracks uniqueness and frequency within the window?
  • What do you do when a duplicate enters the window?

Complexity Target

  • Time: O(n)
  • Space: O(k)

Notes

Language: Java

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraysArray problemsmediumMedium difficultynedbank-prepDirectly maps to Nedbank VAS assessmentsliding-windowSliding window pattern

    Projects

    Status
    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions