Catch the Hacker Coding Interview Question | Skilled.dev
Interview Question

Catch the Hacker

Course launching September 2020

Follow me on YouTube for free coding interview videos.

Users who sign up for the email list will receive an exclusive 75% discount at launch.

Your subscription could not be saved. Please try again.
Your subscription was successful! πŸ€“

You don’t like studying for coding interviews alone, so before you go to bed you post a signup form online where people can add their email if they want to practice interview questions together. When you wake up, you realize that other people dread studying for interviews as much as you, and A LOT of devs have signed up.

However, some prankster thought it would be funny to mess up your list, and they duplicated every email address multiple times. But this person made a mistake - the algorithm they used to duplicate emails actually created more copies of their email address in the list than anyone else. To get this hacker back, you want to find their email address in the list... using a computationally efficient algorithm! πŸ’ͺ πŸ™Œ

Write a function findHackerEmail that will return the email address of the hacker.

// Input
const emails = ['a@gmail.com', 'hey@skilled.dev', 'b@yahoo.com', 'hey@skilled.dev'];

// Output: findHackerEmail(emails);
'hey@skilled.dev'

Validate My Answer

  1. The brute force solution is O(n2), but you can do better.

  2. You may be tempted to sort the list so the duplicate emails are grouped together. Sorts cost O(n log n) which is better than a brute force solution, but think of techniques that allow us to get a better time complexity than this.

  3. Using an additional data structure, we can get the time complexity down to O(n).