Interview Questions/Coding/Fresh Signal Relay Window

Fresh Signal Relay Window

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Fresh Signal Relay Window

A relay monitor receives a sequence of positive signal IDs. A contiguous relay window is considered fresh only when every signal ID inside that window is unique. The energy of a fresh window is the sum of all signal IDs in that window. Windows must remain contiguous in the original order; you cannot skip signals inside a chosen window. Determine the maximum energy among all possible fresh relay windows. Input Format: You are given an integer array signals. Output Format: Return the largest sum of any contiguous subarray whose values are all distinct.

Examples

Example 1
Input:
signals = [4, 2, 4, 5, 6]
Output:
17

Explanation: The best duplicate-free signal window is [2, 4, 5, 6]. Its sum is 17, so the output is 17.

Approach hint

Only move the left pointer forward.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp