Create a function to find the first missing positive number in an array.
HardProblem 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)}")
}
Input
A hardcoded array, e.g., [3, 4, -1, 1]
Expected Output
First missing positive: 2