Maximum Sum With Specific Difference Problem Statement

Given an array of integers and a number 'K', your task is to find the maximum possible sum of disjoint pairs of numbers where the absolute difference between the paired elements is strictly less than 'K'.

Example:

Input:
ARR[] = {3, 5, 10, 15, 17, 12, 9}, K = 4
Output:
62
Explanation:

Possible disjoint pairs with absolute differences less than 'K' are (3, 5), (10, 12), and (15, 17). The maximum sum from these pairs is 3 + 5 + 10 + 12 + 15 + 17 = 62.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 3000
  • 1 <= ARR[i] <= 1000
  • 1 <= K < 1000
Be the first one to answer
Add answer anonymously...
American Express Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter