Professional Documents
Culture Documents
WORKSHEET 3.1
Input
First line contains single integer N denoting the number of elements.
Second line contains N space-separated integers A1, A2, ..., AN denoting the elements of array.
Output
In a single line print single integer - the maximal length of subarray with non-zero product.
2. Source Code:
if (array[j] == k):
return j
return -1
array = [1, 3, 5, 7, 9]
k=7
n = len(array)
result = LinearSearch(array, n, k)
if(result == -1):
else:
def bubbleSort(array):
# access each element
for a in range(len(array)):
# compare array elements
for b in range(0, len(array) - a - 1):
# compare
if array[b] > array[b + 1]:
# swapping elements
temp = array[b]
array[b] = array[b+1]
array[b+1] = temp
#driver code
array = [5, 4, 2, 1, 3]
print("The original array is: ", array)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
bubbleSort(array)
print('The Sorted Array is: ', array)
else:
return mid
return -1
if my_result != -1:
print("Element found at index ", str(my_result))
else:
print("Element not found!") def binary_search(my_list, elem):
low = 0
high = len(my_list) - 1
mid = 0
else:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return mid
return -1
if my_result != -1:
print("Element found at index ", str(my_result))
else:
print("Element not found!")
def selection_sort(array):
length = len(array)
for i in range(length-1):
minIndex = i
return array
array = [21,6,9,33,3]
5. Codechef
if len(arr) == 1:
if arr[0] == 0:
count = 0
else:
count += 1
al.append(count)
else:
for j in range(n):
if arr[j] > 0:
count += 1
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if arr[j] == 0:
al.append(count)
count = 0
continue
if j == n - 1:
al.append(count)
max_val = -sys.maxsize - 1
for j in range(len(al)):
if al[j] > max_val:
max_val = al[j]
print(max_val)
3. Screenshot of Outputs:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING