Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,487 views
in Online Assessments by Expert (34,270 points) | 1,487 views

2 Answers

0 like 0 dislike

My Solution

 

def func(locations, movedFrom, movedTo):
	locations = set(locations)
	for i,j in zip(movedFrom,movedTo):
		locations.remove(i)
		locations.add(j)
	return sorted(list(locations))

 

Initially I came up with similar solution but with list itself. Then It started giving TLE errors. Then I thought of using set and it worked.

by Expert (34,270 points)
0 like 0 dislike

Question-1
Amazon stores its data on different servers at different locations. From time to time, due to several factors, Amazon needs to move its data from one location to another. This challenge involved keeping track of the locations of Amazon's data and report them at the end of the year.

 

At the start of the year, Amazon's data was located at n different locations. Over the course of the year, Amazon's data was moved from one server to another m times. Precisely, in the ith operation, the data was moved from movedFrom[i] to movedTo[i]. Find the locations of the data after all m moving operations. Return the locations in ascending order.

 

Note: It is guaranteed that for any movement of data: 4

 

There is data at movedFrom[i].

 

There is no data at movedTo[i].

 

Example

 

locations = [1, 5, 2, 6]
movedFrom = [1, 4, 5, 7]
movedTo = [4, 7, 1,3]
output = [1, 2, 3, 6]

by Expert (34,270 points)