Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a function to find the first missing positive number in an array.

Hard

Problem Statement

Create a function to find the first missing positive number in an array.

Sample Input

A hardcoded array, e.g., [3, 4, -1, 1]

Sample Output

First missing positive: 2

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun firstMissingPositive(nums: Array<Int>): Int { // Add your code here to find the first missing positive } fun main() { val nums = arrayOf(3, 4, -1, 1) println("First missing positive: ${firstMissingPositive(nums)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded array, e.g., [3, 4, -1, 1]
Expected Output
First missing positive: 2