jeudi 14 juin 2018

Pick random n elements from list1 not present in list2

I would like to pick n elements from list1 that are not present in list2, if there are n such elements. If there are not, only those that are different should be returned or an empty list in the worst case.

Example 1:

  • input: n=2, list1=[0,1,2,3,4,5,6,7], list2=[0,2,4,6]
  • example possible output: [1,5] (other possible outputs: [1,3], [1,7], [3,5], [3,7], [5,7])

Example 2:

  • input: n=5, list1=[0,1,2,3,4,5,6,7], list2=[0,2,4,6]
  • single possible output: [1,3,5,7] since there are only 4 choices and number of elements to choose is 5



Aucun commentaire:

Enregistrer un commentaire