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 .
Your Task:
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 k as parameters and returns an integer denoting the answer.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Constraints:
1 <= n <= 10^{6}
1 <= k <= 10^{5}
1 <= arr[i] <= 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3


class Solution:
    def maximiseSubset(self, arr, n, k):
        # code here



Solutions:
class Solution:

	def maximiseSubset(self, arr, n, k):
		output = 0
		j = 0
		for i in range(n):
			while arr[i] - arr[j] - k > i - j:
				j += 1
			output = max(output, i - j)
		return output + 1 + k


class Solution:

	def maximiseSubset(self, arr, n, k):
		ans = k
		l = 0
		r = 0
		while r < n:
			while arr[r] - arr[l] - (r - l) > k:
				l = l + 1
			ans = max(ans, r - l + k + 1)
			r = r + 1
		return ans


class Solution:

	def maximiseSubset(self, arr, n, k):
		ans = k
		(a, b) = (0, 0)
		for a in range(0, n):
			if arr[a] - arr[b] - (a - b) > k:
				b = b + 1
			ans = max(ans, a - b + 1 + k)
			a += 1
		return ans


from itertools import combinations

class Solution:

	def maximiseSubset(self, arr, n, k):
		ans = k
		a = 0
		b = 0
		for a in range(0, n):
			if arr[a] - arr[b] - (a - b) > k:
				b = b + 1
			ans = max(ans, a - b + 1 + k)
			a = a + 1
		return ans


from itertools import combinations

class Solution:

	def maximiseSubset(self, arr, n, k):
		ans = k
		a = 0
		b = 0
		while a < n:
			if arr[a] - arr[b] - (a - b) > k:
				b = b + 1
			ans = max(ans, a - b + 1 + k)
			a = a + 1
		return ans