Given an array A[] of N integers and an index Key. Your task is to return the element present at index key in the array.
 
Example 1:
Input:
5 2
10 20 30 40 50
Output:
30
 
Example 2:
Input:
7 4
10 20 30 40 50 60 70
Output:
50
 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function findElementAtIndex() which takes the array A[], its size N and an integer Key as inputs and returns the element present at index Key.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 ≤ N ≤ 100
0 ≤ Key ≤ N - 1
1 ≤ A[i] ≤ 100

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



def findElementAtIndex(arr,n,key):

    # Your code goes here

Solutions:
def findElementAtIndex(arr, n, key):
	return arr[key]


def findElementAtIndex(arr, n, key):
	return arr[key] if key >= 0 else 0


def findElementAtIndex(arr, n, key):
	for i in range(n):
		if i == key:
			return arr[i]


def findElementAtIndex(arr, n, key):
	for i in range(len(arr)):
		if key <= len(arr):
			return arr[key]
		else:
			return 'None'


def findElementAtIndex(arr, n, key):
	element = 0
	element = arr[int(key)]
	return element


def findElementAtIndex(arr, n, key):
	if key < n:
		return arr[key]
	else:
		return -1


def findElementAtIndex(arr, n, key):
	for i in range(0, len(arr)):
		if i == key:
			return arr[i]


def findElementAtIndex(arr, n, key):
	for i in arr:
		a = arr[key]
	return a


def findElementAtIndex(arr, n, key):
	if key < 0 or key >= n:
		return -1
	return arr[key]


def findElementAtIndex(arr, n, key):
	k = int(key)
	a = arr[key]
	return a


def findElementAtIndex(arr, n, key):
	for i in range(len(arr)):
		return arr[key]


def findElementAtIndex(arr, n, key):
	for i in range(0, n):
		return arr[key]


def findElementAtIndex(arr, n, key):
	val = 0
	for i in range(n):
		val = arr[key]
		break
	return val


def findElementAtIndex(arr, n, key):
	lo = 0
	hi = n - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if mid < key:
			lo = mid + 1
		elif mid > key:
			hi = mid - 1
		else:
			return arr[mid]


def findElementAtIndex(arr, n, index):
	return arr[index]


def findElementAtIndex(arr, n, key):
	if key < n and key >= 0:
		x = arr[key]
		return x
	else:
		return 0


def findElementAtIndex(arr, n, key):
	i = 0
	while i < n:
		if i == key:
			return arr[i]
		i += 1


def findElementAtIndex(arr, n, key):
	for i in range(n):
		if i == key:
			return arr[i]
		else:
			continue


def findElementAtIndex(arr, n, key):
	for (i, v) in enumerate(arr):
		if i == key:
			return v


def findElementAtIndex(arr, n, key):
	x = arr.pop(key)
	return x