kucheasysa

Algoverse_adesh_15

Jun 11th, 2024
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. class Solution:
  2.     def minOperations(self, boxes: str) -> List[int]:
  3.         a = [0]*len(boxes)
  4.         count1, cost1, count2, cost2, n = 0, 0, 0, 0, len(boxes)
  5.         for i in range(1, n):
  6.             if boxes[i-1] == '1': count1 += 1
  7.             cost1 += count1
  8.             a[i] = cost1
  9.         for j in range(n-2, -1, -1):
  10.             if boxes[j+1] == '1': count2 += 1
  11.             cost2 += count2
  12.             a[j] += cost2
  13.         return a
Advertisement
Add Comment
Please, Sign In to add comment