Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a5afb1d

Browse files
author
Ram swaroop
committed
smallest missing number : added test cases
1 parent 5b80a89 commit a5afb1d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/me/ramswaroop/arrays/SmallestMissingNumber.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ public class SmallestMissingNumber {
1414
* {@param a} consisting of numbers between 0 to m - 1 and m > n where n is
1515
* length of array.
1616
* <p/>
17+
* Time complexity: O(log n)
18+
* Con: Doesn't work if there are repetitive elements.
19+
* <p/>
1720
* EXPLANATION:
1821
* In standard Binary Search, the element to be searched is compared with
1922
* the middle element and on the basis of comparison result, we decide whether
2023
* to search is over or to go to left half or right half.
21-
* In this method, we modify the standard Binary Search algorithm to compare the
24+
* In this method, we modify the standard Binary Search algorithm to compare the
2225
* middle element with its index and make decision on the basis of this comparison.
2326
*
2427
* @param a
@@ -46,5 +49,6 @@ public static void main(String a[]) {
4649
System.out.println(smallestMissingNumber(new int[]{0, 1, 2, 6, 9}, 0, 4));
4750
System.out.println(smallestMissingNumber(new int[]{4, 5, 10, 11}, 0, 3));
4851
System.out.println(smallestMissingNumber(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 10}, 0, 8));
52+
System.out.println(smallestMissingNumber(new int[]{0, 1, 3, 3, 11}, 0, 4)); // doesn't work
4953
}
5054
}

0 commit comments

Comments
 (0)