This programming assignment requires you to implement two fu
Solution
Here is the code :
#!/usr/bin/python
# Function definition is here
def free_time_interval( array, endTime ):
intervals = []
# Creating a list and making all values to be 0.
for index in range(0,endTime):
intervals.append([])
intervals.append(0);
#based on start time and end time , initializing the previosuly created list with 1
# so if an index contains 1 it means a user logged in at that time and if it is 0 then no one logged in
for row in range(0,len(array)):
startInt = array[row][0]
if(array[row][1] >= endTime):
endInt = endTime
else:
endInt = array[row][1]
while(startInt <= endInt):
intervals[startInt].append(1)
startInt = startInt+1
# Printing the values based on 1 and 0
count = 0
for rows in range(0,len(intervals)):
if(intervals[rows][0] == 0):
if(count%2 == 0):
print(rows , \"\ \")
else:
print(rows, \", \",rows+1)
count = count+1
# Now you can call changeme function
array = []
array.append([])
array.append([])
array[0].append(1)
array[0].append(2)
array[1].append(3)
array[1].append(7)
free_time_interval( array, 5 )
Output would be:
0,1
