[Google Onsite] Guess Pin Code

Image placeholder 9899

(This question has been seen in the interviews of the following companies: Google)

Given 2 strings pin and guess. Write a function to provide a hint that indicates how digits in guess match the pin. Use:
* - to indicate a number in the correct possition.
o - to indicate that a number is present in the pin code but in a different possition.
_ - to indicate that there's no such number in the pin code.

Example 1:

Input: pin = "1432", guess = "1246"
Output: "*oo_"

1 is in the correct position so `*`
2 and 4 are present in the pin code but in different positions thus `oo`
There's no 6 in the pin code thus `_`

Example 2:

Input: pin = "1234", guess = "1234"
Output: "****"

Example 3:

Input: pin = "1234", guess = "5678"
Output: "____"

Example 4:

Input: pin = "1224", guess = "5242"
Output: "_*oo"
Example 5:

Input: pin = "1234", guess = "1224"
Output: "**_*"

Example 6:

Input: pin = "2124", guess = "1224"
Output: "oo**"

pin.length == input.length
The input strings contain only digits 0-9.

Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.