##Bugs##
Bugs
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
return Math.max(res, counter); // <-- Accounts for last series
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
return Math.max(res, counter); // <-- Accounts for last series
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
Bugs
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
return Math.max(res, counter); // <-- Accounts for last series
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
res =return Math.max(res, counter); // <-- Add this line before the return
Accounts for returnlast res;series
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
res = Math.max(res, counter); // <-- Add this line before the return
return res;
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
return Math.max(res, counter); // <-- Accounts for last series
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Not linear##
The solution is not linear as you claim because you use Arrays.sort()
at the top, which requires \$O(n*log(n))\$ time.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
res = Math.max(res, counter); // <-- Add this line before the return
return res;
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Not linear##
The solution is not linear as you claim because you use Arrays.sort()
at the top, which requires \$O(n*log(n))\$ time.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
res = Math.max(res, counter); // <-- Add this line before the return
return res;
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.
##Bugs##
The function doesn't handle the last series of numbers. For example:
Input: 5 5 5 Output: 0
Input: 5 5 9 9 9 Output: 2
This can be fixed by modifying the end of the function:
res = Math.max(res, counter); // <-- Add this line before the return
return res;
Also, the function fails to consider a number as the lower of two numbers once it has used it as the upper of two numbers. For example:
Input: 5 5 6 6 6 7 7 7 10 Output: 5 (should be 6)
Here, it groups 5 and 6 together but never considers that 6 and 7 can be grouped together.