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. Interview Preparation Kits
  3. 3 Months Preparation Kit
  4. Week 6
  5. Sherlock and Array

Sherlock and Array

Problem
Submissions
Leaderboard
Discussions
Editorial
HackerRank Logo
|
  1. Prepare
  2. Interview Preparation Kits
  3. 3 Months Preparation Kit
  4. Week 6
  5. Sherlock and Array
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial

Watson gives Sherlock an array of integers. His challenge is to find an element of the array such that the sum of all elements to the left is equal to the sum of all elements to the right.

Example

is between two subarrays that sum to .

The answer is since left and right sum to .

You will be given arrays of integers and must determine whether there is an element that meets the criterion. If there is, return YES. Otherwise, return NO.

Function Description

Complete the balancedSums function in the editor below.

balancedSums has the following parameter(s):

  • int arr[n]: an array of integers

Returns

  • string: either YES or NO

Input Format

The first line contains , the number of test cases.

The next pairs of lines each represent a test case.
- The first line contains , the number of elements in the array .
- The second line contains space-separated integers where .

Constraints




Sample Input

2
3
1 2 3
4
1 2 3 3

Sample Output

NO
YES

Explanation

For the first test case, no such index exists.
For the second test case, , therefore index satisfies the given conditions.

  • 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