Member-only story
Interview question: Delete repeated elements in an integer array
In the last blog post I made concerning Python interview questions, I discussed how to get matching elements of an integer array. That blog post can be read here:- https://medium.com/@tracyrenee61/interview-question-get-matching-elements-of-an-integer-array-5be7f5be89d4
In this blog post, I intend to modify the algorithm used above to delete repeated elements in an array. The solution to this problem is a little tricky. Although it seems like a simple thing to do, the key component in the solution is to make a copy of the list of integers, otherwise the algorithm will not work.
The psuedocode for the algorithm to delete repeated elements in an integer array is:-
- Define the function, del_element, which takes a list as an input, lst.
- Within the function, define the variable, len_lst, which is the length of the list, lst.
- Within the function, defined the variable, which is a copy of the list, lst.
- Within the function, create a for loop that iterates through the range of the length of list at an increment of 1. The iterator is the variable, i.
- Within the for loop, create a second for loop that iterates through the range of i+1 to the length of the list at an increment of 1. The iterator…