← Back to challenges

Find Missing Least Positive Element From Array

JavaScriptHardarrays

Instructions

Create a function that returns an array of missing least positive element(s) from a given array. Resulted array can not contain 0 or negative numbers.

Examples

getLeastPositiveElements([3, 4, -1, 1]) ➞ [2]

getLeastPositiveElements([3, 4, 6, -1, -3,1]) ➞ [2, 5]

getLeastPositiveElements([1, 8, 6, -1, -9,1]) ➞ [2, 3, 4, 5, 7]

Notes

Please check example for clarification

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.