← Back to challenges

Longest Word in a 7 Segment Display

PythonHardarraysloopsstrings

Instructions

Given a list of words, return the longest word which can fit on a 7 segment display.

Image of a 7 segment display

  • Letters which do not fit on a 7 segment display are k, m, v, w and x.
  • Therefore, do not count words which include these letters.

Examples

longest_7segment_word(["knighthood", "parental", "fridge", "clingfilm"]) ➞ "parental"

longest_7segment_word(["coding", "crackers", "innokodakademija", "celebration"]) ➞ "celebration"

longest_7segment_word(["velocity", "mackerel", "woven", "kingsmen"]) ➞ ""

Notes

  • All words will be given in lowercase.
  • Return an empty string if no words are eligible (see example #3).
  • If multiple valid words have the same length, return the first word that appears.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Find First Character That Repeats