Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Backronymiser឵឵

Background

A backronym is an acronym that was formed from an existing word. For example, spam is actually named after the canned meat product as used in the Monty Python sketch, but can be interpreted as "stupid pointless annoying mail".

Challenge

Given a string a, and a word t, capitalise the correct letters of the words in a such that they spell out t. You should always move left-to-right through a, and capitalise the first occurrence of each letter.

For example, if a is all the worlds a stage, and t is LAG, then we walk along the letters of all the worlds a stage:

  • we look for the first l and capitalise it: aLl the worlds a stage
  • now we look for the next a, but it must be after the previously found l: aLl the worlds A stage
  • now we look for a g: aLl the worlds A staGe.

You may assume a will only contain lowercase ASCII letters and spaces.

You may assume t will only contain ASCII letters. You should choose whether t will be input in uppercase or lowercase.

You do not need to handle empty inputs or inputs that have no possible backronymisation.

Test cases

a                            t        output
================================================================
never gonna give you up      VIP      neVer gonna gIve you uP
all the worlds a stage       LAG      aLl the worlds A staGe
why                          WHY      WHY
baacbbccba                   ABC      bAacBbCcba
x                            X        X
xxxx                         X        Xxxx
yellow submarine time        YEET     YEllow submarinE Time

Rules

Answer*

Cancel
2
  • \$\begingroup\$ This is cutting off all letters following the last capitalized letter. Example \$\endgroup\$ Commented Aug 8, 2022 at 7:27
  • \$\begingroup\$ @Deadcode Whoops, over-optimised for the selected test case... \$\endgroup\$ Commented Aug 8, 2022 at 8:34