Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the result variable to zero.
DSA Java
int result = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Initializing result to 1 or null causes wrong calculations or errors.
✗ Incorrect
The result variable should start at 0 to accumulate the integer value.
2fill in blank
mediumComplete the code to get the integer value of the current Roman numeral character.
DSA Java
int currentVal = romanMap.get([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using the index i directly instead of the character causes errors.
Using s.charAt(0) always gets the first character, not the current one.
✗ Incorrect
We get the character at index i from the string s to find its integer value in the map.
3fill in blank
hardFix the error in the if condition to check if the current value is less than the next value.
DSA Java
if (i < s.length() - 1 && currentVal [1] nextVal) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' reverses the logic and causes wrong results.
Using '==' or '>=' does not correctly identify subtraction cases.
✗ Incorrect
We check if currentVal is less than nextVal to decide if we subtract currentVal.
4fill in blank
hardFill both blanks to correctly update the result when current value is less than next value.
DSA Java
result [1]= currentVal; } else { result [2]= currentVal; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition in both cases causes wrong results.
Using multiplication or division is incorrect for this logic.
✗ Incorrect
Subtract currentVal from result if less than nextVal; otherwise, add it.
5fill in blank
hardFill all three blanks to complete the method signature and return statement.
DSA Java
public static int [1](String [2]) { // method body return [3]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method or parameter names causes confusion.
Returning a wrong variable causes errors.
✗ Incorrect
The method name is romanToInt, parameter is s, and we return result.
