Example 60: Frequency of Positive, Negative, and Zero

Learn how to calculate the frequency of numbers.

Problem

Write a program to find the number of positives, negatives, and zeros in the input array.

Store these values in the result array passed as a parameter such that the number of positive values should be stored at index 0, the number of negative values at 1, and zeroes at 2.

Example

Input Output (Positive, Negative, Zeroes)
1, 2, -3, 0, 4 3, 1, 1
4, 0, 2, -1, -3 2, 2, 1
0, 0, 2, 0, -3 1, 1, 3

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.