BackeasyLinked Lists PhonePe HCL

Maximum Link List Frequencies Solution

Problem Statement

Given a linked list of frequency and amplitude pairs, provide a recursive function to update the maximum amplitude for each frequency.

Example 1
Input
-5, 3, 1, 9, 2, 7, -9
Output
9, 7, 1, 9, 2, 7, 9

Explanation: The maximum amplitude for each frequency is updated in the linked list.

Example 2
Input
2, 4, 1, 6, 4, 3
Output
6, 6, 1, 6, 4, 6

Explanation: The maximum amplitude for each frequency is updated in the linked list.

Example 3
Input
10, 10, 10, 10, 10
Output
10, 10, 10, 10, 10

Explanation: Since all frequencies are the same, the maximum amplitude remains the same.

Constraints

  • Input linked list may be empty.
  • Amplitude values may be non-negative.
  • Frequency values may be negative or non-negative.
  • Output linked list should have updated maximum amplitude for each frequency.
  • The function should return the updated linked list.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free