The description of this problem is very confusing and not written properly. So, you have to look into the given test cases and find a pattern.
From deducing the pattern it looks like we are required to find a seat for every student
in a sorted manner with respect to the seats
and add the distance/cost required to switch seats to a result and return that.
Code:
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we are sorting both the
seats
andstudents
which each have a lengthN
. -
Memory
The memory usage is since we are using list comprehension to first generate a list and then sum it.
— A