Update appNew update is available. Click here to update.
About
My Stats
EXP gained
yellow-spark
2238
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
0
Know more
30
Total problems solved
16
Easy
13
Moderate
1
Hard
0
Ninja
Jan Jan Feb Feb Mar Mar Apr Apr May May Jun Jun Jul Jul Aug Aug Sep Sep Oct Oct Nov Nov Dec Dec

Current streak:

0 days

Longest streak:

3 days

Less

More

Achievements
1
Ronin
Topics
Matrices (2D Arrays)
Discussions
easy java solution
Interview problems

import java.io.*;

import java.util.* ;

 

public class Solution{

    public static List<int[]> pairSum(int[] arr, int s) {

        // Write your code here.

        int[] a;

        Arrays.sort(arr);

        List<int[]> l=new ArrayList<>();

        List<Integer> h=new ArrayList<>();

        for(int i=0;i<arr.length;i++){

            boolean b=false;

            if(h.contains(s-arr[i]))

            {

                int c=Collections.frequency(h,s-arr[i]);

                

                a=new int[2];

                a[0]=s-arr[i];

                a[1]=arr[i];

                while(c-->0)

                l.add(0,a);

            }

 

            h.add(arr[i]);

        }

        return l;

    }

}

 

profile
vishnu
Published On 10-Aug-2023
408 views
0 replies
0 upvotes