Question: Translate this code from Python to Java. def countOfFinalStateIndices(operations): ranges = defaultdict(lambda: [0,0]) start = float('inf') end = float('-inf') for left, right in operations: ranges[left][0]
Translate this code from Python to Java.
def countOfFinalStateIndices(operations): ranges = defaultdict(lambda: [0,0]) start = float('inf') end = float('-inf') for left, right in operations: ranges[left][0] += 1 ranges[right][1] += 1 start = min(start, left) end = max(end, right) onBulbs = 0 sumOfOnIndices = 0 for i in range(start, end+1): onBulbs += ranges[i][0] if onBulbs % 2 != 0: print("Bulb number", i,"is on.") sumOfOnIndices += i onBulbs -= ranges[i][1] return sumOfOnIndices operations = [[1,4],[2,6], [1,6]] print(countOfFinalStateIndices(operations))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
