Skip to content

[FEATURE REQUEST] Add 4-Sum Problem #5786

@nishchalgv1

Description

@nishchalgv1

What would you like to Propose?

I would like to propose adding an implementation of the 4-Sum Problem under the https://github.com/TheAlgorithms/Java/tree/master/src/test/java/com/thealgorithms/misc section of the repository.

Issue details

Problem Statement:
Given an array of N integers, your task is to find unique quads that add up to give a target value. In short, you need to return an array of all the unique quadruplets [arr[a], arr[b], arr[c], arr[d]] such that their sum is equal to a given target.

Example 1:
Input Format:
arr[] = [1,0,-1,0,-2,2], target = 0
Result:
[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
Explanation:
We have to find unique quadruplets from the array such that the sum of those elements is equal to the target sum given that is 0. The result obtained is such that the sum of the quadruplets yields 0.

Example 2:
Input Format:
arr[] = [4,3,3,4,4,2,1,2,1,1], target = 9
Result:
[[1,1,3,4],[1,2,2,4],[1,2,3,3]]
Explanation:
The sum of all the quadruplets is equal to the target i.e. 9.

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions