BackhardStrings

Character Composition Classifier Solution

Problem Statement

Given a collection of strings, partition them into groups where each group consists of strings that are compositions of the same characters, regardless of order.

Example 1
Input
["listen","silent","enlist","inlets","banana"]
Output
[["listen","silent","enlist","inlets"],["banana"]]

Explanation: The strings 'listen', 'silent', 'enlist', and 'inlets' are all anagrams of each other, while 'banana' forms its own group.

Example 2
Input
["eat","tea","tan","ate","nat","bat"]
Output
[["eat","tea","ate"],["tan","nat"],["bat"]]

Explanation: The strings 'eat', 'tea', and 'ate' form one group, 'tan' and 'nat' form another, and 'bat' forms its own group.

Constraints

  • 1 <= number of strings <= 100
  • 1 <= length of each string <= 20
  • All strings consist of lowercase letters.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free