Day 9 problem

This is the last one with two pointers

Hello and welcome back brave human being,

Before we dig into the problem, I wanted to have a quick recap of how to use the two-pointer technique as this will be the last problem that uses this technique.

To identify a problem that can be solved using the two-pointer technique, look for the following keywords:

“count the number of pairs in an array”, or “return a pair of an array with a specific condition”

The given arrays are not typically sorted, and this two-pointer technique requires a sorted data structure, so bear this in mind.

What is the time complexity of sorting an array?

Using the built in function sort()

Login or Subscribe to participate in polls.

If the problem asks for the original indices of the array, make sure you keep track of the original indices using something like an array of pairs, otherwise, sort it!

Decide when to move the pointers, in most problems, the condition is whether our two pointers meet the target condition. That is not always the case, as we saw in problem: 11. Container With Most Water.

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Can you leverage the answer from our first day (167. Two Sum II - Input Array Is Sorted)? Think about it… you already have a solution that solves this problem for two numbers, how could you expand it to three numbers?

Happy Valentines 🤟 

Denisse

Add this problem to your log and when the challenge is done send it to me! You’ll be in for a treat.

Reply

or to participate.