Two Pointers: 3 Sum
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target.
Return the sum of the three integers.
Assume that there will only be one solution
Example:
given array S = {-1 2 1 -4}
,
and target = 1
.
The sum that is closest to the target is 2
. (-1 + 2 + 1 = 2)
Read complete question here — https://www.interviewbit.com/problems/min-steps-in-infinite-grid/
Asked in Amazon, Microsoft, Facebook
Watch the complete video to understand the algorithm completely.
Check out this easy code.
If you find this article helpful, give me a clap 👏.
Have any better solution? Share it in the comment section.
Check out Red Coder Publication for more solutions of InterviewBit, Leetcode, Codeforces, etc — Click here
Follow me for more articles 😃