DSA Easy Notes (C#)

DSA Easy Notes (C#)

🚀 DSA Easy Notes (C#)

1. Reverse String

Input: "hello"
Output: "olleh"
Explanation: We reverse characters order.
string str = "hello";
char[] arr = str.ToCharArray();
Array.Reverse(arr);
Console.WriteLine(new string(arr));
Difference: Original: h e l l o Reversed: o l l e h

2. Palindrome

Input: "madam"
Output: Palindrome
Explanation: Same forward & backward.
string str = "madam";
string rev = new string(str.Reverse().ToArray());

Console.WriteLine(str == rev ? "Palindrome" : "Not");
Difference: Forward: madam Backward: madam → Same ✔

3. Max in Array

Input: [1,5,3,9,2]
Output: 9
Explanation: Compare all values and keep largest.
int[] arr = {1,5,3,9,2};
int max = arr[0];

foreach(int i in arr)
{
    if(i > max) max = i;
}

Console.WriteLine(max);
Difference: Compare: 1→5→9 → Max found = 9

4. Fibonacci

Input: n = 5
Output: 0 1 1 2 3
Explanation: Next number = sum of previous two.
int a = 0, b = 1;

for(int i = 0; i < 5; i++)
{
    Console.Write(a + " ");
    int temp = a + b;
    a = b;
    b = temp;
}
Difference: 0 → 1 → 1 → 2 → 3

5. Two Sum

Input: [2,7,11,15], target = 9
Output: index 0,1
Explanation: Find two numbers whose sum = target.
int[] nums = {2,7,11,15};
int target = 9;

Dictionary map = new Dictionary();

for(int i=0;i

Difference: 2 + 7 = 9 ✔

Comments