diff --git a/Problem Statement 1/1.py b/Problem Statement 1/1.py new file mode 100644 index 0000000..34da514 --- /dev/null +++ b/Problem Statement 1/1.py @@ -0,0 +1,5 @@ +n = int(input()) +if not n&1: + print("True") +else: + print("False") \ No newline at end of file diff --git a/Problem Statement 2/2.py b/Problem Statement 2/2.py new file mode 100644 index 0000000..bff42b8 --- /dev/null +++ b/Problem Statement 2/2.py @@ -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)) \ No newline at end of file diff --git a/Problem Statement 3/3.py b/Problem Statement 3/3.py new file mode 100644 index 0000000..5732c15 --- /dev/null +++ b/Problem Statement 3/3.py @@ -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]) \ No newline at end of file diff --git a/Problem Statement 3/README.md b/Problem Statement 3/README.md index b711c79..0d88979 100644 --- a/Problem Statement 3/README.md +++ b/Problem Statement 3/README.md @@ -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. @@ -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 -*** + +---