commit c3c87694aba7a3eb60ac0287ed7d07b8548081b7 parent 5bfd5701a7cb83bb1633ab6d6c156fcb8b052102 Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Thu, 11 May 2023 22:43:23 -0500 Completed solving questions problem using dart Diffstat:
| A | solving-questions-with-brainpower/solving-questionsV3.dart | | | 35 | +++++++++++++++++++++++++++++++++++ |
1 file changed, 35 insertions(+), 0 deletions(-)
diff --git a/solving-questions-with-brainpower/solving-questionsV3.dart b/solving-questions-with-brainpower/solving-questionsV3.dart @@ -0,0 +1,35 @@ +//This is a constant time solution that moves from right to left. +//each time it moves it figures out where the next question it would answer is +//then based on that it uses the points associated with that place to continue moving to the left +//thus building upon previous calculations +//Runtime: 584ms Beats: 100% +//Memory: 227.2MB Beats: 100% +class Solution { +int mostPoints(List<List<int>> questions) { + int max = 0; + List<int> current_val = []; + for(int i = 0 ; i < questions.length ; ++i){ + current_val.add(0); + } + for(int i = questions.length - 1; i >= 0; --i){ + if(current_val.length > questions[i][1] + i + 1){ + int new_val = questions[i][0] + current_val[questions[i][1] + i + 1]; + if(new_val > max){ + max = new_val; + current_val[i] = max; + } + else{ + current_val[i] = current_val[i + 1]; + } + } + else{ + if(questions[i][0] > max){ + max = questions[i][0]; + } + current_val[i] = max; + } + } + return max; + } + +}