Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created May 13, 2026 05:00
Show Gist options
  • Select an option

  • Save Risyandi/bd28f02ecd129aa8c9cc51232d968ec4 to your computer and use it in GitHub Desktop.

Select an option

Save Risyandi/bd28f02ecd129aa8c9cc51232d968ec4 to your computer and use it in GitHub Desktop.
find the positive number in array numeric
import java.util.Arrays;
class Solution {
public int solution(int[] Array) {
int n = Array.length;
boolean[] seen = new boolean[n+2];
// debug
System.out.println("value n:" + n);
System.out.println("value seen[] 1:" + Arrays.toString(seen));
for (int x:Array) {
System.out.println("value x:" + x);
if(x > 0 && x <= n + 1){
seen[x] = true;
}
}
// debug
System.out.println("value seen[] 2:" + Arrays.toString(seen));
for (int index=1; index <= n + 1; index++){
// debug
System.out.println("value index:" + index);
System.out.println("value !seen[index]" + !seen[index]);
if (!seen[index]){
return index;
}
}
return n + 1;
}
// Main method to execute the function
public static void main(String[] args) {
Solution sol = new Solution();
int[] testArray = {1, 2, 4, 3, 6, 8}; // Example input
int result = sol.solution(testArray);
System.out.println("The smallest missing positive integer is: " + result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment