Find Duplicate Words (Medium)

Good morning! Here's our prompt for today.

You may see this problem at Cisco, Indeed, Linkedin, Wework, Intuit, Citadel, Snowflake, Robinhood, Red Hat, Canva, Mailchimp, Digitalocean, Elastic, and Dell.

A very common interview challenge is to determine how often words appear in a given string or set of strings. Here's a version of this: return a list of duplicate words in a sentence.

Description

For example, given 'The dog is the best', returns ["the"].

Likewise, given 'Happy thanksgiving, I am so full', you would return an empty array. This is because there are no duplicates in the string.

Constraints

  • The total length of the string <= 100000
  • The string will consist of ASCII characters (may be some or all)
  • Expected time complexity : O(n) where n are the number of words in the string
  • Expected space complexity : O(n)
JAVASCRIPT
OUTPUT
Results will appear here.