Problem 243609 · easy · Phase 02 Linear Data Structures

Group Words by Length

hash maps · grouping

Given a list of words, return a dictionary mapping each word length to the list of words of that length, in the order they appear in words. Duplicated words stay duplicated.

Examples

Input:  words = ["hi", "sun", "yo", "a"]
Output: {2: ["hi", "yo"], 3: ["sun"], 1: ["a"]}

Constraints

  • 0 <= len(words) <= 10**5
  • Target complexity: O(total characters).

Goals

  • Group items by a computed key
  • Preserve original order inside each group
Starting Python…