Interview Query

Fixed-Length Arrays: Deletion

Start Timer

0:00:00

Upvote
5
Downvote
Save question
Mark as completed
View comments
Next question

Important: You must answer this question before attempting this one. We recommend copying your previous solution and iterating the new solution with the added operations.

Create a more extensive Array class simulating the functionality of fixed-size arrays. The array’s fixed size is 6. In this question, we will be implementing the deletion and search operations.

  • pop_back() -> element - removes the last element of the array. Returns the removed element. If the array is empty, return None.

  • pop_front() -> element - removes the first element of the array. Returns the removed element. If the array is empty, return None.

  • pop(index) -> element - removes the element at the specified index and returns it. When the index is not in range, raise an IndexError.

  • search(element) -> index - searches for the specified element and returns the index of the first instance if it exists inside the array. Returns -1 if the element does not exist inside the array. Example: Array([1, 2, 3]).search(2) -> 1.

  • __contains__(element) -> bool - checks if the element exists inside the array. Returns True if it exists and False if it does not.

  • abolish(element) -> count - removes all instances of an element and returns the count of all removed instances.

  • __eq__(other) -> bool - checks the equality of the array with another array called other. Raises a TypeError if other is not an instance of this custom Array class.

Note: All the basic addition operations must be implemented first. (Refer to Fixed Length Arrays 1)

.
.
.
.
.


Comments

Loading comments