nikoo28 / java-solutions

Solutions in JAVA for some coding platforms.

Home Page:https://studyalgorithms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FindTheDuplicateNumber

rbraju opened this issue · comments

Hi Nikhil,
Thank you very much for the amazing videos on youtube and code in GitHub! It helps a lot to learn and solve algorithms. I need clarification on the solution provided for FindTheDuplicateNumber.java

If we try to access the index based on the values, wouldn't it throw the ArrayIndexOutOfBounds exception when the number is large? For example, the size of the input { 101, 324, 122, 15, 46, 39, 324, 131, 41, 324} is 9 but the values are much larger.

I don't know if there is an assumption where the values are within index.

If you check the problem statement, it says

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive.

So it is guaranteed that your above use case will not happen. :)

Great! Thanks for replying :)
Sorry. Didn't read the problem statement clearly.