Given an integer array Arr[] of size N. The task is to find sum of it.
Example 1:
Input:
N = 4
Arr[] = {1, 2, 3, 4}
Output: 10
Explanation: 1 + 2 + 3 + 4 = 10.
Example 2:
Input:
N = 3
Arr[] = {1, 3, 3}
Output: 7
Explanation: 1 + 3 + 3 = 7.
Your Task:
Complete the function sum() which takes array arr and single integer n, as input parameters and returns an integer denoting the answer. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{5}
1 <= Arr[i] <= 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

class Solution:



	def _sum(self,arr, n):

   		# code here



Solutions:
class Solution:

	def _sum(self, arr, n):
		suma = 0
		for i in range(n):
			suma += arr[i]
		return suma


class Solution:

	def _sum(self, arr, n):
		return sum(arr)


class Solution:

	def _sum(self, arr, n):
		sum = 0
		for i in arr:
			sum = sum + i
		return sum


class Solution:

	def _sum(self, arr, n):
		s = 0
		for v in range(n):
			s += arr[v]
		return s


class Solution:

	def _sum(self, arr, n):
		sum = 0
		for i in arr:
			sum = sum + i
		return sum
	n = 4
	arr = [1, 2, 3, 4]
	sum(arr, n)


import numpy as np

class Solution:

	def _sum(self, arr, n):
		return np.sum(arr)


class Solution:

	def _sum(self, arr, n):
		total = 0
		for num in arr:
			total += num
		return total


class Solution:

	def _sum(self, arr, n):
		sum_ = 0
		for x in arr:
			sum_ += x
		return sum_


class Solution:

	def _sum(self, arr, n):
		count = 0
		for a in range(n):
			count = count + arr[a]
		return count


class Solution:

	def _sum(self, arr, n):
		return sum(arr[0:n:1])


class Solution:

	def _sum(self, arr, n):
		lst = list(arr)
		return sum(lst)