This algorithm focuses on removing array duplicates.
This file contains 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 static int RemoveArrayDuplicate(int nums)|
|int arrayLength = 0;|
|for (int i = 0; i < nums.Length; i++)|
|if (nums[i] == nums[i++])|
|arrayLength = arrayLength + 1;|
Apr 12, 2021
Thank you really for your efforts and this initiative. It is really a great vision that would have massive impact on the tech ecosystem by providing a learning opportunity for persons like myself who are life-long learners. Well done to you and your team!
I also want to thank you for the special mention on your blog as well as your feedback for improvement through this medium, it means a lot to me.
My question as regards handling null parameter passed to the function for a robust solution is, can such scenario also be taken care of by using a try-catch code construct, in other words, writing a function that performs its intended operation and handle every other out of bound edge cases using exception handling ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Hello @Ezeji, thank you for participating in Week 1 of Algorithm Fridays.
This is the most memory-optimal solution because you aren't using any data structure, awesome stuff!
The only one gotcha I see here is that your solution assumes is that the input array cannot have a
nullvalue because what happens if I run
RemoveArrayDuplicate(null)? Ideally, you always want to write code that is robust and doesn't fail on edge cases or unexpected input.
That said, your solution got a special mention in this blog post here where I posted our solution. Please read through and let me know what you think.
Thanks once again and see you on Friday!