Welcome to your first day at PPCG Inc. As our newest junior assistant document sorter, you are responsible for making sure all documents we sent down to you are archived in alphabetical order. It's so easy a monkey can do it. Well, metaphorically speaking, as we did hire a monkey to do it. Guess what? Turns out monkeys lack an understanding of our alphabet. Anyway, there's no time to fix the mess there is right now, so just try to not make the situation any worse, ok? Then get to it! If you get hungry, there's bananas over by the water cooler. Good luck!
- You will receive a list of strings (the archive) and a string that needs to be added to that list (the document)
- All strings will contain only uppercase letters, lowercase letters and spaces
- Strings will always start and end with a letter
Determine the target position of the document: the position it should receive in the archive. The target position can be determined as follows:
- For each position:
- Count the amount of strings in the archive before that position that are alphabetically before the document
- Count the amount of strings in the archive after that position that are alphabetically after the document
- Define the score of the position as the sum of the above two counts
- The target position of the document is the position with the highest score
- In case of a tie, all positions with the highest score are equally valid as target position. Only one needs to be selected.
- Uppercase and lowercase letters are equivalent
- Spaces come before letters
- The archive with the document added to it in any form
- The target position of the document, in either a 0-based or 1-based index
Fewest bytes wins!
Archive: Applebuck Season Friendship is Magic The Ticket Master Griffon the BrushOff Boast Busters Bridle Gossip Document: Dragonshy Position scores (0-based index): 0: 0 + 3 = 3 1: 1 + 3 = 4 2: 1 + 2 = 3 3: 1 + 1 = 2 4: 1 + 0 = 1 5: 2 + 0 = 2 6: 3 + 0 = 3 Target position: 1