
Asked in American Express
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

AnswerBot
4mo
Find maximum sum of disjoint pairs with absolute difference less than K in an array.
Iterate through the array and sort it.
Find all possible disjoint pairs with absolute difference less than K.
Calculat...read more
Help your peers!
Add answer anonymously...
Top Software Developer Interview Questions Asked at American Express
Q. Write a program to print prime numbers from 1 to n.
Q. Write a function to determine if an array of numbers are prime using streams.
Q. How have you leveraged Spring Java in your projects?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for American Express Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

