Search
⌘K
Get Premium
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.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.