comefrom: <doocs>2055.Plates Between Candles_1.py
code: def platesBetweenCandles( s: str, queries: List[List[int]]) -> List[int]:
      n = len(s)
      presum = [0] * (n + 1)
      for i, c in enumerate(s):
          presum[i + 1] = presum[i] + (c == '*')
      
      left, right = [0] * n, [0] * n
      l = r = -1
      for i, c in enumerate(s):
          if c == '|':
              l = i
          left[i] = l
      for i in range(n - 1, -1, -1):
          if s[i] == '|':
              r = i
          right[i] = r
      
      ans = [0] * len(queries)
      for k, (l, r) in enumerate(queries):
          i, j = right[l], left[r]
          if i >= 0 and j >= 0 and i < j:
              ans[k] = presum[j] - presum[i + 1]
      return ans
masked: def sample_funcname ( var_0 : str , var_1 : List [ List [ int ] ] ) -> List [ int ] :
      var_2 = len ( var_0 )
      var_3 = [ 0 ] * ( var_2 + 1 )
      for var_4 , var_5 in enumerate ( var_0 ) :
          var_3 [ var_4 + 1 ] = var_3 [ var_4 ] + ( var_5 == '*' )
      var_6 , var_7 = [ 0 ] * var_2 , [ 0 ] * var_2
      var_9 = var_8 = - 1
      for var_4 , var_5 in enumerate ( var_0 ) :
          if var_5 == '|' :
              var_9 = var_4
          var_6 [ var_4 ] = var_9
      for var_4 in range ( var_2 - 1 , - 1 , - 1 ) :
          if var_0 [ var_4 ] == '|' :
              var_8 = var_4
          var_7 [ var_4 ] = var_8
      var_10 = [ 0 ] * len ( var_1 )
      for var_11 , ( var_9 , var_8 ) in enumerate ( var_1 ) :
          var_4 , var_12 = var_7 [ var_9 ] , var_6 [ var_8 ]
          if var_4 >= 0 and var_12 >= 0 and var_4 < var_12 :
              var_10 [ var_11 ] = var_3 [ var_12 ] - var_3 [ var_4 + 1 ]
      return var_10
  