Skip to the content

Two half maps

Problem

"You've got the other half," the quartermaster tells the captain, and lays her piece of the map next to his. Where one of them lost a letter, the other may still have it.

You get two strings of the same length, made of lowercase letters and the ? sign, which marks what was lost. Return the joined map, position by position: if one has ?, use the other's letter; if both have ?, it stays ?; if both have the same letter, use that letter. If at any position they have different letters, they aren't from the same treasure: return "", even if everything else fits. Two empty strings give "".

With "i?la?d" and "?s?an?" you return "island".

Examples

  • They fill each other in

    "i?la?d", "?s?an?" → "island"

  • A gap nobody has

    "c?e?t", "ch??t" → "che?t"

  • They clash on the last letter

    "chest", "ch?sk" → ""

  • Empty maps

    "", "" → ""

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def join_maps(a, b):
    pass

JavaScript

function joinMaps(a, b) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →