Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6560
@blackshadows 6400
@mb1973 5777
@Quandray 5271
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4356
@sanjay05 3762
@mantu_singh 3638
@gfgaccount 3601
@marius_valentin_dragoi 3525
Complete Leaderboard
Min Subsets with Consecutive Numbers
Easy Accuracy: 55.9% Submissions: 510 Points: 2

Given an array of distinct positive numbers, the task is to calculate the minimum number of subsets (or subsequences) from the array such that each subset contains consecutive numbers.
 

Example 1:

Input:
N = 10
Arr[] = {100, 56, 5, 6, 102, 58, 101, 57, 7, 103} 
Output:
3
Explanation:
{5, 6, 7}, { 56, 57, 58}, {100, 101, 102, 103} are
3 subset in which numbers are consecutive.

 

Example 2:

Input:
N = 3
Arr[] = {10, 100, 105}
Output:
3
Explanation:
{10}, {100} and {105} are 3 subset
in which numbers are consecutive.

 


Your Task:  
You don't need to read input or print anything. Your task is to complete the function numofsubset() which takes the array Arr[] and its size N as inputs and returns the count of number of such subset's that contains consecutive numbers.


 

Expected Time Complexity: O(N. log(N))
Expected Auxiliary Space: O(1)


Constraints:
1 ≤ N≤ 105
1 ≤ A[] ≤ 105

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Min Subsets with Consecutive Numbers

Output Window