 New update is available. Click here to update. Close
Topic list
Find Four Elements That Sums To A Given Value
MEDIUM
10 mins 82 upvotes
Sorting
Arrays
Binary Search
Topics (Covered in this problem)
Problem solved
Skill meter Sorting
-
- Binary Search
-
- Arrays
-
-
Other topics
Problem solved
Skill meter Strings
-
- Matrices (2D Arrays)
-
- -
- Stacks & Queues
-
- Trees
-
- Graph
-
- Dynamic Programming
-
- Greedy
-
- Tries
-
- SQL
-
- Binary Search Trees
-
- Heap
-
- Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Find Four Elements That Sums To A Given Value

Medium 0/80
Avg time to solve 10 mins
Success Rate 90 % Share 82 upvotes

## Problem Statement

#### You are given an array/list 'ARR' of ‘N’ integers and an integer value ‘TARGET’. You need to check whether there exist four numbers (ARR[i], ARR[j], ARR[k], ARR[l]) such that (0 <= i < j < k < l < N) and ARR[i] + ARR[j] + ARR[k] + ARR[l] = 'TARGET'.

##### Note:
``````1. All four numbers should exist at different indices in the given array.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images ) ##### Sample Input 1:
``````2
5 9
1 3 3 10 2
6 20
2 4 6 3 1 1
``````
##### Sample Output 1:
``````Yes
No
``````
##### Explanation For Sample Input 1:
``````Test case 1:
The elements at indices (0, 1, 2, 4) gives sum 9 i.e, ARR + ARR + ARR + ARR = 9. Hence the answer is Yes.

Test case 2:
None of the combinations of 4 numbers gives 20 as 'TARGET'. Hence the answer is No.
``````
##### Sample Input 2:
``````2
5 15
0 10 1 2 2
6 20
-2 12 -1 1 20 1
``````
##### Sample Output 2:
``````Yes
Yes
``````  Auto Console