You are given an array arr[], you have to re-construct an array arr[].
The values in arr[] are obtained by doing OR(bitwise or) of consecutive elements in the array.
Example 1:
Input : arr[ ] = {10, 11, 1, 2, 3}
Output : 11 11 3 3 3
Explanation:
At index 0, arr[0] or arr[1] = 11
At index 1, arr[1] or arr[2] = 11
At index 2, arr[2] or arr[3] = 3
...
At index 4, No element is left So, it will 
remain as it is.
New Array will be {11, 11, 3, 3, 3}.
Example 2:
Input : arr[ ] = {5, 9, 2, 6} 
Output :  13 11 6 6 
 
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function game_with_number() that takes an array (arr), sizeOfArray (n), and return the array re-constructed array arr. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
 
Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ arr[i] ≤ 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Starter code: #User function Template for python3



def game_with_number (arr,  n) : 

    #Complete the function

Solutions:
def game_with_number(arr, n):
	for i in range(n - 1):
		arr[i] = arr[i] | arr[i + 1]
	return arr


def game_with_number(arr, n):
	l = []
	for i in range(len(arr) - 1):
		l.append(arr[i] | arr[i + 1])
	l.append(arr[-1])
	return l


def game_with_number(arr, n):
	if n <= 1:
		return arr
	else:
		for i in range(0, n - 1):
			arr[i] = arr[i] | arr[i + 1]
		return arr


def game_with_number(arr, n):
	l = []
	for i in range(n):
		if i + 1 < n:
			l.append(arr[i] | arr[i + 1])
		else:
			l.append(arr[i])
	return l


def game_with_number(arr, n):
	res = [0] * n
	res[n - 1] = arr[n - 1]
	for i in range(0, n - 1):
		res[i] = arr[i] | arr[i + 1]
	return res


def game_with_number(arr, n):
	b = []
	for i in range(n - 1):
		c = arr[i] | arr[i + 1]
		b.append(c)
	b.append(arr[n - 1])
	return b


def game_with_number(arr, n):
	l = arr[-1]
	for i in range(n - 1):
		arr.append(arr[i] | arr[i + 1])
	arr.append(l)
	for i in range(n):
		arr.pop(0)
	return arr


def game_with_number(arr, n):
	a = []
	for i in range(n - 1):
		a.append(arr[i] | arr[i + 1])
	a.append(arr[-1])
	return a


def game_with_number(arr, n):
	arr1 = []
	for i in range(n - 1):
		arr[i] = arr[i] | arr[i + 1]
		arr1.append(arr[i])
	arr1.append(arr[n - 1])
	return arr1


def game_with_number(arr, n):
	res = [arr[index] | arr[index + 1] for index in range(n - 1)]
	res.append(arr[-1])
	return res


def game_with_number(arr, n):
	li = []
	for i in range(n - 1):
		li.append(arr[i] | arr[i + 1])
	li.append(arr[-1])
	return li


def game_with_number(arr, n):
	list1 = []
	for i in range(0, n - 1):
		list1.append(arr[i] | arr[i + 1])
	list1.append(arr[-1])
	return list1


def game_with_number(arr, n):
	l = []
	s = 0
	while s != n - 1:
		l.append(arr[s] | arr[s + 1])
		s += 1
	l.append(arr[len(arr) - 1])
	return l


def game_with_number(arr, n):
	y = arr[n - 1]
	for i in range(n - 1):
		x = arr[i] | arr[i + 1]
		arr[i] = x
	arr[n - 1] = y
	return arr


def game_with_number(arr, n):
	l = [arr[n - 1] for _ in range(n)]
	for i in range(n - 1):
		l[i] = arr[i] | arr[i + 1]
	return l


def game_with_number(arr, n):
	for i in range(0, len(arr) - 1):
		arr[i] = arr[i] | arr[i + 1]
	return arr


def game_with_number(arr, n):
	ans = [0] * n
	for i in range(n - 1):
		ans[i] = arr[i] | arr[i + 1]
	ans[-1] = arr[-1]
	return ans


def game_with_number(arr, n):
	l1 = []
	for i in range(len(arr) - 1):
		arr[i] = arr[i] | arr[i + 1]
	return arr


def game_with_number(arr, n):
	i = 0
	ans = []
	while i + 1 < n:
		ans.append(arr[i] | arr[i + 1])
		i = i + 1
	ans.append(arr[len(arr) - 1])
	return ans


def game_with_number(arr, n):
	count = 0
	while count < n - 1:
		arr[count] |= arr[count + 1]
		count += 1
	return arr


from functools import reduce

def game_with_number(arr, n):
	l = [arr[i] | arr[i + 1] for i in range(0, n - 1)]
	l += [arr[-1]]
	return l


def game_with_number(arr, n):
	arrf = []
	for i in range(n - 1):
		arrf.append(arr[i] | arr[i + 1])
	arrf.append(arr[-1])
	return arrf


def game_with_number(arr, n):
	z = []
	for i in range(n - 1):
		z.append(arr[i] | arr[i + 1])
	z.append(arr[-1])
	return z


def game_with_number(arr, n):
	for x in range(n - 1):
		arr[x] |= arr[x + 1]
	return arr


def game_with_number(arr, n):
	list_1 = []
	for i in range(n):
		if 0 <= i < n - 1:
			val = arr[i] | arr[i + 1]
			list_1.append(val)
		elif i == n - 1:
			list_1.append(arr[i])
	return list_1


def game_with_number(arr, n):
	for i in range(0, n - 1):
		x = arr[i] | arr[i + 1]
		arr[i] = x
	return arr