Haskell, 43 bytes
'['#x=x-1
']'#x=x+1
_#x=x
maximum.scanr(#)0
Usage example: maximum.scanr(#)0 $ "[1, [[3]], [5, 6], [[[[8]]]], 1]"
-> 5
.
Haskell doesn't have mixed lists (Integer
mixed with List of Integer
), so I cannot exploit some list detection functions and I have to parse the string.
Im starting at the right with 0
and add 1 for every ]
, subtract 1 for every [
and keep the valuesvalue otherwise. scanr
keeps all intermediate results, so maximum
can do it's work.