Back to course home
0% completed
Vote For New Content
Unnecessary short distance calculations
Manuel
Jan 7, 2025
This part of the code will be called multiple times unnecessarily
// If both the positions are updated, update the shortest distance if (position1 != -1 && position2 != -1) { shortestDistance = Math.min(shortestDistance, Math.abs(position1 - position2)); }
Scenario:
String[] words = { "a", "c", "d", "b","x" ,"a" }; String word1 = "a"; String word2 = "b";
1
0
Comments
Comments