tag:blogger.com,1999:blog-4228859841453048938.post3051370841953382627..comments2024-03-27T15:28:22.271+08:00Comments on Coding Interview Questions: No. 32 - Remove Numbers in ArrayHarry Hehttp://www.blogger.com/profile/10363303096963693183noreply@blogger.comBlogger20125tag:blogger.com,1999:blog-4228859841453048938.post-74278332286638210972019-08-10T15:11:17.032+08:002019-08-10T15:11:17.032+08:00My implementation in C#:
https://www.knowsh.com/N...My implementation in C#:<br /><br />https://www.knowsh.com/Notes/250492/Remove-Numbers-In-ArrayPriyank Saxenahttps://www.blogger.com/profile/04059942869055309258noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-2699379974143958142019-08-10T15:09:59.035+08:002019-08-10T15:09:59.035+08:00This comment has been removed by the author.Priyank Saxenahttps://www.blogger.com/profile/04059942869055309258noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-82202339274295245682018-06-09T17:24:51.361+08:002018-06-09T17:24:51.361+08:00Greetings Mate,
Three cheers to you ! Hooray!!! ...Greetings Mate, <br /><br />Three cheers to you ! Hooray!!! I feel like I hit the jackpot on Remove Numbers in Array<br /><br /><br />I created a new AWS account but then realised a better thing to do would be to change the email address of an existing account to the new email address. I closed the new account but can't change the email address of the existing account to the new email as it now says "The new e-mail address you have provided is already in use. <a href="https://www.youtube.com/watch?v=M-vNN1ntJDo&index=1&list=PLVNl9sThbR3FTwlKNHDDTZlxrfwqx8c0l/" rel="nofollow"> AWS Training USA </a> Please use a different e-mail address."<br /><br />Very useful article, if I run into challenges along the way, I will share them here.<br /><br />,Merci<br />Radhey<br />Anonymoushttps://www.blogger.com/profile/13698826098269783192noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-37708722478982900332018-06-02T17:42:22.392+08:002018-06-02T17:42:22.392+08:00Hello Harry,
I am shocked, shocked, that there is...Hello Harry,<br /><br />I am shocked, shocked, that there is such article exist!! But I really think you did a great job highlighting some of the key No. 32 - Remove Numbers in Array in the entire space.<br /><br /><br />Pretty new to all this, just switched to AWS from 1and1. They used to track the number of visitors and page views and other stats. How can I do this with AWS, just to see if I'm getting 5 vs 500 visitors per day? Any help/advice is appreciated.<br /><br /><br />Build a new AMI by first rotating up an example from a trusted AMI then add packages and components required <a href="https://asha24.com/blog/aws-tutorials-training-certification-and-interview-qa/" rel="nofollow"> AWS Training USA </a>. Be cautious of placing sensitive data on an AMI. For example, access credentials of yours should be added to an instance after spinup with a database, position an external volume that operates your MySQL data after spinup as well.<br /><br />Appreciate your effort for making such useful blogs and helping the community. <br /><br />Thank you,<br />KevinAnonymoushttps://www.blogger.com/profile/02198548195213794657noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-1804066312793602512018-05-31T17:49:10.906+08:002018-05-31T17:49:10.906+08:00Hi Harry,
In total awe…. So much respect and gra...Hi Harry,<br /><br /><br />In total awe…. So much respect and gratitude to you folks for pulling off such amazing blogs without missing any points on the No. 32 - Remove Numbers in Array . Kudos!<br /><br />I joined the Amazon affiliate site and received my access key id and my secret key.<br /><br />There was a problem downlaoding and saving the secret key so I created another one.<br /><br />I am submitting this information to Amazon to complete my affilaite site but <a href="https://asha24.com/aws-certification-training" rel="nofollow"> No. 32 - Remove Numbers in Array </a> is accepting the information.<br /><br />I would appreciate any information as to why this may be ocurring.<br /><br />I look forward to see your next updates.<br /><br />Kind Regards,<br />Irene HynesAnonymoushttps://www.blogger.com/profile/01329230669792273903noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-41784713215368889962017-01-03T17:57:45.708+08:002017-01-03T17:57:45.708+08:00The bets use of collecting secondary data is when ...The bets use of <a href="http://www.secondarydatacollection.com/how-our-collecting-secondary-data-help-works/" rel="nofollow">collecting secondary data</a> is when you have complex data and unable to find any solution. <br />aliyaahttps://www.blogger.com/profile/06184256288293330921noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-15176048646599492442016-05-08T20:50:31.970+08:002016-05-08T20:50:31.970+08:00Why we cannot just count how many times target val...Why we cannot just count how many times target value appears in the array and return array.length - count? There is no requirement to provide cleaned array, just its resulting length, so why bother?kirhgoffhttps://www.blogger.com/profile/18396838111644722185noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-63085560584106834782015-02-07T08:25:07.740+08:002015-02-07T08:25:07.740+08:00我觉得你这个做法是最机智的我觉得你这个做法是最机智的Anonymoushttps://www.blogger.com/profile/01536005317559451608noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-80162969811688887682015-02-07T08:22:50.268+08:002015-02-07T08:22:50.268+08:00这是我的做法,用一前一后双指针不断替换。
public int removeNumberInArra...这是我的做法,用一前一后双指针不断替换。<br />public int removeNumberInArray(int[] num, int target){<br /> int i = 0, j = num.length-1;<br /> while(i < j){<br /> if(num[i]==target){<br /> int temp = num[j];<br /> num[j] = num[i];<br /> num[i] = temp;<br /> j--;<br /> }else{<br /> i++;<br /> }<br /> }<br /> if(num.length==0){return 0;}<br /> return num[i]==target?i:i+1;<br /> }Anonymoushttps://www.blogger.com/profile/01536005317559451608noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-82092696157714825282013-06-29T02:10:05.539+08:002013-06-29T02:10:05.539+08:00我想Harry是对的,因为他的函数输出的是0, 如果是你的case的话,所以是一个从numbers起...我想Harry是对的,因为他的函数输出的是0, 如果是你的case的话,所以是一个从numbers起始,长度为0的arrayAnonymoushttps://www.blogger.com/profile/12248281698370470836noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-85874083125970948202013-04-12T14:59:10.892+08:002013-04-12T14:59:10.892+08:00你看这个双指针思路如何:
int removeElement(int A[], int lengt...你看这个双指针思路如何:<br /> int removeElement(int A[], int length, int elem) { <br /> int cur = 0; <br /> for(int i =0; i< length; i++) <br /> { <br /> if(A[i] == elem) <br /> continue; <br /> A[cur]=A[i]; <br /> cur++; <br /> } <br /> return cur; <br /> } tanglianghttps://www.blogger.com/profile/16757228731021205725noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-59699631603619886502013-04-12T14:41:57.114+08:002013-04-12T14:41:57.114+08:00你的这个思路在leetcode在线测试平台上运行有误你的这个思路在leetcode在线测试平台上运行有误tanglianghttps://www.blogger.com/profile/16757228731021205725noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-79856292412380672772013-04-12T14:37:43.353+08:002013-04-12T14:37:43.353+08:00何老师,假如输入是 A[2,2,2],length=3,n=2.你的这个函数还是原样输出数组A,这符...何老师,假如输入是 A[2,2,2],length=3,n=2.你的这个函数还是原样输出数组A,这符合题意么?tanglianghttps://www.blogger.com/profile/16757228731021205725noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-36517380238032937282013-04-03T19:46:42.253+08:002013-04-03T19:46:42.253+08:00Harry, why the exchange? If it does not matter wha...Harry, why the exchange? If it does not matter what is beyond the new end, why not just copy the value from the end and leave it at that. You save one memory write operation per match.<br /><br />So the if could contain only: *p1 = *p2--;LenardGhttps://www.blogger.com/profile/01706882673213117576noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-68082246515614067532013-02-05T10:46:35.891+08:002013-02-05T10:46:35.891+08:00The algorithm given by "E", could also a...The algorithm given by "E", could also achieve O(k) data moves by only moves at i>0, and his solution keeps the orignial order of the array, I guess should be betterAnonymoushttps://www.blogger.com/profile/02141677073183861874noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-16986306106185140662012-03-29T09:46:30.886+08:002012-03-29T09:46:30.886+08:00Thank you anon for your comments. You are right be...Thank you anon for your comments. You are right because the time efficiency is O(n) indeed. However, the number of data moves is O(k) in my solution, but it has O(n) data moves in the first reply by "E.".Harry Hehttps://www.blogger.com/profile/10363303096963693183noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-12474630394460408092012-03-29T01:31:35.913+08:002012-03-29T01:31:35.913+08:00I mean ++p1 and --p2.I mean ++p1 and --p2.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-8554373125433527932012-03-29T01:28:33.556+08:002012-03-29T01:28:33.556+08:00Harry, I think you're wrong and your solution ...Harry, I think you're wrong and your solution is O(n). Since the statements ++p1 and ++p2 run for a total of n times.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-12884918983052574202012-02-19T08:48:01.828+08:002012-02-19T08:48:01.828+08:00Your solution works. However, its time complexity ...Your solution works. However, its time complexity is O(n) if the length of array is n. The time complexity of the solution in post above is O(k), if there are k target numbers in the array. Usually k is less than n, so the solution illustrated in the post is more efficient than yours.Harry Hehttps://www.blogger.com/profile/10363303096963693183noreply@blogger.comtag:blogger.com,1999:blog-4228859841453048938.post-31008726928364040642012-02-19T00:22:14.410+08:002012-02-19T00:22:14.410+08:00I don't get why we can't use a simple solu...I don't get why we can't use a simple solution with a pointer, like this one:<br /><br />public int removeNumber(int[] A, int n) {<br /><br /> if (A == null || A.length == 0) return;<br /> int i = 0;<br /> for (int j=0; j<A.length; j++)<br /> if (A[j] != n) A[i++] = A[j];<br /><br /> return i; // The new dimension of the array<br />}<br /><br />Complexity is still O(n). What am I missing?E.https://www.blogger.com/profile/14038471267418452751noreply@blogger.com