Products of Characters and Anagrams!
Description:
Given an array of characters take the numerical position in the alphabet of each letter and return the product of all positions. You also need to return an anagrammed word containing all of the characters in the array, but it needs to be the word that comes first alphabetically out of all longest possible options.
Make sure you calculate the product of all character positions before assembling them to a valid word.
If the word you return does not contain all letters in the array and is not the first alphabetically out of all max length possibilities, you will not pass. You must account for random testing using letters that do not form a valid English word. If the letters cannot be combined into a word, return ""
and the product before letter shuffling.
myList = ['b','q','g']
return "", 238
If this problem were not on codewars you could have a plethora of solutions for validating a word's existence in the English language. However, the few modules I tried (enchant, nltk) when developing this challenge do not work on this website. In light of that, I suggest you use the very straightforward API for Anagramica to help with this problem. There are other options available to you, this is just the one I used.
Example
myArray = ['a','b','t']
would be "1 x 2 x 20" and the product would be "40"
The two possible words from this 3 letter scramble are:
- "tab" and "bat"
Since bat comes first alphabetically and contains all of the letters in the array, that would be the correct word to submit alongside your characters' positional product.
return "bat", 40
For simplicity's sake and to stay below codewars' execution timeout of 12000ms, you will not receive an array with more than 5 characters or less than 3 characters.
Similar Kata:
Stats:
Created | Aug 14, 2022 |
Warriors Trained | 10 |
Total Skips | 0 |
Total Code Submissions | 41 |
Total Times Completed | 8 |
Python Completions | 8 |
Total Stars | 0 |
% of votes with a positive feedback rating | 25% of 4 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 3 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 7 kyu |