Start a Thread

Subscribe You’re not receiving notifications from this thread.

Least Positive Number Explanation

Challenges • Asked 5 months ago by grvchik

grvchik Commented on Jan 09, 2021:

I do not understand the explanation of this problem

nums[nums[i] - 1] != nums[i]) can give ArrayIndexOutOfBounds Exception as we are assuming that nums[i] will be an index

Besides this, explanation states we are comparing the current number with previous number
It should be nums[i-1]!=nums[i]

Jake from AlgoDaily Commented on Jan 10, 2021:

Hi grvchik,

I'm sorry that you're having difficulty with this problem.

  • The nums[i] > 0 clause ensures we don't get an ArrayIndexOutOfBounds exception.
  • We're not comparing numbers directly-- we're "mapping" the positive numbers to their equivalent array indexes.

I've gone ahead and recorded an explainer video for it here and updated the tutorial to make it more understandable. Hope it clarifies your issues.