Subsequence Sum

0

0 votes
Datastructures, , Implementation, Basics of Greedy Algorithms, Basic Programming, Algorithms, Greedy Algorithms, 1-D, Basics of Implementation
Problem

You are given an array of N integer A1,A2,...,AN.

Task

You need to tell the difference between the maximum subsequence sum and minimum subsequence sum, both consisting of at least one element.

Notes

  • 0 based indexing is followed.
  • A  subsequence of an array is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.

  • A subsequence sum is the sum of all elements present in the subsequence.

Function description
Complete the solve function provided in the editor. This function takes the following 2 parameters and returns the difference between the maximum subsequence sum and minimum subsequence sum, both consisting of at least one element:

  • N: Represents the size of array A
  • A: Represents the elements of the array

Input format

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button)

  • The first line contains an integer T denoting the number of test cases. T also denotes the number of times you have to run the solve function on a different set of inputs.
  • For each test case:
    • The first line contains an integer denoting the size of array A.
    • The second line contains N space-separated integers, denoting the array elements.

Output Format:

For each test Case, print one integer denoting the difference in maximum subsequence sum and minimum subsequence sum.

Constraints :

1T10

1N10000

10000Ai10000

Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

NA

Editor Image

?