Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
If you find a triplet on the first call to seach_pair you will get a list index ...

stephen

Dec 2, 2022

If you find a triplet on the first call to seach_pair you will get a list index error because right already equals the end of the list so right +1 is out of bounds.

1

0

Comments
Comments
Shubham Vora
Shubham Voraa year ago

Check it properly. We reduce the right by 1 via right-- expression and then try to access right + 1 the index. So, it won't cause any problems.

if (currentSum == targetSum) { // found the triplet         triplets.add(Arrays.asList(-targetSum, arr[left...

On this page

Problem Statement

Examples

Example 2

Solution

Step-by-Step Algorithm

Algorithm Walkthrough

Code

Complexity Analysis:

Time Complexity

Space Complexity