// points array reprents the points you can get each day
// goals array is NOT sorted
// get minimum number of days of points you need to meet the goal correspondingly
// input: int[] points = {100, 300, 400, 500, 600}
// int[] goals = {400,200,700,900,1400}
// output: int[] meetGoal = {2, 2, 3, 4, 5}
// explanation: for each element from goal array
// to reach 400, you need at least 100(day 1) + 300 (day 2), which returns 2
// to reach 200, same reason as above
// to reach 700, you need at least 100(day 1) + 300(day 2) + 400(day 3), which returns 3
// to reach 900, you need to have all points 100(day 1) + 300(day 2) + 400(day 3) + 500(day 4), which returns 4
// to reach 1400, you need to have all points 100(day 1) + 300(day 2) + 400(day 3) + 500(day 4) + 600(day 5), which returns 5
// Note: you cannot jump days, even though on day 3 you can score 400 points
// , you still need to get day 1 and day 2's points first before get day 3's point
// required time complexity: O(NlogN) or better.
What is the best solution for this question? I had this solution I dont know wheather my answer is correct.
public static int [] solution(int[] points, int[] goals) {
int [] p_by_days = {100,400,800,1300,1900};
int [] arr = new int[goals.length];
int j = 1;
for(int i = 0; i<goals.length; i++) {
j = 1;
while(goals[i]>p_by_days[j]) {
j++;
}
arr[i] = j+1;
}
return arr;
}
```