FastPrepResolve Key-Value Chains
Problems/Resolve Key-Value Chains

Resolve Key-Value Chains

Indeed logoIndeed● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the task as one input and output, ['a:1', 'b:2', 'c:a'] to ['a:1', 'b:2', 'c:1'], where a value can name another key and each key ends with its final value.

The report gives only this example. Here, keys are all different, chains never loop, and any value that equals a key is followed, even one made of digits. Keys and values are 1 to 8 lowercase letters or digits, there are at most 1000 mappings, and the output keeps the input order.

The judged task matches the report at about 85%.

You are given an array mappings. Each element is a string key:value.

A value may be the name of another key. Then the key's final value is the final value of that other key. A value that is not any key is final as it is.

Return an array in the same order as mappings, where element i is key:final for the key of mappings[i] and its final value.

Function

resolveMappings(mappings: String[]) → String[]

Examples

Example 1

mappings = ["a:1","b:2","c:a"]return = ["a:1","b:2","c:1"]

1 and 2 are not keys, so a and b keep them. c maps to the key a, whose final value is 1, so c becomes c:1.

Example 2

mappings = ["x:y","y:z","z:42","w:q"]return = ["x:42","y:42","z:42","w:q"]

x goes to y, then z, then 42, which is not a key. y and z also end at 42. q is not a key, so w keeps it.

Example 3

mappings = ["p7:3","3:end","k:p7"]return = ["p7:end","3:end","k:end"]

The key 3 is made of a digit, but it is still a key. p7 goes to 3 and then to end, and k goes to p7 and ends at end too.

Constraints

  • 1 <= mappings.length <= 1000
  • Each mappings[i] has the form key:value with exactly one colon, where key and value are each 1 to 8 lowercase English letters or digits.
  • All keys are different.
  • Following values from any key never comes back to a key already passed, so there are no loops.

More Indeed problems

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public String[] resolveMappings(String[] mappings) {
        // Write your code here.
    }
}
Checking account…