Given an array and an integer B, traverse the array (from the beginning) and if the element in array is B, double B and continue traversal. Find the value of B after the complete traversal.
Example 1:
Input:
N = 5, B = 2
arr[] = {1 2 3 4 8}
Output: 16
Explanation: B is initially 2. We get 2 at
the 1st index, hence B becomes 4. 
Next, we get B at the 3rd index, hence B 
becomes 8. Next, we get B at 4-th index, 
hence B becomes 16.
Example 1:
Input:
N = 5, B = 3
arr[] = {1 2 3 4 8}
Output: 6
Explanation: B is initially 3. We get 3 at
the 2nd index, hence B becomes 6.
Your Task:
You don't need to read input or print anything. Your task is to complete the function solve () which takes the array arr[], its size N and an integer B as inputs and returns the final value of B after the complete traversal of the array.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1<=N<=50
1<=B<=1000
1<=arr[i]<=10^{18}

Source: geeksforgeeks | Difficulty: EASY
Tags: Complete search

Starter code: #User function Template for python3



class Solution:

    def solve(self,n : int, a : list, b : int):

        # Complete this function

Solutions:
class Solution:

	def solve(self, n: int, a: list, b: int):
		for i in a:
			if i == b:
				b *= 2
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		t = 0
		for i in range(n):
			if a[i] == b:
				t = b + b
				b = t
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		for x in range(n):
			if a[x] == b:
				b *= 2
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		for i in range(len(a)):
			if a[i] == b:
				b = b + b
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		while b in a:
			b *= 2
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		m = set()
		for i in range(n):
			m.add(a[i])
		while b in m:
			b = b * 2
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		for i in range(n):
			if a[i] == b:
				b = b * 2
			else:
				continue
		return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		a.sort()
		i = b
		if i in a:
			while True:
				if i in a:
					i = i * 2
				if i not in a:
					break
			return i
		else:
			return b


class Solution:

	def solve(self, n: int, a: list, b: int):
		i = 0
		for l in a:
			if l == b:
				a[i] = 2 * l
				b = 2 * b
			i += 1
		return b