Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to access the element at index 2 in the array.
DSA Java
int value = numbers[1]2;
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for array access.
Using curly braces or angle brackets which are invalid for arrays.
✗ Incorrect
In Java, arrays use square brackets [] to access elements by index.
2fill in blank
mediumComplete the code to check if the linked list contains the value 5.
DSA Java
boolean found = list[1](5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using search() which is not a LinkedList method.
Using find() or has() which do not exist for LinkedList.
✗ Incorrect
The LinkedList class in Java has a contains() method to check if an element exists.
3fill in blank
hardFix the error in the code to get the value for key "apple" from the hash map.
DSA Java
String value = map[1]("apple");
Attempts:
3 left
💡 Hint
Common Mistakes
Using getValue() which does not exist in HashMap.
Using fetch() or lookup() which are not Java HashMap methods.
✗ Incorrect
The HashMap class uses get() to retrieve a value by key.
4fill in blank
hardFill both blanks to create a hash map and add a key-value pair.
DSA Java
HashMap<String, Integer> map = new HashMap<>(); map.[1]("banana", [2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using add() which is not a HashMap method.
Using a string instead of an integer for the value.
✗ Incorrect
Use put() to add a key-value pair to a HashMap. The value 5 is an integer.
5fill in blank
hardFill all three blanks to iterate over an array and print each element.
DSA Java
for (int [1] = 0; [2] < arr.length; [3]++) { System.out.println(arr[i]); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop parts.
Using 'j' which is not used in the loop body.
✗ Incorrect
The loop variable is 'i' used consistently for initialization, condition, and increment.
