Mid
From PDF
MNC Coding
C# MNC Coding Interview
First non-repeating character in a string?
Short answer: First non-repeating character in a string What interviewers test Hashing Single-pass logic Clean thinking Optimized solution public static char? FirstUniqueChar(string input)
Example code
{
var frequency = new Dictionary<char, int>();
foreach (var ch in input)
frequency[ch] = frequency.GetValueOrDefault(ch) + 1;
foreach (var ch in input)
if (frequency[ch] == 1)
return ch;
return null;
} Complexity Time O(n) Spac O(k) (unique chars) Why two loops? First: count Second: preserve order
Real-world example (ShopNest)
MNC rounds expect working code plus explanation. Walk through an example input from a ShopNest cart list, then discuss time and space.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png