파비의 매일매일 공부기록

2023.05.12 Today's Challenge 본문

Problem Solving/LeetCode

2023.05.12 Today's Challenge

fabichoi 2023. 5. 12. 23:45

https://leetcode.com/problems/solving-questions-with-brainpower/

 

Solving Questions With Brainpower - LeetCode

Can you solve this real interview question? Solving Questions With Brainpower - You are given a 0-indexed 2D integer array questions where questions[i] = [pointsi, brainpoweri]. The array describes the questions of an exam, where you have to process the qu

leetcode.com

전형적인 DP 문제.
이제 한동안 DP만 나오려나

class Solution:
    def mostPoints(self, questions: List[List[int]]) -> int:
        n = len(questions)
        dp = [0] * n
        dp[-1] = questions[-1][0]

        for i in range(n-2, -1, -1):
            dp[i] = questions[i][0]
            skip = questions[i][1]

            if i + skip + 1 < n:
                dp[i] += dp[i+skip+1]
            
            dp[i] = max(dp[i], dp[i+1])
        
        return dp[0]
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

2023.05.14 Today's Challenge  (0) 2023.05.14
2023.05.13 Today's Challenge  (1) 2023.05.13
2023.05.11 Today's Challenge  (0) 2023.05.11
2023.05.10 Today's Challenge  (0) 2023.05.10
2023.05.09 Today's Challenge  (0) 2023.05.09
Comments