TORONTO KIDS COMPUTER CLUB | PMCA Sunday 12:00 Java Homework 20.03.15.
17227
post-template-default,single,single-post,postid-17227,single-format-standard,ajax_fade,page_not_loaded,,no_animation_on_touch,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

PMCA Sunday 12:00 Java Homework 20.03.15.

20 Mar PMCA Sunday 12:00 Java Homework 20.03.15.

Question:
Given an array of positive and negative numbers, find if there is a subarray (of size at-least one) with 0 sum.

Subarray is a small part of the array. For e.g. for array {2,3,4} is a subarray of the array {1,2,3,4,5} while array{1,3,5 } is not a subarray of array {1,2,3,4,5}

Print true if the subarray exists if the subarray doesn’t exists print false

Input Description
The input contains N+1 lines. The first line of the input contains a number N which describes the size of an array. The next N lines of input contains the (N) numbers of the array

Output Description
Print true if the subarray exists, print false otherwise

Input
7
1
4
-2
-2
5
-4
3

Output
True

Explanation: {4,-2,-2} is a subarray whose sum is 0


Input
5
-3
2
3
1
6

Output
False

Explanation: No subarray exists whose sum is 0

No Comments

Sorry, the comment form is closed at this time.