3 Sum
Medium Acceptance 35.80% Points 30.00
You are given an array arr[] and an integer target, determine if there exists a triplet in the array whose sum equals the given target.
Return true if such a triplet exists, otherwise, return false.
Examples
Example 1
Example 1
Input: arr[] = [1, 4, 45, 6, 10, 8], target = 13
Output: true
Explanation: The triplet {1, 4, 8} sums up to 13
Example 2
Example 2
Input: arr[] = [1, 2, 4, 3, 6, 7], target = 10
Output: true
Explanation: The triplets {1, 3, 6} and {1, 2, 7} both sum to 10.
Hints
Hint 1
Expected Time Complexity: O(n^2)
Hint 2
Expected Space Complexity: O(1)
Constraints
- 3 <= arr.size() <= 10^3
- 1 <= arr[i] <= 10^5
Companies
Microsoft Apple Samsung Visa
Topics
Array Sorting Algorithm
Track your submissions
Please log in to review your progress and explore code submissions from other participants.
Unlock the full solution
Please log in to access detailed answers and explanations.
Join the discussion
Please log in to join conversations with other participants.