714257. Minimum Integer

Easy

Minimum Integer

Slug: minimum-integer--170647

Difficulty: Easy

Topic Tags: Mathematical, Arrays

Company Tags: None

Summary

The problem is to find the smallest integer that is not present in an array. The array contains a set of integers and we need to write a program to find the missing integer.

Detailed Explanation

We can solve this problem by first sorting the array and then iterating through the sorted array to find the smallest integer that is not present. Here's how you can do it:

Step 1: Sort the array in ascending order.

View on GeeksforGeeks
public class Main {
    public static void main(String[] args) {
        int[] arr = {4, 5, 6, 7, 9};
        Arrays.sort(arr);
        System.out.println(findMinInteger(arr));
    }

    public static int findMinInteger(int[] arr) {
        if (arr.length == 0) {
            return 1;
        }
        for (int i = 0; i < arr.length - 1; i++) {
            if (arr[i] + 1 != arr[i + 1]) {
                return arr[i] + 1;
            }
        }
        return arr[arr.length - 1] + 1;
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.