Showing:
Handle Score
@Ibrahim Nash 6420
@mb1973 5704
@Quandray 5245
@akhayrutdinov 5111
@saiujwal13083 5046
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3523
@mantu_singh 3510
@sushant_a 3459
Money Division
Easy Accuracy: 29.31% Submissions: 130 Points: 2

Given an array where each element is the money a person have and there is only Rs. 3 note. We need to check whether it is possible to divide the money equally among all the persons or not. If it is possible then find Minimum number of transactions needed.

Example 1:

Input: nums = [5, 8, 11]
Output: 1
Explanation: 3rd person can give Rs. 3
then all person would have Rs. 8

Example 2:

Input: nums = [1, 2, 3, 4]
Output: -1
Explanation: 1 + 2 + 3 + 4 = 10. Rs. 10
can not be distributed among 4 persons.

You don't need to read or print anything. Your task is to complete the function MinimumTransaction() which takes the array as input parameter and returns the minimum number of transactions needed to distribute the money equally. If not possible returns -1.

Expected Time Complexity: O(n) where n is length of array
Expected Space Complexity: O(1)

Constraints:
1 <= n <= 105
1 <= elements of array <= 106