In practice easy mode , CLEANUP problem (6 no from last ) my code is giving wrong answer
t = int(input())
while(t):
t=t-1
n,m= map(int,input().split())
tw =[i for i in range(1,n+1)]
l = list(map(int,input().split()))
rw=list(set(tw)-set(l))
print(*rw[0::2],sep =’ ')
print(*rw[1::2],sep = ’ ')
It works for sample input . But giving wrong answer answer. Can any one tell me?
t = int(input())
while(t):
t=t-1
n,m= map(int,input().split())
tw =[i for i in range(1,n+1)]
l = list(map(int,input().split()))
rw=list(set(tw)-set(l))
print(*rw[0::2],sep =’ ')
print(*rw[1::2],sep = ’ ')
Thanks !, I think set change the order of element of “tw” thus giving wrong answer.
can it be better way to subtract 1st list to 2nd list without changing the order of element of 1st list ?
In python sets are not sorted. So you need to sort the sets after performing subtraction. Link to my solution. I hope you will understand after seeing the solution.
You are using set data-structure but you are not using the basic definition of the set i.e. A set is an unordered collection of distinct elements/objects.
Now when you performed the subtraction between the set total_jobs_set - jobs_completed_set, you are left with the set of jobs which are not completed, but the set is unordered, and as per the problem description, chef always chooses an even index job and his assistant always chooses an odd indexed job according to zero-base indexing, so you need to first sort the set to establish the order in the set and then use slice operator [::] to print the answer.
Below is a code for an AC solution for your reference.
def compute_the_assigned_jobs(jobs_set,jobs_completed_set):
jobs_uncompleted_set = jobs_set - jobs_completed_set
jobs_uncompleted_set = sorted(list(jobs_uncompleted_set))
print(' '.join(map(str,jobs_uncompleted_set[0::2])))
print(' '.join(map(str,jobs_uncompleted_set[1::2])))
def main():
for t in range(int(input().rstrip())):
n, m = tuple(map(int,input().rstrip().split()))
jobs_completed_set = set(map(int,input().rstrip().split()))
jobs_set = set([i for i in range(1,n + 1)])
compute_the_assigned_jobs(jobs_set,jobs_completed_set)
if __name__ == "__main__":
main()