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 Java
String reversed = new StringBuilder(input).[1]().toString();Attempts:
3 left
💡 Hint
Common Mistakes
Using toUpperCase() instead of reverse()
Trying substring() which extracts part of string
Using trim() which removes spaces
✗ Incorrect
The reverse() method of StringBuilder reverses the characters, which is needed to check palindrome.
2fill in blank
mediumComplete the code to compare the original and reversed strings ignoring case.
DSA Java
boolean isPalindrome = input.[1](reversed);Attempts:
3 left
💡 Hint
Common Mistakes
Using equals() which is case sensitive
Using compareTo() which returns int, not boolean
Using contains() which checks substring presence
✗ Incorrect
equalsIgnoreCase compares two strings ignoring case differences, useful for palindrome check.
3fill in blank
hardFix the error in the loop that checks characters from start and end for palindrome.
DSA Java
for (int i = 0; i < input.length() / [1]; i++) { if (input.charAt(i) != input.charAt(input.length() - 1 - i)) { return false; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking full length causing index errors
Dividing by 3 or 4 which misses some pairs
Dividing by 1 which does nothing
✗ Incorrect
We only need to check up to half the string length, so dividing by 2 is correct.
4fill in blank
hardFill both blanks to create a map of words to their palindrome status.
DSA Java
Map<String, Boolean> palindromeMap = words.stream()
.collect(Collectors.toMap(word -> word[1], word -> isPalindrome(word) [2]));Attempts:
3 left
💡 Hint
Common Mistakes
Using '== true' which is redundant
Not normalizing keys causing duplicates
Using .trim() which doesn't normalize case
✗ Incorrect
We normalize words to lowercase as keys and check if isPalindrome(word) is not false for values.
5fill in blank
hardFill all three blanks to filter and collect only palindrome words in uppercase.
DSA Java
List<String> palindromes = words.stream()
.filter(word -> word.[1]())
.map(word -> word.[2]())
.collect(Collectors.[3]());Attempts:
3 left
💡 Hint
Common Mistakes
Missing parentheses in toString() causing errors
Using equalsIgnoreCase without reverse string
Using collect(Collectors.toSet()) instead of toList()
✗ Incorrect
Filter uses equalsIgnoreCase comparing word to its reversed string, map converts to uppercase, collect gathers to list.
