CLASSPLUS Hiring | On-Campus OA (2024) | Find Minimum Operations to Make All Array Elements Equal Problem

Question · Posted Jun 2026

Problem Statement You are given an integer array nums and an array of queries queries. For each query value q, determine the minimum number of operations required to make every element in nums equal to q. One operation consists of: Incrementing an element by 1, or Decrementing an element by 1. Return an array where each element represents the minimum operations needed for the corresponding query. Example Input nums = [3,1,6,8] queries = [1,5] Output [14,10] Explanation For query 1: ...

The full answer & interview discussion are available to premium members.

Log in Create a free account