Maximum size of consecutives
Easy Accuracy: 29.41% Submissions: 17 Points: 2

Given a sorted array arr of n distinct elements and an integer k. The array elements denote positions of points on 1-D number line, find the maximum size of subset of points that can have consecutive values of points which can be formed by placing another k points on the number line.

Example 1:

Input:
n = 8, k = 4
arr[] = {1, 2, 3, 4, 10, 11, 14, 15}
Output: 8
Explanation:
For maximum size subset, it is optimal to
choose the points on number line at
coordinates 12, 13, 16 and 17, so that the
size of the consecutive valued subset will
become 8 which will be maximum.

Example 2:

Input:
n = 6, k = 5
arr[] = {7, 8, 12, 13, 15, 18}
Output: 10
Explanation:
For maximum size subset, it is optimal to choose
the points on number line at coordinates 9, 10,
11, 14 and 16, so that the size of the consecutive
valued subset will become 10 which will be maximum .

You don't need to read input or print anything. Your task is to complete the function maximiseSubset() which takes the array of integers arr, n and as parameters and returns an integer denoting the answer.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)

Constraints:
1 <= n <= 106
1 <= k <= 105
1 <= arr[i] <= 106

We are replacing the old Disqus forum with the new Discussions section given below.

### Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

#### My Submissions:  