Three Sum Closest Problem

Three Sum Closest Problem — ExecCode Easy DSA Practice

Solve the Three Sum Closest problem on ExecCode. Free online easy DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given an integer array nums of length n and an integer target, find three integers at distinct indices in nums such that the sum is closest to target. Your task is to compute the required answer and return the sum of the three integers. You may assume that each input would have exactly one solution.

Examples

Input {"nums": [-1, 2, 1, -4], "target": 1}; Output 2. Input {"nums": [0, 0, 0], "target": 1}; Output 0. Input {"nums": [1, 1, 1, 0, -1], "target": 2}; Output 2

Constraints

3 <= nums.length <= 500 -1000 <= nums[i] <= 1000 -10^4 <= target <= 10^4

Practice Three Sum Closest free on ExecCode. Browse DSA problems, topic map, and placement guides.