Interviews

[Google Onsite] Guess Pin Code

user profile image
System made a post.

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_"

Explanation:
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**"

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



One-on-One Algorithm and Coding Training

One-on-One System Design Training

One-on-One Mock Interview

Get one-to-one training from Google Facebook engineers


Top-notch Professionals

Learn from Facebook, Google, Uber senior engineers interviewed 100+ candidates.aonecode.com
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.


Free Consultation

aonecoding@gmail.com