Menu

3041. Maximize Consecutive Elements in an Array After Modification
πŸ“°

3041. Maximize Consecutive Elements in an Array After Modification

DEV Community: phpΒ·MD ARIFUL HAQUEΒ·10 days ago
#gJVw5xIp
#devto#dev#nums#example#elements
Long article (1064 words) β€” no AI summary yet.
Reading 0:00
15s threshold

3041. Maximize Consecutive Elements in an Array After Modification

Difficulty: Hard

Topics: Senior Staff , Array , Dynamic Programming , Sorting , Biweekly Contest 124

You are given a 0-indexed array nums consisting of positive integers.

Initially, you can increase the value of any element in the array by at most 1.

After that, you need to select one or more elements from the final array such that those elements are consecutive when sorted in increasing order. For example, the elements [3, 4, 5] are consecutive while [3, 4, 6] and [1, 1, 2, 3] are not.

Return the maximum number of elements that you can select .

Example 1:

Input: nums = [2,1,5,1,1]

Output: 3

Explanation:

We can increase the elements at indices 0 and 3.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.