We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3ebe48c commit bab0ae5Copy full SHA for bab0ae5
1021-best-sightseeing-pair.js
@@ -10,3 +10,22 @@ const maxScoreSightseeingPair = function(A) {
10
}
11
return res;
12
};
13
+
14
15
+// another
16
17
+/**
18
+ * @param {number[]} A
19
+ * @return {number}
20
+ */
21
+const maxScoreSightseeingPair = function(A) {
22
+ let ans =A[0];
23
+ let prevBestIdx =0;
24
+ for(let j=1;j<A.length;j++){
25
+ ans = Math.max(ans, A[prevBestIdx]+prevBestIdx+A[j]-j);
26
+ if(A[prevBestIdx ]+prevBestIdx <A[j]+j){
27
+ prevBestIdx =j;
28
+ }
29
30
+ return ans;
31
+};
0 commit comments