TASK #1 › Group Anagrams
Task
You are given an array of strings @S
.
Write a script to group Anagrams together in any random order
My solution
This is pretty straight forward. Read the list of words, group them into a hash with the letters ordered, and then display the values of the hash. Simples.
Examples
» ./ch-1.pl opt bat saw tab pot top was
[ ("saw", "was"),
("bat", "tab"),
("opt", "pot", "top") ]
» ./ch-1.pl x
[ ("x") ]
TASK #2 › Binary Tree to Linked List
Task
You are given a binary tree.
Write a script to represent the given binary tree as an object and flatten it to a linked list object. Finally print the linked list object.
My solution
Okay, confession time. When doing these challenges. I have two rules. 1) Never read people's solutions before doing my own, and 2) Don't use modules that aren't part of Perl core. Perl doesn't have a native linked list implementation, and therefore I am intentionally skipping half this task to get the end result.
This task is similar to last week's second task. My code is largely copied from that. Instead of storing the paths, I add to the @digits
array as I walk the path.
Example
» ./ch-2.pl < example-1.txt
1 -> 2 -> 4 -> 5 -> 6 -> 7 -> 3
Top comments (0)