DSA Day 2/100

DSA Day 2/100

Topic: Array

Questions Attempted: 4

1

Array subset of another array

2

First repeating element

3

Alternate positive and negative number

4

Non-repeating element

Questions Successfully Completed: 1

Array Subset of another array

Time Complexity : O(n*logn)

Space Complexity : O(1)

public String isSubset( long a1[], long a2[], long n, long m) {
        Arrays.sort(a1);
        Arrays.sort(a2);
        int j = 0;
        boolean flag = true;
        for(int i=0;i<n;i++){
            if(a2[j]==a1[i]){
                flag=true;
            }
            else{
                flag = false;
                continue;
            }
            if(j==m-1){
                return "Yes";
            }
            else{
                j++;
            }
        }
        return "No";  
    }

Thank you for reading!! :)