Company: IBM application developer - cloud full stack_16march
Difficulty: medium
You are given a string taskAllocation of length n made of lowercase English letters. The character at index i represents the server assigned to the i th task. Each distinct letter represents a different server, and the number of times a letter appears is the number of tasks assigned to that server. In one operation, you may perform exactly one of the following: Add a new task by inserting any lowercase letter (assigning the task to that server). Remove an existing task by deleting any one character from the string. Your objective is to make the workload balanced, meaning: Every server that appears in the final string has the same number of assigned tasks (all remaining letters must have equal frequency). Determine the minimum number of operations needed to reach a balanced workload. Example taskAllocation = "xzyzxa" The 6 tasks will be assigned to servers 'x', 'y', 'z' and 'a'. There are 2 tasks for the servers 'x' and 'z' and 1 for the others. One possible solution is to append 1 'y'