Replace Values

EasyData EngineeringArray

Description

Given a data array and two parallel arrays from and to that define a mapping, return the data with every value that appears in from replaced by the matching value in to. Values not in the mapping are left unchanged.

Examples

Input:[1,2,3,2], [2], [9]
Output:[1,9,3,9]
Explanation:

Any value found in the mapping is swapped for its replacement while everything else passes through untouched.

Input:[1,1,1], [1], [0]
Output:[0,0,0]
Explanation:

Any value found in the mapping is swapped for its replacement while everything else passes through untouched.

Input:[5,6,7], [6,7], [60,70]
Output:[5,60,70]
Explanation:

Any value found in the mapping is swapped for its replacement while everything else passes through untouched.

Constraints

  • 1 ≤ length ≤ 10⁴
  • from and to have equal length

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.