Company: Citi

Difficulty: easy

Problem Statement

Sign of the Product You are given an array A of N integers. Determine the sign of the product of all the numbers in the array multiplied together, and return it as one of three values: 1 if the product is positive, -1 if the product is negative, 0 if the product is zero. You must not be tricked into actually needing the product itself: with up to 1000 factors the product does not fit in any built-in integer type, so the sign has to be decided from the numbers themselves. Input Format The first line contains a single integer N , the number of elements in the array. The second line contains N space-separated integers, the elements of A . Output Format Print a single integer: 1 , -1 , or 0 - the sign of the product of all elements of A . Constraints 1 <= N <= 1000 -100 <= A[i] <= 100 Example 1 Input 4 1 -2 -3 5 Output 1 Explanation The multiplication equals 30, which is positive, so the answer is 1. Example 2 Input 4 1 2 3 -5 Output -1 Explanation The multiplication equals -30

More Citi OA questionsInterview experiences