Given a List Arr, of 26 integers denoting the number of Alphabets of each type. You have to make all alphabets same. Exchanging an alphabet with another costs the difference in their ASCII value. For example, to exchange A with C, it will cost him 67-65 = 2.
Calculate the minimum amount you must spend to make all the alphabets same.
 
Example 1: 
Input:
Arr = {2 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0}
Output:
6
Explanation:
Exchanging all the alphabets to B
will cost the minimum.
Exchanging 2 A's for B's: 2*(66-65)=2
Exchanging 4 C's for B's: 4* (67-66)=4
Total cost = 6
Example 2: 
Input:
Arr = { 3 4 0 0 0 0 0 0 6 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 }
Output:
45
Explanation:
Exchanging all the alphabets to B
will cost the minimum.
Exchanging 3 A's for B's: 3*(66-65)= 3
Exchanging 6 I's for B's: 6*(73-66)= 42
Total cost = 45 
Your Task:
You don't need to read input or print anything. Your task is to complete the function getMinCost() which takes an Array/List Arr as input and return an answer.
Expected Time Complexity: O(|Arr|^{2})
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= Total number of alphabets <= 26*(10^5)

Source: geeksforgeeks | Difficulty: EASY

Starter code: #User function Template for python3

class Solution:
    def getMinCost(self , arr):
        # code here 

Solutions:
class Solution:

	def getMinCost(self, arr):
		minn = float('inf')
		for i in range(0, 26):
			temp = 0
			for j in range(0, 26):
				temp += arr[j] * abs(j - i)
			minn = min(temp, minn)
		return minn


class Solution:

	def getMinCost(self, arr):
		ans = 1e+18
		for i in range(26):
			cost = 0
			for j in range(26):
				cost += arr[j] * abs(i - j)
			ans = min(ans, cost)
		return ans


class Solution:

	def getMinCost(self, arr):
		temp = []
		i = 0
		for i in range(0, 26):
			a = 0
			for j in range(0, 26):
				e = i - j
				c = arr[j] * e
				if c < 0:
					a = a - c
				else:
					a = a + c
			temp.append(a)
		d = min(temp)
		return d


class Solution:

	def getMinCost(self, arr):
		a = []
		for i in range(len(arr)):
			if arr[i] != 0:
				a.append(i)
		costarr = []
		j = int(len(a) / 2)
		for i in range(len(a)):
			cost = 0
			for j in range(len(a)):
				cost += abs(a[i] - a[j]) * arr[a[j]]
			costarr.append(cost)
		if len(costarr) == 0:
			return 0
		return min(costarr)