Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Problem Statement 1/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
n = int(input())
if not n&1:
print("True")
else:
print("False")
10 changes: 10 additions & 0 deletions Problem Statement 2/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
n = int(input())
prev=[1,1,1,1,1]
ans=[1,1,1,1,1]
for i in range(n-1):
s=0
for j in range(4,-1,-1):
s=s+prev[j]
ans[j]=s
prev=ans.copy()
print(sum(ans))
16 changes: 16 additions & 0 deletions Problem Statement 3/3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
A = list(map(int,input().split()))
k = int(input())
L = len(A)
memo = [ 0 for _ in range(k) ]
for i in range(L-1,-1,-1):
m, best = 0, 0
for j in range(i,min(L,i+k)):
if A[j] > m:
m = A[j]
s = (j-i+1)*m + memo[(j+1)%k]
if s > best:
best = s

memo[i%k] = best

print(memo[0])
9 changes: 4 additions & 5 deletions Problem Statement 3/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Problem Statement-3

***
---

### Question

Given an integer array arr, partition the array into (contiguous) subarrays of length at most k. After partitioning, each subarray has their values changed to become the maximum value of that subarray.
Expand All @@ -13,22 +14,20 @@ Input: arr = [1,15,7,9,2,5,10], k = 3
Output: 84
Explanation: arr becomes [15,15,15,9,10,10,10]


Example 2:

Input: arr = [1,4,1,5,7,3,6,1,9,9,3], k = 4
Output: 83


Example 3:

Input: arr = [1], k = 1
Output: 1


Constraints:

1 <= arr.length <= 500
0 <= arr[i] <= 109
1 <= k <= arr.length
***

---