tag:blogger.com,1999:blog-87926254414007961.post1470030414061839843..comments2023-06-04T14:14:20.296+03:00Comments on Coder Eye: Java interview question: Check array for duplicate values in one passGuy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-87926254414007961.post-40986548537006902362014-08-09T15:27:31.761+03:002014-08-09T15:27:31.761+03:00This an "Interview Question". The whole ...This an "Interview Question". The whole point is that the terms have been set for you.Guy Bashanhttps://www.blogger.com/profile/13987595961461293379noreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-59025696699692991792014-02-07T14:34:29.204+02:002014-02-07T14:34:29.204+02:00Yo can first find out the max number in 'arr&#...Yo can first find out the max number in 'arr' and then create a 'helperArr' of that size to avoid ArrayIndexOutOfBoundsException. More elegant way in O(n) time complexity.Vishalhttps://www.blogger.com/profile/11299177870093333128noreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-60613504990262417852013-10-17T11:27:35.653+03:002013-10-17T11:27:35.653+03:00Why aren't you simply using a Map to store the...Why aren't you simply using a Map to store the values?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-4956411084637365912012-09-27T15:55:28.255+02:002012-09-27T15:55:28.255+02:00Of course it does. Because the array contains the ...Of course it does. Because the array contains the number "6". If you will look at the definition of the problem, you will see that the numbers that can be in the array are only from 0 to N - 1. Which means that "6" is not allowed. Of course supporting up to N number and even up to N * 2 (and so on...) can be added very easily.Guy Bashanhttps://www.blogger.com/profile/13987595961461293379noreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-89974790315734930292012-09-27T12:14:48.708+02:002012-09-27T12:14:48.708+02:00System.out.println(isDuplicate(new int[] { 2, 0, 1...System.out.println(isDuplicate(new int[] { 2, 0, 1,4,6 ,6}));<br />giving ArrayIndexOutOfBoundsExceptionAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-24151232242541629112010-03-26T23:17:01.990+03:002010-03-26T23:17:01.990+03:00If you mean: find duplicate characters in a string...If you mean: find duplicate characters in a string, the easiest way would be, to iterate the string char by char and put each char in a Set (or chars of course). On each iteration, before inserting the new char to the Set, check if it already exists (using the "contains" method). If the new char already exists in the Set, it is a duplicate char. Note, that a Set is actually a Map, so using the "contains" method should be pretty efficient to give you a good running time of O(n).Guy Bashanhttps://www.blogger.com/profile/13987595961461293379noreply@blogger.comtag:blogger.com,1999:blog-87926254414007961.post-1598140582539192022010-03-26T10:30:12.733+03:002010-03-26T10:30:12.733+03:00Good one..
Is it Possible to find a string array ...Good one.. <br />Is it Possible to find a string array for duplicates with this complexity (o(n))?.Anonymousnoreply@blogger.com