If we are given "c{a}{b}" and the map as inputs, then we can simply check for the existence if keys {a} and {b} in the map and if both exists, then use StringBuilder to build out the key as- c.append(map.get(a)).append(map.get(b)). If this new key combination exists in the map, return the value, else we fall out of the if statements to return null or -1.