Pergunta de entrevista da empresa Microsoft

They asked me to implement a function that finds the first non-repeating character in a string and return its index, or return -1 if no such character exists.

Resposta da entrevista

Sigiloso

21 de nov. de 2025

I started by using a hash map to count the frequency of each character in the string with a first pass. Then I made a second pass through the string to find the first character with a count of 1 and returned its index. I initially missed the case where all characters repeat, but added the return -1 after the interviewer prompted me to consider what happens when no solution exists.