#dsa help

1 messages · Page 1 of 1 (latest)

silent wing
#

can someone tell me the approach of the question like when we do recursive call where do we check the condition

outer fogBOT
#

This post has been reserved for your question.

Hey @silent wing! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 720 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

runic marten
#

can you send the full image

silent wing
silent wing
molten knoll
#

You will need 2 for loops, nested into each other

silent wing
#

i got da answer guys

idle tokenBOT
#
"""class Solution {
    static int count = 0;
    public int reversePairs(int[] nums) {
        count = 0;
       mergeSort(nums);
        return count;
    }
    public void mergeSort(int[] arr){
        int n = arr.length;
        if(n <= 1){
            return;
        }
        int[] a = new int[n/2];
        int[] b = new int[n-n/2];
        int k = 0;
        for(int i = 0; i < a.length; i++) a[i] = arr[k++];
        for(int j = 0; j < b.length; j++) b[j] = arr[k++];

        mergeSort(a);
        mergeSort(b);
        merge(arr,a,b);
    }
    public void merge(int[] target, int[] a, int[] b){
        int i = 0, j = 0;
        while(i < a.length){
            while(j < b.length && a[i] > 2L * b[j]){
                j++;
            }
            count += j;
            i++;
        }
        i = 0;
        j = 0;
        int k = 0;
        while(i < a.length && j < b.length){
            if(a[i] < b[j]){
                target[k++] = a[i++];
            }
            else{
                target[k++] = b [j++];
            }
        }
        while(i < a.length) target[k++] = a[i++];
        while(j < b.length) target[k++] = b[j++]; 
    }
}""" ```

This message has been formatted automatically. You can disable this using /preferences.