We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def min_operations(n, boxes):
# Separate the balls in each box
for i in range(1, n):
for j in range(3):
if boxes[i][j] != boxes[0][j]:
boxes[i][j] = boxes[0][j]
# Count the total number of operations
operations = 0
for i in range(n):
for j in range(3):
if boxes[i][j] != boxes[0][j]:
operations += 1
return operations
Input reading
n = int(input()) # Number of boxes
boxes = [list(map(int, input().split())) for _ in range(n)] # List of boxes
Get the result
result = min_operations(n, boxes)
Run this Python code and input the number of boxes along with the colors of balls in each box. It will output the minimal number of operations required to separate the balls. Moreover, for debugging apply update from adb and then run this python code.
Print the result
print(result)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Operations
You are viewing a single comment's thread. Return to all comments →
def min_operations(n, boxes): # Separate the balls in each box for i in range(1, n): for j in range(3): if boxes[i][j] != boxes[0][j]: boxes[i][j] = boxes[0][j]
Input reading
n = int(input()) # Number of boxes boxes = [list(map(int, input().split())) for _ in range(n)] # List of boxes
Get the result
result = min_operations(n, boxes) Run this Python code and input the number of boxes along with the colors of balls in each box. It will output the minimal number of operations required to separate the balls. Moreover, for debugging apply update from adb and then run this python code.
Print the result
print(result)