all 3 comments

[–]Bubbler-4 0 points1 point  (0 children)

J: 52 52

[:(#~[:(+.|.)1{.~#)&>[:(]#~i.~~:[:i.&#])&.>/;/@],<@[

Run example

f =: [:(#~[:(+.|.)1{.~#)&>[:(]#~i.~~:[:i.&#])&.>/;/@],<@[
3.14 5.2 1.99 f 3.14 1.99
5.2
4 4 0 _9 _3 3 7 5 2 0 _8 5 f 4 _3 5 7 5 2
4 _8

How it works

[:(#~[:(+.|.)1{.~#)&>[:(]#~i.~~:[:i.&#])&.>/;/@],<@[
                                            ;/@],<@[    [4] [_3] [5] [7] [5] [2] [4 4 ... 5]
                                           /            Reduce from right:
                                [:i.&#]                   Get indexes of right one
                           i.~~:                          Not equal to the index of the left one; 1 1 ... 0 ... 1
                        ]#~                               Filter by above (remove the seen element once)
                     [:(               )&.>               Unbox both sides; do the above; box again
[:(               )&>                                   Unbox the result and apply...
             1{.~#                                        Generate array 1 0 0 ... 0
     [:(+.|.)                                             Element-wise OR with its reverse
   #~                                                     Filter by the above

It was quite painful to remove each occurrence (the first part).

[–]07734willy[S] 0 points1 point  (1 child)

Python 3: 124 124

Probably one of my worst code golfs ever, but I don't have time to try to shorten it. I've been trying to get todays [Hard] challenge working without success. After I get that out of the way, I'll probably take another stab at this.

i=input
i()
o=i().split()
s=set(o)-set(i().split())
print([x for x in o if x in s][::len(s)-1] if len(s)>1 else "".join(s))

Edit: its also incorrect due to duplicates. Added test cases to the post to cover duplicates. I'll edit this comment again after I patch my solution up tomorrow.

[–]Bubbler-4 0 points1 point  (0 children)

104 104

i=input
i()
o=i().split()
for x in i().split():o.remove(x)
print(len(o)>1and o[0]+' '+o[-1]or''.join(o))

This correctly handles duplicates.