Grokking Oracle Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
For the python3 solution, after a triplet is found, why can't we just break out ...

Richard Yuan

Jan 27, 2022

For the python3 solution, after a triplet is found, why can't we just break out of the outer while loop after the triplet is appended to the list? I can't seem to figure out the point of the two while loops that follow to increment left and decrement right since if we return back to the search_triplets function, the left and right pointers will be reinitialized.

0

0

Comments
Comments
W
William Huang4 years ago

So the idea is that you want to look for all possible triplets given a specific target. the while loops are there to make sure that we are not adding the same triplet

R
Richard Yuan4 years ago

Ah I see. With a specific target sum, we need to find unique solutions. So if the previous left and right pointers were a valid pair, we now need to find the next unique pair for the specific target sum if one exists. Makes sense, thanks!

On this page