Uber | Coding assessment online | Chemical elements in name
Anonymous User
1683

For an input string, output the chemical names and symbols present in it.

Data for chemical elements:

elements = [
	....
    {
        "name": "Nitrogen",
        "symbol": "N"
    },
    {
        "name": "Sodium",
        "symbol": "Na"
    },
    {
        "name": "Oxygen",
        "symbol": "O"
    }
	.... // other chemical elements + fake data
]

Example:

Input; Jonathan
Output:

O - Oxygen,
N - Nitrogen,
Na - Sodium,
...// other elements in name

P.S. - What would be an optimised solution for this, not a brute force one ?

Clarification:

Precomputation of input data into a hashmap like below is not possible:

elements = {
	....
        "N": "Nitrogen"
        "Na": "Sodium",
        "O": "Oxygen",
	.... 
}

Reason being that this data would be fetched from an API, on per request basis, and this data may contain fake imaginary checmical elements too. Sorry for missing this vital info earlier.

Comments (5)