The TransCompilator

Solved LeetCode program · 49 of 1,000

#0049 · Group Anagrams

Medium Array chunk-01.md

Original English source

The text is "eat,tea,tan,ate,nat,bat". The wordslist is split text by ",". The last is the last position of wordslist. The signatures is an empty list of text.
For each word in wordslist.
The signature is sort characters of word. Place signature into signatures.

For every left from 0 to last.
For every right from left to last.
If item right of signatures comes before item left of signatures, swap item left of signatures and item right of signatures, swap item left of wordslist and item right of wordslist.

The group is empty text. The groupcount is 0. The current is empty text. The answers is an empty list of text.
For every position from 0 to last.
The signature is item position of signatures. The word is item position of wordslist. If position is 0, set current to signature, Place word into group, add 1 to groupcount. The same is 1. If signature comes before current, set same to 0. If current comes before signature, set same to 0. If position is more than 0 and same is 1 and groupcount is more than 0, Place "," into group, Place word into group, add 1 to groupcount. If position is more than 0 and same is 0, Place group into answers, set group to empty text, set groupcount to 0, set current to signature, Place word into group, add 1 to groupcount.

Place group into answers. For each answer in answers, display answer.

Open in Playground Browse all 1,000 problems

Expected stdout

bat
tea,ate,eat
nat,tan