 Explore
Placement Prep Edit Edit

# Program to check if all the numbers of an array can be made equal | FACE Prep

Published on 09 Mar 2020

Let us assume an array arr[]. We need to check if all the numbers of an array can be equalized to a particular number. In a single operation, any element of the array can be either multiplied by 2 or by 3. If it's possible to make all the array elements equal with the given operation then print Yes else print No.

Example:

Input:
3
50 75 100

Output:
Yes ->{50 * 2 * 3, 75 * 2 * 2, 100 * 3} = {300, 300, 300}

Input:
2
10 14

Output:
No


## Algorithm:

To make the elements of an array all equal,

• Start traversing the array and check if the number is divisible by 2.
• If it is divisible, divide the array element by 2.
• Similarly, check if the array element is divisible by 3.
• If it is divisible, divide the array element by 3.
• Then, check the remaining elements with the first element of the array.
• If they are equal, the array can be equalized.

## Program to check if all the numbers of an array are equal

Asked in companies like Paypal.


C
C++
Java
Python 3

Output
Input- 3 5 7 10 OUtput- No Input- 3 50 75 100 Output- Yes

Recommended Programs  