Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a dictionary that stores character counts.
DSA C#
var charCount = new Dictionary<char, [1]>();Attempts:
3 left
💡 Hint
Common Mistakes
Using string or char as the value type instead of int.
Forgetting to specify the value type in the dictionary.
✗ Incorrect
The dictionary stores characters as keys and their counts as integer values.
2fill in blank
mediumComplete the code to check if the dictionary contains the character key.
DSA C#
if (!charCount.[1](c)) { charCount[c] = 1; } else { charCount[c]++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Add instead of ContainsKey, which causes errors.
Using ContainsValue which checks values, not keys.
✗ Incorrect
ContainsKey checks if the dictionary already has the character as a key.
3fill in blank
hardFix the error in the loop that finds the first non-repeating character.
DSA C#
foreach (var c in s) { if (charCount[c] [1] 1) { return c; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which assigns instead of compares.
Using '!=' which finds characters that repeat.
✗ Incorrect
We check if the count equals 1 to find the first non-repeating character.
4fill in blank
hardFill both blanks to complete the method signature and return statement.
DSA C#
public static char [1](string [2]) { /* method body */ return '\0'; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names.
Using vague method names.
✗ Incorrect
The method is named FirstNonRepeatingChar and takes a string parameter named s.
5fill in blank
hardFill all three blanks to complete the dictionary update and loop.
DSA C#
foreach (char [1] in [2]) { if (!charCount.ContainsKey([1])) { charCount[[1]] = 1; } else { charCount[[1]][3]; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names in the loop.
Using decrement operator instead of increment.
✗ Incorrect
We loop over each character c in string s and increment its count with ++.
