Tencent interview question

Leetcode 192 counting the words