Asked inAdobe,Mts1

Maximum Sum Problem Statement

You are given an array ARR of N integers. Your task is to perform operations on this array until it becomes empty, and maximize the sum of selected elements. In each operation, select an element from the array at index i (i.e., ARR[i]), remove one occurrence of the selected element, and remove all occurrences of ARR[i]-1 and ARR[i]+1 from the array if present.

Example:

Input:
ARR = [2, 3, 3, 3, 4, 5]
Output:
14
Explanation:

Select one of the 3's, removing (3, 2, 4), leaving [3, 3, 5]. Select the remaining 3's, leaving [5]. Select 5, resulting in an empty array. The sum is 3+3+3+5=14.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 105
  • 1 <= ARR[i] <= 105
Input:
The first line of input contains an integer 'T' representing the number of test cases.
For each test case:
The first line contains integer N, the size of the array.
The second line contains 'N' space-separated integers representing the array elements.
Output:
For each test case, print a single integer denoting the maximum sum, in a single line.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
AnswerBot
4mo

The task is to maximize the sum of selected elements from an array by following specific rules.

  • Select elements strategically to maximize the sum

  • Remove occurrences of selected element, and its neighbor...read more

Help your peers!
Select
Add answer anonymously...

Adobe Mts1 interview questions & answers

A Mts1 was asked Q. Left View of a Binary Tree Problem Statement Given a binary tree, your task is t...read more
A Mts1 was asked Q. Level Order Traversal of Binary Tree Given a binary tree of integers, return its...read more
A Mts1 was asked Q. Design a system that can store an incoming stream of characters in a sorted mann...read more

Popular interview questions of Mts1

A Mts1 was asked Q1. Left View of a Binary Tree Problem Statement Given a binary tree, your task is t...read more
A Mts1 was asked Q2. Level Order Traversal of Binary Tree Given a binary tree of integers, return its...read more
A Mts1 was asked Q3. Design a system that can store an incoming stream of characters in a sorted mann...read more
Adobe Mts1 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits