Given an Integer N and an array arr[] of length N. If index of the element is a Fibonacci Number, multiply the number by the index. After multiplying, if the number becomes greater than 100, make the element equal to the last two digits of the multiplied number. After doing these for all elements, find out the average of the N numbers in the Array.
Note: The array is in 1-based indexing (also in the Input). Also, print the floor value of the answer.
 
Example 1:
Input:
N = 5, arr[] = { 34, 78, 80, 91, 99 }
Output:
63
Explanation:
There are 5 elements.
1 is a fibonacci number and hence
34 is multiplied by 1.
2 is a fibonacci number and hence 78 is
multiplied by 2 and becomes 156 which being
greater than 100 is reduced to 56.
3 is a fibonacci number and hence 80 is
multiplied by 3 and it becomes 240, which
being greater than 100 is reduced to 40.
4 is not a fibonacci number and hence 91
is kept as it is.
5 is a fibonacci number and hence 99 is
multiplied by 5 and becomes 495 which being
greater than 100 is reduced to 95.
The total becomes 316 and the average is
63.2, floor of which is 63.
Example 2:
Input:
N = 2, arr[] = { 34, 99 }
Output:
66
Explanation:
There are 2 elements.
1 is a fibonacci number and hence
34 is multiplied by 1.
2 is a fibonacci number and hence 99 is
multiplied by 2 and becomes 198 which being
greater than 100 is reduced to 98.
The total becomes 132 and the average is 66.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function getAvg() which takes an Integer N and an Array arr[] of length N as input and returns the answer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
 
Constraints:
1 <= N <= 10^{5}
1 <= arr[i] <= 100

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def getAvg(self, N, arr):

        # code here 

Solutions:
class Solution:

	def getAvg(self, N, arr):
		fab = [0, 1]
		sum = 0
		for j in range(N):
			if j + 1 == fab[0] + fab[1]:
				v = arr[j] * (j + 1)
				if v > 100:
					v %= 100
				arr[j] = v
				(fab[0], fab[1]) = (fab[1], j + 1)
			sum += arr[j]
		return sum // N


from math import sqrt as sqrt

class Solution:

	def getAvg(self, N, arr):
		sol = Solution()
		for i in range(1, N + 1):
			if sol.check(i) == 1:
				arr[i - 1] *= i
			if arr[i - 1] > 100:
				arr[i - 1] %= 100
		return int(sum(arr) / N)

	def check(self, n):
		(n1, n2) = (5 * pow(n, 2) + 4, 5 * pow(n, 2) - 4)
		if pow(int(sqrt(n1)), 2) == n1 or pow(int(sqrt(n2)), 2) == n2:
			return 1
		return 0