Oct-10-2020, 09:39 AM
Task: you are given the number of channels, the number(always even)of logs into each channel, the log itself
For example:
1 #the number of channels
2 #the number of logs
1 4 7 8#log itself, where the number on uneven positions is the time when the channel became busy ,the number on the even position-when the channel became free ( so 1 is when somebody logged into the channel,4-when smb logged out,7-logged in,8-logged out)
You need to write a program which will return the time when all the channel were busy.
Example:
Input:
2
4
1 3 6 9
4
1 2 8 9
Output:
1 2 8 9
Input:
3
4
1 5 7 10
2
3 6
6
1 2 4 6 8 11
Output:
4 5
My idea is to create a list of channels, and insert in that list lists of logs of every channel
For the first example it would be [[1,3,6,9],[1,2,8,9]]. Then write all the numbers between the difference of logged in time ,and logged out time,and place them into the sets. It would become [[(1,2,3),(6,7,8,9)],[(1,2),(8,9)]]. Then intersect every set with others.
Maybe there is an easier solution or more optimal?
For example:
1 #the number of channels
2 #the number of logs
1 4 7 8#log itself, where the number on uneven positions is the time when the channel became busy ,the number on the even position-when the channel became free ( so 1 is when somebody logged into the channel,4-when smb logged out,7-logged in,8-logged out)
You need to write a program which will return the time when all the channel were busy.
Example:
Input:
2
4
1 3 6 9
4
1 2 8 9
Output:
1 2 8 9
Input:
3
4
1 5 7 10
2
3 6
6
1 2 4 6 8 11
Output:
4 5
My idea is to create a list of channels, and insert in that list lists of logs of every channel
For the first example it would be [[1,3,6,9],[1,2,8,9]]. Then write all the numbers between the difference of logged in time ,and logged out time,and place them into the sets. It would become [[(1,2,3),(6,7,8,9)],[(1,2),(8,9)]]. Then intersect every set with others.
Maybe there is an easier solution or more optimal?