Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the string to lowercase for case-insensitive comparison.
DSA C#
string s1Lower = s1.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using ToUpper instead of ToLower, which also works but is not the chosen method here.
Using Trim which removes spaces but does not change case.
✗ Incorrect
Using ToLower() converts all characters to lowercase, making the comparison case-insensitive.
2fill in blank
mediumComplete the code to sort the characters of the string for comparison.
DSA C#
char[] s1Chars = s1Lower.[1]();
Array.Sort(s1Chars);Attempts:
3 left
💡 Hint
Common Mistakes
Using Split which splits by a delimiter and returns a string array, not char array.
Using OrderBy which returns an IEnumerable but not an array.
✗ Incorrect
ToCharArray() converts the string into a character array which can be sorted.
3fill in blank
hardFix the error in the comparison of sorted character arrays.
DSA C#
bool areAnagrams = new string(s1Chars).[1](new string(s2Chars));Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which does not fit the method syntax here.
Using CompareTo which returns an int, not a bool.
✗ Incorrect
Using Equals compares the content of the strings correctly.
4fill in blank
hardFill both blanks to create a dictionary counting characters in the first string.
DSA C#
var charCount = new Dictionary<char, int>(); foreach (char c in s1) { if (charCount.[1](c)) { charCount[c] [2] 1; } else { charCount[c] = 1; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add which causes error if key exists.
Using Remove which deletes keys instead of counting.
✗ Incorrect
ContainsKey checks if the character exists; if yes, increment count by 1.
5fill in blank
hardFill all three blanks to check if the second string matches the character counts.
DSA C#
foreach (char c in s2) { if (!charCount.[1](c)) { return false; } charCount[c] [2] 1; if (charCount[c] [3] 0) { charCount.Remove(c); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '-=' which increases count incorrectly.
Using '!=' instead of '==' for zero check.
✗ Incorrect
Check if character exists, decrease count by 1, and remove if count reaches zero.
