All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1001_1100.s1014_best_sightseeing_pair.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.28
Show newest version
package g1001_1100.s1014_best_sightseeing_pair

// #Medium #Array #Dynamic_Programming #Dynamic_Programming_I_Day_7
// #2023_05_17_Time_336_ms_(66.67%)_Space_77.2_MB_(16.67%)

class Solution {
    fun maxScoreSightseeingPair(values: IntArray): Int {
        var bestPrevious = values[0]
        var maxSum = 0
        for (i in 1 until values.size) {
            maxSum = maxSum.coerceAtLeast(bestPrevious + values[i] - i)
            bestPrevious = bestPrevious.coerceAtLeast(values[i] + i)
        }
        return maxSum
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy