Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the input strings to lowercase for case-insensitive comparison.
DSA Java
String s1Lower = s1.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using toUpperCase instead of toLowerCase.
Forgetting to normalize case before comparison.
✗ Incorrect
Using toLowerCase() converts the string to all lowercase letters, which helps in comparing anagrams without case differences.
2fill in blank
mediumComplete the code to convert the string into a character array for sorting.
DSA Java
char[] chars1 = s1Lower.[1]();Attempts:
3 left
💡 Hint
Common Mistakes
Using split which returns a String array, not char array.
Using substring which returns a string, not an array.
✗ Incorrect
toCharArray() converts the string into a char array, which can then be sorted to check for anagrams.
3fill in blank
hardFix the error in the sorting line to correctly sort the character array.
DSA Java
java.util.Arrays.[1](chars1);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sorted' which is not a method in Arrays class.
Using 'order' or 'arrange' which do not exist.
✗ Incorrect
Arrays.sort() is the correct method to sort arrays in Java.
4fill in blank
hardFill both blanks to convert the sorted char array back to a string.
DSA Java
String sortedS1 = new String([1]); String sortedS2 = new String([2]);
Attempts:
3 left
💡 Hint
Common Mistakes
Using original strings instead of sorted char arrays.
Mixing variable names.
✗ Incorrect
We create new strings from the sorted character arrays chars1 and chars2 to compare them.
5fill in blank
hardFill all three blanks to complete the anagram check by comparing sorted strings.
DSA Java
if ([1].equals([2])) { return [3]; } else { return false; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of equals() for string comparison.
Returning false when strings match.
✗ Incorrect
If the sorted strings are equal, the method returns true indicating the strings are anagrams.
