You are given an array A of size N. Let us denote S as the sum of all integers present in the array. Among all integers present in the array, find the minimum integer X such that S ≤ N*X.
Example 1:
Input:
N = 3,
A = { 1, 3, 2}
Output:
2
Explanation:
Sum of integers in the array is 6.
since 6 ≤ 3*2, therefore 2 is the answer.
Example 2:
Input:
N = 1,
A = { 3 }
Output:
3
Explanation:
3 is the only possible answer
Your Task:
The task is to complete the function minimumInteger() which takes an integer N and an integer array A as input parameters and returns the minimum integer which satisfies the condition.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤  N ≤ 10^{5}
1 ≤  A_{i} ≤ 10^{9}

Difficulty: EASY
Tags: Data structures

Mathematics
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
from typing import List





class Solution:

    def minimumInteger(self, N : int, A : List[int]) -> int:

        # code here

    

Solutions:
from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		c = max(A)
		if N == 1:
			return A[0]
		for i in A:
			if s <= N * i:
				c = min(c, i)
		return c


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		p = sum(A)
		q = []
		for i in A:
			if p <= N * i:
				q.append(i)
		return min(q)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		su = 0
		ans = []
		for i in range(0, N):
			su += A[i]
		for x in A:
			if su <= x * N:
				ans.append(x)
		return min(ans)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		SOA = sum(A)
		x = int(SOA / N)
		if SOA % N != 0:
			x += 1
		lowest = 1000000000
		for i in A:
			if i >= x:
				lowest = min(lowest, i)
		return lowest


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		m = s
		for i in A:
			if i * N >= s:
				m = min(m, i)
		return m


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		l = []
		s = sum(A)
		for i in A:
			if N * i >= s:
				l.append(i)
		l.sort()
		return l[0]


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		summ = sum(A)
		A.sort()
		for i in A:
			if summ <= N * i:
				return i


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		total = sum(A)
		result = []
		for i in A:
			if len(A) * i >= total:
				result.append(i)
		if len(result) >= 0:
			return min(result)
		return 0


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		m = max(A)
		for i in range(N):
			if A[i] * N >= s:
				if A[i] <= m:
					res = A[i]
					m = res
		return res


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		sm = sum(A)
		mini = float('inf')
		for i in range(N):
			if sm <= N * A[i]:
				mini = min(A[i], mini)
		return mini


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		S = 0
		d = []
		for i in A:
			S += i
		for X in A:
			if S <= N * X:
				d.append(X)
		res = min(d)
		return res


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		ans = -1
		num = A[0]
		for i in range(N):
			if s <= A[i] * N:
				if ans == -1:
					ans = A[i] * N
					num = A[i]
				elif A[i] * N < ans:
					ans = min(ans, A[i] * N)
					num = A[i]
		return num


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		l1 = set()
		num_sum = sum(A)
		for i in A:
			if num_sum <= N * i:
				l1.add(i)
		return min(l1)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		ans = 10000000000.0
		for i in A:
			if i * N >= s:
				ans = min(ans, i)
		return ans


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		best_so_far = float('inf')
		for elem in A:
			if elem * N >= s and elem < best_so_far:
				best_so_far = elem
		return best_so_far


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		summ = sum(A)
		min_element = None
		for x in A:
			temp = N * x
			if summ <= N * x:
				if min_element is None:
					min_element = x
				else:
					min_element = min(min_element, x)
		return min_element


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		if len(A) == 1:
			return A[0]
		su = sum(A)
		mini = float('inf')
		for i in A:
			if su <= N * i:
				mini = min(mini, i)
		return mini


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		A.sort()
		s = sum(A)
		min_int = 0
		for i in A:
			if s <= N * i:
				min_int = i
				break
		return min_int


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		A.sort()
		p = sum(A)
		t = 0
		for i in A:
			if p <= N * i:
				t = i
				break
		return t


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		(s, m) = (sum(A), int(1000000000.0) + 7)
		for i in range(N):
			if s <= N * A[i]:
				m = min(m, A[i])
		return m


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		c = []
		for i in range(len(A)):
			if s <= N * A[i]:
				c.append(A[i])
		return min(c)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		A.sort()
		s = sum(A)
		for elem in A:
			if elem * N >= s:
				return elem


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		l = []
		s = 0
		for i in A:
			s = s + i
		for j in A:
			if j >= s / N:
				l.append(j)
			else:
				continue
		return min(l)


class Solution:

	def minimumInteger(self, N, A):
		A.sort()
		s = sum(A)
		for i in range(0, N):
			if s <= A[i] * N:
				return A[i]


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		A.sort()
		S = sum(A)
		min = 0
		for i in A:
			if S <= N * i:
				min = i
				break
		return min


from typing import List

class Solution:

	def minimumInteger(self, n: int, A: List[int]) -> int:
		A.sort()
		s = sum(A)
		for x in A:
			if s <= n * x:
				return x
		return -1


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		S = sum(A)
		min1 = pow(10, 9) + 1
		for i in A:
			if N * i >= S:
				min1 = min(min1, i)
		return min1


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		if N == 1:
			return A[N - 1]
		else:
			A.sort()
			Sum = sum(A)
			min = 0
			for i in A:
				if Sum <= N * i:
					min = i
					break
			return min


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		S = sum(A)
		lower = max(A)
		for i in A:
			if lower * N > i * N >= S:
				lower = i
		return lower


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		if N == 1:
			return A[N - 1]
		s = sum(A)
		b = []
		for i in range(N):
			if s <= N * A[i]:
				b.append(A[i])
		return min(b)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		A.sort()
		p = 1
		for i in A:
			if i * N >= s:
				return i


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		p = 0
		ma = max(A)
		for i in range(N):
			p = p + A[i]
		for j in range(N):
			if p <= N * A[j]:
				if A[j] <= ma:
					ma = A[j]
		return ma


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		sum1 = sum(A)
		mini = 9999999999999
		for i in range(N):
			if sum1 <= N * A[i] and A[i] < mini:
				mini = A[i]
		return mini


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		if len(A) == 1:
			return A[0]
		A.sort()
		s = sum(A)
		for i in range(N):
			if s <= N * A[i]:
				return A[i]


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		l = []
		for i in A:
			if N * i >= s:
				l.append(i)
		if l:
			return min(l)
		else:
			return -1


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		if len(A) == 1:
			return A[0]
		liste = []
		somme = 0
		for i in range(len(A)):
			somme = somme + A[i]
		for i in range(len(A)):
			if somme <= N * A[i]:
				liste.append(A[i])
		return min(liste)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		a = sum(A) / len(A)
		M = max(A)
		for i in range(N):
			if A[i] >= a:
				if M > A[i]:
					M = A[i]
		return M


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		c = 0
		s = sum(A)
		l = []
		for i in range(0, N):
			if s <= N * int(A[i]):
				l.append(A[i])
		if N > 1:
			k = min(l)
			return k
		return int(A[0])


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		A.sort()
		s = sum(A)
		(beg, end) = (0, N)
		while beg <= end:
			mid = (beg + end) // 2
			if A[mid] * N >= s:
				end = mid - 1
			else:
				beg = mid + 1
		return A[beg]


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		tot = sum(A)
		min = 999999999
		for i in range(N):
			if tot <= N * A[i]:
				if A[i] < min:
					min = A[i]
		return min


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		suma = 0
		for i in A:
			suma += i
		maxi = 1000000000
		for i in A:
			if suma <= N * i:
				if maxi > i:
					maxi = i
		return maxi


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		n = len(A)
		l = []
		for i in A:
			if s <= n * i:
				l.append(i)
		m = min(l)
		return m


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		li = []
		for i in A:
			if s <= N * i:
				li.append(i)
			else:
				pass
		return min(li)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		A.sort()
		import bisect as bs
		i = bs.bisect_left(A, s / N)
		return A[i]


from typing import List
import math

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		mini = math.inf
		f_sum = sum(A)
		for i in range(N):
			if f_sum <= N * A[i]:
				mini = min(mini, A[i])
		return mini


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		a = sorted(A)
		k = sum(a)
		l = []
		for i in a:
			if k <= N * i:
				l.append(i)
		return l[0]


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		if N > 1:
			s = sum(A)
			dict = {}
			for i in range(N):
				t = N * A[i]
				if t >= s:
					dict[t] = A[i]
			return min(zip(dict.keys(), dict.values()))[1]
		else:
			return A[0]


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		mini = max(A)
		s = sum(A)
		for i in A:
			if s <= N * i and mini > i:
				mini = i
		return mini


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		S = sum(A)
		possible_outcomes = []
		for integer in A:
			if integer >= S / N:
				possible_outcomes.append(integer)
		minimum = min(possible_outcomes)
		return minimum


from typing import List

class Solution:

	def minimumInteger(self, n: int, arr: List[int]) -> int:
		res = []
		s = sum(arr)
		for i in range(n):
			if arr[i] * n >= s:
				res.append(arr[i])
		return min(res)


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		res = 10 ** 10
		s = sum(A)
		for i in range(N):
			if s <= N * A[i]:
				res = min(res, A[i])
		return res


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		s = sum(A)
		d = max(A) * N - s
		for i in range(N):
			p = N * A[i] - s
			if p >= 0 and p <= d:
				d = p
				output = A[i]
		return output


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		sum = 0
		for i in range(0, len(A)):
			sum += A[i]
		min = []
		for i in range(0, len(A)):
			if sum <= N * A[i]:
				min.append(A[i])
		min_integer = min[0]
		for i in range(0, len(min)):
			if min[i] < min_integer:
				min_integer = min[i]
		return min_integer


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		maxi = max(A)
		S = sum(A)
		for i in range(N):
			if S <= N * A[i] and A[i] < maxi:
				maxi = A[i]
		return maxi


from typing import List

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		A = sorted(A)
		total = sum(A)
		value = 0
		for i in range(len(A)):
			if total <= len(A) * A[i]:
				value += A[i]
				break
		return value


from typing import List
import math
import sys

class Solution:

	def minimumInteger(self, N: int, A: List[int]) -> int:
		tot_sum = sum(A)
		x = math.ceil(tot_sum / N)
		ans = sys.maxsize
		for i in A:
			if i >= x:
				ans = min(ans, i)
		return ans