Skip to content

Instantly share code, notes, and snippets.

@jamescurran
Last active February 12, 2025 17:59
Show Gist options
  • Select an option

  • Save jamescurran/63b5730016db08364661ae27a4a8542e to your computer and use it in GitHub Desktop.

Select an option

Save jamescurran/63b5730016db08364661ae27a4a8542e to your computer and use it in GitHub Desktop.
Daily Challenge: JS-100 Find Smallest Missing Positive Integer (in C#)
/*
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