Skip to content

Commit

Permalink
Oct 30
Browse files Browse the repository at this point in the history
  • Loading branch information
siddydutta committed Oct 30, 2024
1 parent 53a845c commit 93099b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import List


class Solution:
def minimumMountainRemovals(self, nums: List[int]) -> int:
dpf = [1] * len(nums)
for i in range(len(nums)-1, -1, -1):
for j in range(i+1, len(nums)):
if nums[i] > nums[j]:
dpf[i] = max(dpf[i], 1+dpf[j])
dpb = [1] * len(nums)
for i in range(len(nums)):
for j in range(i-1, -1, -1):
if nums[i] > nums[j]:
dpb[i] = max(dpb[i], 1+dpb[j])
max_len = 0
for i in range(1, len(nums)-1):
if dpf[i] > 1 and dpb[i] > 1:
max_len = max(max_len, dpf[i]+dpb[i]-1)
return len(nums) - max_len


def main():
nums = [1, 3, 1]
assert Solution().minimumMountainRemovals(nums) == 0

nums = [2, 1, 1, 5, 6, 2, 3, 1]
assert Solution().minimumMountainRemovals(nums) == 3


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions 2024-10-October-LeetCoding-Challenge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
| October 27 | [1277. Count Square Submatrices with All Ones](https://leetcode.com/problems/count-square-submatrices-with-all-ones/) | Medium | Solved |
| October 28 | [2501. Longest Square Streak in an Array](https://leetcode.com/problems/longest-square-streak-in-an-array/) | Medium | Unsolved |
| October 29 | [2684. Maximum Number of Moves in a Grid](https://leetcode.com/problems/maximum-number-of-moves-in-a-grid/) | Medium | Solved |
| October 30 | []() | | |
| October 30 | [1671. Minimum Number of Removals to Make Mountain Array](https://leetcode.com/problems/minimum-number-of-removals-to-make-mountain-array/) | Hard | Unsolved |
| October 31 | []() | | |


Expand All @@ -41,4 +41,4 @@
| --- | --- | --- | --- |
| Easy | 2 | 2 | 0 |
| Medium | 24 | 14 | 10 |
| Hard | 3 | 2 | 1 |
| Hard | 4 | 2 | 2 |

0 comments on commit 93099b9

Please sign in to comment.