Created
April 21, 2021 04:13
-
-
Save rohanjai777/d31dcfc9886e5a76b239382247089419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int repeatedNumber(final int[] arr) { | |
int n = arr.length; | |
for(int i=0;i<n;i++){ | |
arr[i] = arr[i]-1; | |
} | |
for(int i=0;i<n;i++){ | |
arr[(arr[i])%n] = arr[(arr[i])%n]+n; | |
} | |
for(int i=0;i<n;i++){ | |
//System.out.println() | |
if(arr[i]/n > 1){ | |
return i+1; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment