Need help regarding this problem | IBM OA
Anonymous User
945

Problem:
image

My solution involved tracking the no of changes over indexes in new array that happed over data indexes by iterating over ranges given in updates array and finally if it was odd we negate it else we do nothing.

It gave TLE for few test cases. Since I just started leetcoding idk from which toic this question belongs to. Can anyone point me to its optimal soln.
EDIT: MY Submission (py3)

def getFinalData (data, updates):
	noOfOps = [0 for x in range(len(data))]
	
	for update in updates:
		lowerBound = update[0] - 1
		upperBound = update[1]
		
		for idx in range(lowerBound, upperBound):
			noOfOps[idx] += 1
	
	for i in range(len(data)):
		if noOfOps[i] % 2 != 0:
			data[i] = -data[i]
			
	return data

Thanks

Comments (7)