Open
Description
I came across this page https://github.com/codereport/array-language-comparisons/blob/main/comparisons/leetcode/P1614_Max_Paren_Depth.md
For Julia, I'm not too sure what "no row-wise minus reduction" means, but it sounds like you are looking for maximum(cumsum(...
, something like this:
julia> str = "(1)+((2))+(((3)))";
julia> maximum(cumsum([(c=='(')-(c==')') for c in str]))
3
julia> maximum(Iterators.accumulate(+, (c=='(')-(c==')') for c in str)) # lazy version
3
julia> foldl(str; init=(0,0)) do (i,maxi), c
c=='(' && return i+1, max(i+1,maxi)
c==')' && return i-1, maxi
i, maxi
end[2]
3
Metadata
Metadata
Assignees
Labels
No labels