DEV Community

Discussion on: Google Javascript Interview Question - Remove Duplicates from Sorted Array

Collapse
 
leonardosnt profile image
Leonardo Santos

The point here is to write the algorithm yourself. In this case you are just delegating the problem to the library to solve.

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Sets are built into JS, not a library.

The post states that this is specifically a JS interview question, not an algorithm or computer science test.

The question does not explicitly forbid anything, we've just been asked to solve the problem using JavaScript. Using this method would demonstrate to the interviewer that you have a grasp of modern JS, can use common sense by not reinventing the wheel, and have the sense to rely on an inbuilt language feature that is almost certainly faster than anything you could write (and presumably less likely to contain errors).

This is an interview situation where you should try to highlight everything you know, including being able to identify more efficient solutions.

If the interviewer actually wanted to test your ability to construct the algorithm yourself, they will ask for that explicitly - either in the question statement, or after you present them with the Sets based solution.

Thread Thread
 
leonardosnt profile image
Leonardo Santos

built into JS = standard LIBRARY. You get what I mean.

The post states that this is specifically a JS interview question, not an algorithm or computer science test.

Yes, this post lacks a lot of details about the problem. It is actually a general problem, he is just using JS to solve it.

Before the author edited the post, he mentioned that the space complexity should be O(1) (this is what is required in many places where this problem is described) which your solution does not meet.

You can see more details about the problem here:
interviewbit.com/problems/remove-d...
leetcode.com/problems/remove-dupli...

This is an interview situation where you should try to highlight everything you know, including being able to identify more efficient solutions.

So, what's the overall performance of your solution? What's the time and space complexity?

The original problem requires you to use constant space and linear time, so that means you should work with the array in place and not allocate an extra array.