Skip to content

Commit 22dc44a

Browse files
committed
Add new questions
1 parent b2ee2ed commit 22dc44a

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def max_sum(arr):
2+
max_so_far = arr[0]
3+
curr_max = arr[0]
4+
for i in range(1, len(arr)):
5+
curr_max = max(arr[i], curr_max + arr[i])
6+
max_so_far = max(max_so_far, curr_max)
7+
8+
return max_so_far
9+
10+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
3+
def max_sum(arr):
4+
first = second = third = -sys.maxsize
5+
6+
for i in arr:
7+
if i > first:
8+
third = second
9+
second = first
10+
first = i
11+
elif i > second:
12+
third = second
13+
second = i
14+
elif i > third:
15+
third = i
16+
17+
return first + second + third
18+
19+
20+
arr = [1,3,6,3,6,8,3,3,7,9,4,-1,-1]
21+
22+
print(max_sum(arr))
23+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# The array is sorted in decreasing order
2+
3+
def count(arr):
4+
start = 0
5+
end = len(arr) - 1
6+
7+
while start <= end:
8+
mid = (start + end) // 2
9+
if arr[mid] == 1 and (arr[mid + 1] == 0 or mid == high):
10+
return mid + 1
11+
if arr[mid] == 1:
12+
start = mid + 1
13+
else:
14+
end = mid - 1
15+
return 0
16+
17+
18+
arr = [0,0,0,0]
19+
20+
print(count(arr))

0 commit comments

Comments
 (0)