Minimum Operations Problem Statement

You are given an array 'ARR' of size 'N' consisting of positive integers. Your task is to determine the minimum number of operations required to make all elements in the array equal. An operation can be either addition, subtraction, multiplication, or division performed on any element in the array.

Input:

The first line contains a single integer 'T', the number of test cases.
The first line of each test case contains an integer 'N', the length of the array.
The second line of each test case consists of 'N' space-separated integers representing the array 'ARR'.

Output:

For each test case, output an integer on a new line, depicting the minimum number of operations needed to make all elements of the array equal.

Example:

Input:
T = 1
N = 3
ARR = [1,2,3]
Output:
2
Explanation:

One possible way to achieve equal elements is by incrementing the element with value 1 by 1 and decrementing the element with value 3 by 1, resulting in the array [2,2,2]. This requires 2 operations.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 105
  • 0 <= ARR[i] <= 105
  • Time Limit: 1 sec
AnswerBot
4mo

Minimum number of operations to make all elements in an array equal by performing addition, subtraction, multiplication, or division.

  • Iterate through the array to find the maximum and minimum elements....read more

Help your peers!
Select
Add answer anonymously...

MakeMyTrip Full Stack Developer interview questions & answers

A Full Stack Developer was asked Q. Minimum Operations Problem Statement You are given an array 'ARR' of size 'N' co...read more
A Full Stack Developer was asked Q. Number of Islands II Problem Statement You have a 2D grid of dimensions 'N' rows...read more
A Full Stack Developer was asked Q. Tower of Hanoi Problem Statement You have three rods numbered from 1 to 3, and '...read more

Popular interview questions of Full Stack Developer

A Full Stack Developer was asked Q1. Minimum Operations Problem Statement You are given an array 'ARR' of size 'N' co...read more
A Full Stack Developer was asked Q2. Number of Islands II Problem Statement You have a 2D grid of dimensions 'N' rows...read more
A Full Stack Developer was asked Q3. Tower of Hanoi Problem Statement You have three rods numbered from 1 to 3, and '...read more
MakeMyTrip Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits