Given an array Arr of N elements and a integer K. Your task is to return the position of first occurence of K in the given array.
Note: Position of first element is considered as 1.
Example 1:
Input:
N = 5, K = 16
Arr[] = {9, 7, 2, 16, 4}
Output: 4
Explanation: K = 16 is found in the
given array at position 4.
Example 2:
Input:
N = 7, K = 98
Arr[] = {1, 22, 57, 47, 34, 18, 66}
Output: -1
Explanation: K = 98 isn't found in
the given array.
Your Task:
Complete the function search() which takes an array arr, two integers n and k, as input parameters and returns an integer denoting the answer. Return -1 if the number is not found in array. You don't to print answer or take inputs.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 10^{6}
1 <= K <= 10^{6}
1 <= Arr[i] <= 10^{6}

Difficulty: EASY
Tags: Data structures

Complete search
Skill types: Data structures

Complete search
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:



	

	def search(self,arr, n, k): 

    	# code here



Solutions:
class Solution:

	def search(self, arr, n, k):
		for i in range(len(arr)):
			if arr[i] == k:
				return i + 1
		return -1


class Solution:

	def search(self, arr, n, k):
		if k not in arr:
			return -1
		return arr.index(k) + 1


class Solution:

	def search(self, arr, n, k):
		for i in arr:
			if i == k:
				return arr.index(i) + 1
		else:
			return -1


class Solution:

	def search(self, arr, n, k):
		g = None
		for i in range(n):
			if arr[i] == k:
				g = i + 1
				break
			else:
				g = -1
		return g


class Solution:

	def search(self, arr, n, k):
		a = 0
		for i in range(0, n):
			if arr[i] == k:
				a = i + 1
				break
		if a != 0:
			return a
		else:
			return -1


class Solution:

	def search(self, arr, n, k):
		pos = -1
		for i in range(n):
			if arr[i] == k:
				pos = i + 1
				break
		return pos


class Solution:

	def search(self, arr, n, k):
		try:
			index = arr.index(k) + 1
			return index
		except ValueError as e:
			return -1


class Solution:

	def search(self, arr, n, k):
		position = 0
		while position < n:
			if arr[position] == k:
				return position + 1
				break
			else:
				position += 1
		return -1


class Solution:

	def search(self, arr, n, k):
		index = 1
		while index <= n:
			if k == arr[index - 1]:
				return index
			index += 1
		return -1


class Solution:

	def search(self, arr, n, k):
		for i in range(0, len(arr)):
			if k in arr:
				return arr.index(k) + 1
			else:
				return -1


class Solution:

	def search(self, arr, n, k):
		index_arr = range(n)
		position = -1
		for i in index_arr:
			if arr[i] == k:
				position = i + 1
				break
		return position


class Solution:

	def search(self, arr, n, k):
		i = 0
		while i < n:
			if arr[i] == k:
				return i + 1
			i += 1
		return -1


class Solution:

	def search(self, arr, n, k):
		try:
			i = arr.index(k)
		except:
			return -1
		return i + 1


class Solution:

	def search(self, arr, n, k):
		for item in range(0, n):
			if k == arr[item]:
				return item + 1
			item += 1
		return -1


class Solution:

	def search(self, arr, n, k):
		if k in arr:
			res = arr.index(k) + 1
		else:
			res = -1
		return res


class Solution:

	def search(self, arr, n, k):
		for (index, value) in enumerate(arr):
			index = index + 1
			if value == k:
				return index
		else:
			return -1


class Solution:

	def search(self, arr, n, k):
		count = arr.count(k)
		if count == 0:
			return -1
		else:
			a = arr.index(k) + 1
			return a


class Solution:

	def search(self, arr, n, k):
		count = 1
		for i in arr:
			if i == k:
				return count
			count += 1
		return -1


class Solution:

	def search(self, arr, n, k):
		flag = False
		for i in range(n):
			if arr[i] == k:
				return i + 1
				flag = True
		if flag == False:
			return -1
		return