We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Advanced
  4. Pair Sums

Pair Sums

Problem
Submissions
Leaderboard
Discussions
Editorial

Given an array, we define its value to be the value obtained by following these instructions:

  • Write down all pairs of numbers from this array.
  • Compute the product of each pair.
  • Find the sum of all the products.

For example, for a given array, for a given array [, , , ],

Pairs (7, 2), (7, -1), (7, 2), (2, -1), (2, 2), (-1, 2)
Products of the pairs 14, -7, 14, -2, 4, -2
Sum of the products 14 + (-7) + 14 + (-2) + 4 + (-2) =

Note that is listed twice, one for each occurrence of .

Given an array of integers, find the largest value of any of its nonempty subarrays.

Note: A subarray is a contiguous subsequence of the array.

Complete the function largestValue which takes an array and returns an integer denoting the largest value of any of the array's nonempty subarrays.

Input Format

The first line contains a single integer , denoting the number of integers in array .
The second line contains space-separated integers denoting the elements of array .

Constraints

Subtasks

  • for 20% of the points.
  • for 70% of the points.

Output Format

Print a single line containing a single integer denoting the largest value of any of the array's nonempty subarrays.

Sample Input 0

6
-3 7 -2 3 5 -2

Sample Output 0

41

Explanation 0

In this case, we have . The largest-valued subarray turns out to be with value .

Sample Input 1

10
5 7 -5 6 3 9 -8 2 -1 10

Sample Output 1

200

Author

harungunaydin

Difficulty

Expert

Max Score

80

Submitted By

2634

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

Join us

Create a HackerRank account

Be part of a 26 million-strong community of developers

Please signup or login in order to view this challenge

or
Already have an account?Log in