This is a question I got in a coding interview and while I know how to solve it in python, Java is a different beast. My approach was to split the sentence into an array of words and then check how many times a word appears in the array. First, we have to remove all the punctuation marks. Then to convert the sentence into an array of words we slice the array from the start of the array to a space. Then one letter from the space till the next space. The problem then is we need to add a space at the end of the sentence to make sure we count the last word. From there we just compare each word and our function returns how many times a word occurs regardless of the case. This challenge definitely showed me that I need to revise some of the fundamental aspects of Java. Tomorrow I will start with sorting algorithms which is a section that I ignored since np.sort exists.
Thank you for reading and if you would like to see the code check out my GitHub.