โญ Introduction
These problems appear again and again in:
- C# interviews
- Online coding rounds
- Machine coding rounds
- Technical screenings
If you can solve these confidently, you are 90% interview-ready.
๐น 1. Reverse a String
Checks: String handling, loops
string input = "hello";
char[] arr = input.ToCharArray();
Array.Reverse(arr);
Console.WriteLine(new string(arr));
๐น 2. Check Palindrome
Checks: Logic, string/number manipulation
string s = "madam";
string rev = new string(s.Reverse().ToArray());
Console.WriteLine(s == rev);
๐น 3. Find Factorial
Checks: Recursion / loops
int Factorial(int n)
{
return n <= 1 ? 1 : n * Factorial(n - 1);
}
๐น 4. Fibonacci Series
Checks: Loops, logic
int a = 0, b = 1;
for (int i = 0; i < 5; i++)
{
Console.Write(a + " ");
int temp = a + b;
a = b;
b = temp;
}
๐น 5. Check Prime Number
Checks: Math logic
bool IsPrime(int n)
{
if (n <= 1) return false;
for (int i = 2; i <= Math.Sqrt(n); i++)
if (n % i == 0) return false;
return true;
}
๐น 6. Find Largest Number in Array
Checks: Arrays
int[] arr = { 3, 7, 2 };
Console.WriteLine(arr.Max());
๐น 7. Remove Duplicate Characters
Checks: Collections, LINQ
string s = "programming";
string result = new string(s.Distinct().ToArray());
Console.WriteLine(result);
๐น 8. Reverse Words in a Sentence
Checks: String split
string s = "I love CSharp";
var words = s.Split(' ').Reverse();
Console.WriteLine(string.Join(" ", words));
๐น 9. Count Character Occurrences
Checks: Dictionary
string s = "hello";
var dict = s.GroupBy(c => c)
.ToDictionary(g => g.Key, g => g.Count());
๐น 10. Swap Two Numbers (Without Temp)
Checks: Logic
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
๐น 11. Find Second Largest Number
Checks: Sorting, logic
int[] arr = { 5, 1, 9, 7 };
int secondLargest = arr.Distinct()
.OrderByDescending(x => x)
.Skip(1)
.First();
๐น 12. Check Armstrong Number
Checks: Math + loops
int n = 153, sum = 0, temp = n;
while (temp > 0)
{
int d = temp % 10;
sum += d * d * d;
temp /= 10;
}
Console.WriteLine(sum == n);
๐น 13. Find Missing Number in Array
Checks: Math logic
int[] arr = { 1, 2, 4, 5 };
int n = 5;
int expected = n * (n + 1) / 2;
Console.WriteLine(expected - arr.Sum());
๐น 14. Find Duplicate Elements
Checks: LINQ
int[] arr = { 1, 2, 3, 2, 4 };
var duplicates = arr.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(g => g.Key);
๐น 15. Sort Array Without Built-in Sort
Checks: Algorithm basics
int[] arr = { 3, 1, 2 };
for (int i = 0; i < arr.Length; i++)
for (int j = i + 1; j < arr.Length; j++)
if (arr[i] > arr[j])
(arr[i], arr[j]) = (arr[j], arr[i]);
๐น 16. Count Vowels in String
Checks: String traversal
string s = "education";
int count = s.Count(c => "aeiou".Contains(c));
๐น 17. Find Sum of Digits
Checks: Math logic
int n = 123, sum = 0;
while (n > 0)
{
sum += n % 10;
n /= 10;
}
๐น 18. Check Anagram
Checks: String comparison
string s1 = "listen";
string s2 = "silent";
Console.WriteLine(
new string(s1.OrderBy(c => c).ToArray()) ==
new string(s2.OrderBy(c => c).ToArray())
);
๐น 19. Find Common Elements in Two Arrays
Checks: LINQ, sets
int[] a = { 1, 2, 3 };
int[] b = { 2, 3, 4 };
var common = a.Intersect(b);
๐น 20. Reverse an Integer
Checks: Number manipulation
int n = 123, rev = 0;
while (n > 0)
{
rev = rev * 10 + n % 10;
n /= 10;
}
Console.WriteLine(rev);
๐ง What Interviewers Really Look For
โ Clean logic
โ Edge case handling
โ Readable code
โ Correct use of C# features
โ Ability to explain solution
๐ฏ Interview Tip
After writing code, always explain:
- Time complexity
- Edge cases
- Alternative approach
This impresses interviewers more than fast typing.
๐ Conclusion
These 20 C# coding problems cover:
โ Strings
โ Arrays
โ Numbers
โ LINQ
โ Logic building
Master these and you will confidently clear:
- C# interviews
- Coding rounds
- Machine coding tests