tag:blogger.com,1999:blog-8712770457197348465.post6602262816550345394..comments2024-03-28T23:53:37.044-07:00Comments on Javarevisited: How to Find Multiple Missing Integers in Given Array of Numbers with Duplicates in Java?javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-8712770457197348465.post-42414946506572008952022-10-24T13:40:55.352-07:002022-10-24T13:40:55.352-07:00int[] array = { 1, 2, 3, 5, 7, 10,9,15 };
... int[] array = { 1, 2, 3, 5, 7, 10,9,15 };<br /><br /><br /> for(int i=0 ; iarray[j])<br /> {<br /> temp=array[i];<br /> array[i]=array[j];<br /> array[j]=temp;<br /><br /> }<br /> }<br /><br /> }<br /><br /> int[] holder=new int[array[array.length-1]];<br />Robelhttps://www.blogger.com/profile/15923657621930357337noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6577534051034467902020-01-16T08:16:05.540-08:002020-01-16T08:16:05.540-08:00HI Javin paul,
ArrayIndexOutOfBond isssue will co...HI Javin paul,<br /><br />ArrayIndexOutOfBond isssue will come if any alteration to array. Because while iterating input you are setting 1 to register array, but what if register[i] value larger than length of register array.<br /><br />Simple Register array should not be length of main array.<br /><br />ex: int[] input = { 1, 1, 2, 3, 7, 9, 9, 9 };<br /> System.out.println(input.length);<br ShivaKhttps://www.blogger.com/profile/00215961180468941825noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-16272581999462241862019-06-30T21:39:40.080-07:002019-06-30T21:39:40.080-07:00please tell me the same program in C
please tell me the same program in C<br />GUnahttps://www.blogger.com/profile/06530483597521673571noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72498396920102681322019-06-19T19:57:14.094-07:002019-06-19T19:57:14.094-07:00Yes Ashish, good point, for negative numbers this ...Yes Ashish, good point, for negative numbers this won't work, can you solve that problem? javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41228483325042879032019-06-19T06:01:30.394-07:002019-06-19T06:01:30.394-07:00What if the array contains negative integers, this...What if the array contains negative integers, this solution won't work then.Ashish Singhhttps://www.blogger.com/profile/01132565630349601867noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-60560266506170891002019-04-12T06:46:51.370-07:002019-04-12T06:46:51.370-07:00Hello Farman, can you provide more details? what a...Hello Farman, can you provide more details? what are you trying to do? May be just share the test case or past the error you are getting?javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-4354707265615138962019-04-11T02:43:30.201-07:002019-04-11T02:43:30.201-07:00i am also getting error(ArrayIndexOutOfBond) if i ...i am also getting error(ArrayIndexOutOfBond) if i am changing the length of array.<br /> Farmanhttps://www.blogger.com/profile/09137059005058537855noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-19004080585632245972019-03-05T16:24:15.865-08:002019-03-05T16:24:15.865-08:00@Anonymous, to check whether a number is present o...@Anonymous, to check whether a number is present or not. It's like a map where key is array index and value is the array value. For example, if 10 is present than register[10] will be 1 and if 10 is not present then it will be zero as default value. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61710159889328710302019-03-05T10:49:18.346-08:002019-03-05T10:49:18.346-08:00for (int i : input) { register[i] = 1; }
why are ...for (int i : input) { register[i] = 1; }<br /><br />why are we using this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-44476890387847243662019-03-05T10:48:10.690-08:002019-03-05T10:48:10.690-08:00for (int i : input) { register[i] = 1; }
why are ...for (int i : input) { register[i] = 1; }<br /><br />why are we using this?Anonymoushttps://www.blogger.com/profile/05412985546803650161noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-74208386657115320012019-01-31T21:01:00.724-08:002019-01-31T21:01:00.724-08:00"Register""999999999999999999"..."Register""999999999999999999"JC takes on a new worldhttps://www.blogger.com/profile/03136733158797497525noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-75764014550670852632019-01-31T20:59:26.271-08:002019-01-31T20:59:26.271-08:00"Register" "99999999999900090999999..."Register" "999999999999000909999999999999"<br />JC takes on a new worldhttps://www.blogger.com/profile/03136733158797497525noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43606366512001429542018-12-31T14:27:20.365-08:002018-12-31T14:27:20.365-08:00The "register" array shouldn't be wi...The "register" array shouldn't be with the length of the "input" array. Instead it should be with the length of the max. element inside input - in this case: 9.Anonymoushttps://www.blogger.com/profile/05269315121654881351noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-91759225528556392752018-12-18T02:20:06.823-08:002018-12-18T02:20:06.823-08:00the program is incorrect if we alter the given arr...the program is incorrect if we alter the given array length...so make it for any lengthHARISHKANDEKARhttps://www.blogger.com/profile/13104655613572201246noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-23817194449749617662018-10-03T03:36:16.415-07:002018-10-03T03:36:16.415-07:00We can solve this problem with space complexity of...We can solve this problem with space complexity of O(1);<br /><br /> private static void printMissingNumbers(int[] array) {<br /> for (int i = 0; i < array.length; i++) {<br /> int value = Math.abs(array[i]);<br /> if (array[value - 1] > 0) {<br /> array[value - 1] = -array[value - 1];<br /> }<br /> }<br /><br /> Murat Çelikhttps://www.blogger.com/profile/05672678926940086204noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-45525528285154207032018-09-02T22:46:37.107-07:002018-09-02T22:46:37.107-07:00Hi,
int[] input = { 1, 2, 3, 5, 7, 9 };
For this...Hi,<br /><br />int[] input = { 1, 2, 3, 5, 7, 9 };<br /><br />For this I am getting error.harihttps://www.blogger.com/profile/00928869076250875266noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-22928130417798753202018-05-02T04:03:17.244-07:002018-05-02T04:03:17.244-07:00Yes, that's a good idea and nice approach, but...Yes, that's a good idea and nice approach, but sorting will take around O(NLogN) time, let's say if we use quicksort or mergesort, which makes it little slower than what we have currently i.e. O(n) solution. But, yes, if you trade off space and do in place sorting, which you should if its too big, this solution is good javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-19812607788954626022018-05-01T21:02:53.869-07:002018-05-01T21:02:53.869-07:00If the array is not sorted, then we can sort it an...If the array is not sorted, then we can sort it and then check the current and next number. If the gap is more than 1, then the current+1 number is missing. This will be done in 1 traversal and no extra space required, no? Only downside I see is sorting is required once. Any suggestions?Anonymoushttps://www.blogger.com/profile/17170185466089709167noreply@blogger.com