From the course: Java Practice: Collections

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Solution: Indices of sum

Solution: Indices of sum - Java Tutorial

From the course: Java Practice: Collections

Solution: Indices of sum

- [Instructor] Here is my solution for this challenge, and you may have come up with a different one, and that is always great. The whole purpose of this course is to improve your problem solving skills, and hopefully, that is achieved by looking at different ways to solve problems. So the reason I picked this one, even though it's trickier than the rest of them that we've done in this course is that I've seen this be used in job interviews. And that's because there's typically one way that a developer approaches this problem, and there's a way to improve it. So typically, the first thing an engineer thinks of when they see this problem is to use a nested for loop. So I have my list of all these numbers, and I have the outer loop going through all of these, and then I have the inner loop starting one ahead, and then checking if each one of those creates the right sum. However, a more efficient way to solve the problem is…

Contents