public static int FindNumberCount(int lowerIndex, int upperIndex, char toMatch){var count = Enumerable.Range(lowerIndex, upperIndex).Sum(x =>{return x.ToString().ToCharArray().Count(y => y == toMatch);});return count;}
Interviews6 answers
Interviews6 answers
public static int FindNumberCount(int lowerIndex, int upperIndex, char toMatch){var count = Enumerable.Range(lowerIndex, upperIndex).Sum(x =>{return x.ToString().ToCharArray().Count(y => y == toMatch);});return count;}
int count = 0;
for (int i=100;i<=10000;i++)
{
char[] number = i.ToString().ToCharArray();
for (int j=0;j<number.Length;j++)
{
// Console.WriteLine(number[j]);
if (number[j].ToString() == “9”)
count++;
}
}
Console.Write(count); //3980
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegisterMembers onlyFeatured eBookClaude for AI-Native BuildersDownload nowAnswer an interview question and earn +10 SHARP for every answer.
See unanswered questions