# Task
 You are given an array of integers `a` and a non-negative number of operations `k`, applied to the array. Each operation consists of two parts:
```
find the maximum element value of the array;
replace each element a[i] with (maximum element value - a[i]).```
How will the array look like after `k` such operations?

# Example

 For `a = [-4, 0, -1, 0]` and `k = 2`, the output should be `[0, 4, 3, 4]`.
 ```
 initial array: [-4, 0, -1, 0]
 1st operation: 
 find the maximum value --> 0
 replace each element:  --> [(0 - -4), (0 - 0), (0 - -1), (0 - 0)]
                        --> [4, 0, 1, 0]
 2nd operation: 
 find the maximum value --> 4
 replace each element:  --> [(4 - 4), (4 - 0), (4 - 1), (4 - 0)]
                        --> [0, 4, 3, 4]
 
 ```
 For `a = [0, -1, 0, 0, -1, -1, -1, -1, 1, -1]` and `k = 1`, 
 
 the output should be `[1, 2, 1, 1, 2, 2, 2, 2, 0, 2]`.
 ```
 initial array: [0, -1, 0, 0, -1, -1, -1, -1, 1, -1]
 1st operation: 
 find the maximum value --> 1
 replace each element:  -->
 [(1-0),(1- -1),(1-0),(1-0),(1- -1),(1- -1),(1- -1),(1- -1),(1-1),(1- -1)]
--> [1, 2, 1, 1, 2, 2, 2, 2, 0, 2]
 ```

# Input/Output


 - `[input]` integer array a

    The initial array.

    Constraints: 

    `1 <= a.length <= 100`
    
    `-100 <= a[i] <= 100`


 - `[input]` integer `k`

    non-negative number of operations.

    Constraints: `0 <= k <= 100000`


 - [output] an integer array

    The array after `k` operations.

Difficulty: introductory

Starter code:

def array_operations(a, k):
	

Solutions:
def array_operations(a, n):
  li = []
  for i in range(n):
        m = max(a)
        a = [m-i for i in a] 
        if a in li:
            if not n & 1 : return li[-1]
            return a
        li.append(a)
  return a

def array_operations(a, k):
    for _ in range(2 + (k & 1)):
        m = max(a)
        a = [m - n for n in a]
    return a

def array_operations(a, k):
    m = max(a)
    a = [m-x for x in a]
    for i in range((k-1) % 2):
        m = max(a)
        a = [m-x for x in a]
    return a

def transform(a):
    m = max(a)
    return [m - element for element in a]

def array_operations(a, k):
  # After the first iteration, the the array alternates between two patterns
  return transform(a) if k % 2 == 1 else transform(transform(a))


def array_operations(a, k):
    b = [max(a)-i for i in a]
    c = [max(b)-i for i in b]
    return b if k%2 else c if k>0 else a

def array_operations(a, k):
    if k <= 0:
        return a
    elif k % 2:
        m = max(a)
        return [m - x for x in a]
    else:
        m = min(a)
        return [x - m for x in a]

def array_operations(A,k,p=0,q=0):
    D,E={},{}
    for i in range(k):
        s=str(A)
        if s in D:
            A=D[s]
            p=i
            q=E[s]
            break
        m=max(A)
        A=[(m-a)for a in A]
        D[s]=A
        E[s]=i
    if p!=q:
        for i in range(q+(k-q)%(p-q)):A=D[str(A)]
    return A

def array_operations(a, k):
    mx, mi = max(a), min(a)
    t = 0
    for i in range(k):
        if k%2 == 0:
            t = t + mx if i%2 != 0 else t-mx
        else:
            t = t - mx if i%2 != 0 else t+mx
        mx, mi = mx-mi, mx-mx       
    return [t-i for i in a] if k%2 != 0 else [t+i for i in a]