P21772 [GeeksforGeeks] Min subsets with consecutive numbers0601
普及-
题目描述

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≤ 10^{5}
1 ≤ A[] ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
N = 10 Arr[] = {100, 56, 5, 6, 102, 58, 101, 57, 7, 103}
样例输出
3