Search
⌘K

Leetcode 2606. Find the Substring With Maximum Cost

Map each character in s to an integer value (use vals when the char appears in chars, otherwise its 1-indexed alphabet position). Then find the maximum contiguous subarray sum (empty substring allowed, so result ≥ 0) — solvable with Kadane's algorithm in O(n).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.