Returning this Output "]"

Viewed 37

//QUES - Minimum Subsequence in Non-Increasing Order

///CODE STARTS FROM HERE

/**
 * Note: The returned array must be malloced, assume caller calls 
free().
 */

int* minSubsequence(int* nums, int numsSize, int* returnSize){
    returnSize = (int *)malloc(numsSize*sizeof(int));
    int temp;
    int suma=0,sumb = 0;
    int n=0,i=0,j =0;
    int count = 0;
    for (int i = 0; i < numsSize; i++) {     
        for (int j = i+1; j < numsSize; j++) {     
           if(nums[i] > nums[j]) {    
               temp = nums[i];    
               nums[i] = nums[j];    
               nums[j] = temp;    
           }     
        }     
    }

    i = numsSize - 1;
    for(int m = 0;m<numsSize;m++)
    {
        sumb += nums[i];
       
        while(j<i)
        {   
  
            suma += nums[j];
            j++;
        }
        if(sumb <= suma)
        {
            returnSize[n] = nums[i];
            n++;
            count+=1;
        }
        else if(sumb > suma)
        {
            returnSize[n] = nums[i];
            count+=1;
            break;
        }
        i--;
        suma = 0;
        j = 0;
    }
    printf("\n");
    printf("ARRAY => "); 
    for(int k = 0 ;k<count;k++)
    {    
        printf("%d\t",returnSize[k]);
    }
    printf("\n");
    return returnSize;
}

//When i am printing ReturnSize elements , its showing correct Answers but when i am returning returnSize pointer its printing "]" . What mistake am i doing here? QUESTION OUTPUT

0 Answers
Related