This is thematically similar to Generate keyboard shortcuts for a menu, but its actually a pretty different challenge.

Let's take PHPStorm's menu as an example:

New Project
New
Open Directory
Open
Open URL
New Project from Existing Files
Save As
Open Recent
Close Project
Rename Project


We need to assign a single-letter access keys for each of these menu items. Typically we pick the first letter, but if you notice, many of the above menu items start with the same letter!

Therefore, we'd want to pick:

P -> New Project
N -> New
D -> Open Directory
O -> Open
U -> Open URL
F -> New Project from Existing Files
S -> Save As
E -> Open Recent  (We don't pick "R" here because "Rename Project" needs it)
C -> Close Project
R -> Rename Project


Therefore, for our list we need to maximize (in order of importance):

1. The number of access keys actually contained in the string.
• ["X" -> "New"] should be avoided unless its your only option.
2. The number of access keys that start a word.
• ["N"->"New", "P"->"New Project"] is better than ["E"->"New", "N"->"New Project"]
3. The number of access keys that start the sentence.
• ["N"->"New Project"] is better than ["P"->"New Project"]

Access keys are case-insensitive, so if your menu is ["Add", "add"], one of them will need to use D as its access key.

# Input/output

You need to input a list of strings. The strings will only contain alphabetic characters and spaces. You can optionally input a single string with a delimiter for each of the lines. You can assume there will be between 1 and 26 menu items (inclusive).

You need to output either:

1. A Key-value map, where the key is the access key letter, and the value is the string it maps to
2. A list of access key letters, where the Nth entry pairs with the Nth item in the list.

You can either return the objects themselves, or a reasonable string representation of them. Access key letters can be in any case.

# Test Cases:

A                            -> A

• What about non-unique outputs? I assume for your test case D,A would also be a valid output, right? What if priority number 1 can't be avoided? Test case Add,add,ADD. – Martin Ender Sep 13 '16 at 18:19
• D,A is valid output. I've got a test case for that already: Add,add,Dad -> A,B,D – Nathan Merrill Sep 13 '16 at 18:21
• Can we assume that only first letters in a word are upper case, i.e. that CamelCase will not appear? Or doesn´t it matter? – Titus Sep 13 '16 at 22:44