Program to check if all the numbers of an array can be made equal | faceprep

Program to check if all the numbers of an array can be made equal | faceprep

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.


Program to check if all the numbers of an array can be made equal


Example:nnInput:n3n50 75 100nnOutput:nYes ->{50 * 2 * 3, 75 * 2 * 2, 100 * 3} = {300, 300, 300}nnInput:n2n10 14nnOutput:nNon


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 can be made equal

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

Asked in companies like Paypal.n


@@coding::1@@



Recommended Programs






Program to check if all the numbers of an array can be made equal

c