Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a string is a palindrome by reversing it.
DSA C#
string reversed = new string(input.Reverse().ToArray());
bool isPalindrome = input [1] reversed;Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong palindrome detection.
Using comparison operators like '>' or '<' is incorrect for string equality.
✗ Incorrect
We compare the original string with its reversed version using '=='. If they are equal, the string is a palindrome.
2fill in blank
mediumComplete the code to convert the input string to lowercase before checking palindrome.
DSA C#
string lowerInput = input.[1]();
string reversed = new string(lowerInput.Reverse().ToArray());
bool isPalindrome = lowerInput == reversed;Attempts:
3 left
💡 Hint
Common Mistakes
Using ToUpper instead of ToLower changes the case but is inconsistent with the reversed string.
Using Trim or Replace does not change letter case.
✗ Incorrect
Converting the string to lowercase ensures the palindrome check is case-insensitive.
3fill in blank
hardFix the error in the loop that compares characters from start and end to detect palindrome.
DSA C#
for (int i = 0; i < input.Length / 2; i++) { if (input[i] [1] input[input.Length - 1 - i]) { return false; } } return true;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes the function to return false for palindromes.
Using comparison operators like '>' or '<' is incorrect for character equality.
✗ Incorrect
We return false if characters at mirrored positions are not equal, so the condition uses '!='.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps words to their palindrome status.
DSA C#
var palindromeStatus = words.ToDictionary(word => word, word => word.[1]() == new string(word.[2]().Reverse().ToArray()));
Attempts:
3 left
💡 Hint
Common Mistakes
Using different case conversions on each side causes incorrect results.
Using ToUpper instead of ToLower is acceptable but inconsistent here.
✗ Incorrect
Converting words to lowercase before comparison ensures case-insensitive palindrome detection.
5fill in blank
hardFill all three blanks to filter a list of words and create a dictionary of palindromes only.
DSA C#
var palindromes = words.Where(word => word.[1]() == new string(word.[2]().Reverse().ToArray())) .ToDictionary([3] => [3], [3] => true);
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently causes errors.
Not converting to lowercase causes case-sensitive mismatches.
✗ Incorrect
Convert words to lowercase for comparison and use a variable name 'w' for dictionary keys and values.
