Basic implementation of longestWord method