We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Cap Kay • 4 years ago

For a typical interview at Google, I would think that the format is almost no different from that of other companies. However the rating criteria is different. Google uses a few clear criteria that I will describe here in a general way:

https://www.rooftopslushie....

Andrew Meyer • 4 years ago

I believe your dups() implementation using a set is wrong, as you’re just converting the array to a set (i.e. removing duplicates), not finding duplicates. The “if” condition that adds to the set only if the item isn’t in the set is superfluous, as the nature of a set will take care of that for you.

Instead, I think you want to iterate each element and add it to a set, but before adding to the set, check it to see if the item is already there. If so, add the item to a separate list of values, which you’ll ultimately return.

Pseudocode (writing on phone, so apologies):

    dups(items)
d = []
s = set()
for item in items
if item in s, then d += item
s.add(item)
return d

Time: O(n)
Space: O(n)

henrypan • 4 years ago

Great

Zaheer Mohiuddin • 5 years ago

Great resource! After you get the offer though don't forget to negotiate! Check out www.comp.fyi for how much you can fetch at each level.

Nezaj • 5 years ago

Love levels.fyi and comp.fyi is a great addition (did not know of this before)-- thanks for making both!

Also, another helpful resource for readers — see jobsearch.dev

cryptnotic • 5 years ago

The second dups() implementation is incorrect. That version returns the set of elements in A, not the set of duplicates.

Regarding the third dups() implementation, you can avoid sorting by using two sets. Here's an example:


def dups(A):
s1 = set()
s2 = set()
for x in A:
if x not in s1:
s1.add(x) # s1 contains elements seen at least once.

else:
s2.add(x) # s2 contains elements seen more than once.

return list(s2)

Or you could do the same thing using a single dict that keeps count of how many times an element is seen.


def dups(A):
s = dict()
for x in A:
if x not in s:
s[x] = 1
else:
s[x] = s[x] + 1
return [ x for x in s if s[x] > 1 ]

Another note: dict() and set() will be about the same time for operations because they're both based on the same hash table implementation. (A set is just a dict where you don't care about the values, only whether the key is present or not.)

Edit: Disqus is screwing up my indented code, but you should be able to figure it out.