Challenge Summary
This challenge asks us to implement a function that takes a string and returns the first duplicated word in that string.
Whiteboard Process
Approach & Efficiency
To solve this challenge I started by splitting the string into words then I mapped each word with an integer representing its frequency inside the string and when I find a word that is duplicated I return it to be the answer. This function takes O(n) space complexity since I declare a new array of strings to hold the words and O(n) speed complexity since I loop over all n words inside the string. You can view the code from here
Solution
To use this function you can simply call it and send a string inside it as follows:
HashmapRepeatedWord(string)
or you can run ./gradlew run
to run the test cases.