Last active
February 12, 2025 17:59
-
-
Save jamescurran/63b5730016db08364661ae27a4a8542e to your computer and use it in GitHub Desktop.
Daily Challenge: JS-100 Find Smallest Missing Positive Integer (in C#)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Find Smallest Missing Positive Integer | |
| Write a function that finds the smallest positive integer | |
| that is missing from an unsorted array of integers. | |
| Your function should run with an expected time complexity of O(n). | |
| Example: | |
| Input: [-1, 4, 2, 1, 9, 10] | |
| Output: 3 | |
| */ | |
| int[] array = { -1, 4, 2, 1, 9, 10 }; | |
| var hash = array.Where(a => a > 0 ).ToHashSet(); | |
| Enumerable.Range(1, Int32.MaxValue).First(e => hash.Add(e) ).Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment