Skip to content

Commit

Permalink
Dec 13
Browse files Browse the repository at this point in the history
  • Loading branch information
siddydutta committed Dec 13, 2024
1 parent 94f1526 commit 0205495
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 findScore(self, nums: List[int]) -> int:
nums_idx = [(num, idx) for idx, num in enumerate(nums)]
nums_idx.sort(reverse=True)
score = 0
marked = set()
while nums_idx:
num, idx = nums_idx.pop()
if idx in marked:
continue
score += num
marked.add(idx)
if idx > 0:
marked.add(idx-1)
if idx < len(nums)-1:
marked.add(idx+1)
return score


def main():
nums = [2, 1, 3, 4, 5, 2]
assert Solution().findScore(nums) == 7

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


if __name__ == '__main__':
main()
4 changes: 2 additions & 2 deletions 2024-12-December-LeetCoding-Challenge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
| December 10 | [2981. Find Longest Special Substring That Occurs Thrice I](https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i/) | Medium | Unsolved |
| December 11 | [2779. Maximum Beauty of an Array After Applying Operation](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/) | Medium | Unsolved |
| December 12 | [2558. Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile/) | Easy | Solved |
| December 13 | []() | | |
| December 13 | [2593. Find Score of an Array After Marking All Elements](https://leetcode.com/problems/find-score-of-an-array-after-marking-all-elements/) | Medium | Solved |
| December 14 | []() | | |
| December 15 | []() | | |
| December 16 | []() | | |
Expand All @@ -39,5 +39,5 @@
| Level | Problems | Solved | Unsolved |
| --- | --- | --- | --- |
| Easy | 3 | 3 | 0 |
| Medium | 9 | 6 | 3 |
| Medium | 10 | 7 | 3 |
| Hard | 0 | 0 | 0 |

0 comments on commit 0205495

Please sign in to comment.