[Question]
  [
You will be given two Arrays / Lists / Vectors of non-negative integers **A** and **B**. Your task is to output the highest integer **N** that appears in both **A** and **B**, and is also unique in both **A** and **B**. 
* You may assume that there is at least one such number.
* Any [reasonable Input and Output method / format](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods) is allowed.
* [These Loopholes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in every programming language wins!
---
Test Cases:
```
A, B -> Output
[6], [1, 6] -> 6
[1, 2, 3, 4], [4, 5, 6, 7] -> 4
[0, 73, 38, 29], [38, 29, 73, 0] -> 73
[1, 3, 4, 6, 6, 9], [8, 7, 6, 3, 4, 3] -> 4
[2, 2, 2, 6, 3, 5, 8, 2], [8, 7, 5, 8] -> 5
[12, 19, 18, 289, 19, 17], [12, 19, 18, 17, 17, 289] -> 289
[17, 29, 39, 29, 29, 39, 18], [19, 19, 18, 20, 17, 18] -> 17
[17, 29, 39, 29, 29, 39, 18, 18], [19, 19, 18, 20, 17, 18] -> 17
```
  
[Answer]
# [Python 3](https://docs.python.org/3/), 61 56 54 bytes
Saved 7 bytes thanks to [@Mr.Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder), [@pizzapants184](https://codegolf.stackexchange.com/users/44694/pizzapants184) and [@ovs](https://codegolf.stackexchange.com/users/64121/ovs)
```
lambda a,b:max(f*(a.count(f)==b.count(f)<2)for f in a)
```
[Try it online!](https://tio.run/##TVDbDoIwDH2Wr@gjM41hTB0Q@RIkZqiLJAoGMNGvx3YDMdmy051Lmz4/w61t1Gjz43g3j@piwGCVPcw7tOvQbM7tqxlCK/K8@uFDLGzbgYW6ASPG4doPp7Pprz3kUASrotiXCIVE2Jclck0wRlAIWya2CDviEPRERwSJVAnJUlZ45H@jJYMDnJGO05FMu8ozapLGrl08M9SM8xYDf8yppJLUSbIiSadCu/n/KKn9Jcls1H5Elfp3xjJx3vQvNpr8rmcZ8Ore@OHlLZvLgtWzq3m7IXFCjF8 "Python 3 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
fċ@ÐṂ;Ṁ
```
[Try it online!](https://tio.run/##hU67DcIwEO09xQ1wEv4EbIuGNZCVEgqUBegQLQ1bMEPqsEgmMfeJRbpItu7d@9zd7TIM91qv39dpes/j8ziPjzp9/O5cazFQDj1CcQhUjQCPEBA6pjuEPSkIUURLgKSQyJRZV6SsbXkOS4ieuMgUpVMliNHLIt94WsOz/nYmdCJ5HO1wrKe8NFGuXkku6ieLxqKeFrLWhl2SZF4NtUs6bQQ3wqb/AQ "Jelly – Try It Online")
### How it works
```
fċ@ÐṂ;Ṁ  Main link. Left argument: A. Right argument: B
f        Filter; keep those elements of A that appear in B.
   ÐṂ    Yield all elements of the result for which the link to left yields a
         minimal value (2).
 ċ@        Count the occurrences of the element...
     ;     in the concatenation of A and B.
      Ṁ  Take the maximum.
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + coreutils, 49 bytes
```
U()(sort -rn|uniq -u$1)
(U<<<$1;U<<<$2)|U D|sed q
```
*Thanks to @seshoumara for golfing off 1 byte!*
[Try it online!](https://tio.run/##S0oszvj/P1RDU6M4v6hEQbcor6Y0L7NQQbdUxVCTSyPUxsZGxdAaTBlp1oQquNQUp6YoFP7//9/QnMvIksvYEkRCGIYWQPTfEMgAs40MuIBqQAwA "Bash – Try It Online")
### How it works
*uniq* takes sorted input and performs one or several actions, depending on the command-line flags.
`U<<<$1` and `U<<<$2` call the function `U` with the first and second command-line argument as input. For each one, `sort -rn|uniq -u` is executed, sorting the input numerically (`-n`) and in descending order (`-r`) for *uniq*, which will print only unique lines (`-u`).
The output of both (unique elements of each array) is concatenated and piped to `U D`, i.e.,  
`sort -rn|uniq -uD`. This time, *uniq* will only print duplicate lines (`-D`), and only the first repetition of each.
While the man page says it will print all repetitions, the added `-u` causes `-D` to print only the first occurrence of duplicated lines. This behavior is normally achieved with `uniq -d`.
Finally, `sed q` quits immediately, reducing its input (unique elements of both arrays) to its first line. Since the output was sorted in descending order, this is the maximum.
[Answer]
# Pyth, ~~12~~ 9 bytes
[Try it](https://pyth.herokuapp.com/?code=eS%40Fm.m%2Fd&input=[1%2C+3%2C+4%2C+6%2C+6%2C+9]%2C+[8%2C+7%2C+6%2C+3%2C+4%2C+3]&debug=0)
```
[[email protected]](/cdn-cgi/l/email-protection)/d
```
Saved 3 bytes thanks to Mr. Xcoder.
### Explanation
```
[[email protected]](/cdn-cgi/l/email-protection)/d
    m  /d   Count the occurrences of each element.
     .m     Take only those that appear the minimum number of times.
  @F        Apply the above to A and B and take the intersection.
eS          Take the largest.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~9~~ 8 bytes
-1 byte thanks to [Erik the Outgolfer](https://codegolf.stackexchange.com/users/41024/erik-the-outgolfer)
```
εÐ¢Ï}`Ãà
```
[Try it online!](https://tio.run/##MzBNTDJM/f//3NbDEw4tOtxfm3C4@fCC//@jDc11FIwsdRSMLSE0jG1oEcsVbQhigDlACQMgbQ6WAAA "05AB1E – Try It Online")
```
ε   }    # For each input
 Ð¢Ï     #   Get the unique elements
     `Ã  # Keep only the elements that appear in both lists
       à # Keep the greatest element
         # Implicit print
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
→►≠OfEΠ
```
Takes input as a list of two lists, works for any number of lists as well (returning the highest number that occurs exactly once in each, if possible).
[Try it online!](https://tio.run/##dY49CgIxFIR7T7GlwhT52c3PAaw9QEgrgti4eAAtBFsL6z2FhaUH8BC5SHwviQiCJOQNM9/wsjmM29zt5mM6HfeL5z2n8zXdHukyrdbL15RzDsFEBAkT4yzQVNDoyekxwMAWV8BqaAflKSiTDdEaxBNpwKGDJcWOLqkCH3YGUK8RpGtXQXpICpwvyvJXPqa0fCmqrOW12vNbhXRM@0Z3SpSG@0v/FL78Gw "Husk – Try It Online")
## Explanation
This is the first Husk answer to (ab)use the new "maximum by" function `►`.
```
→►≠OfEΠ  Implicit input, say [[3,2,1,3],[1,2,3,4]]
      Π  Cartesian product: [[3,1],[2,1],[3,2],[2,2],[1,1],[3,3],[1,2],[3,1],[3,4],[2,3],[1,3],[3,2],[2,4],[3,3],[1,4],[3,4]]
    fE   Keep those that have equal elements: [[2,2],[1,1],[3,3],[3,3]]
   O     Sort: [[1,1],[2,2],[3,3],[3,3]]
 ►≠      Find rightmost element that maximizes number of other elements that are not equal to it: [2,2]
→        Take last element: 2
```
[Answer]
# Bash + coreutils, 60 bytes
```
f()(sort -rn<<<"$1"|uniq -u);grep -m1 -wf<(f "$1") <(f "$2")
```
[Try It Online](https://tio.run/##S0oszvj/P01DU6M4v6hEQbcoz8bGRknFUKmmNC@zUEG3VNM6vSi1QEE311BBtzzNRiNNASSrqQBhGSlp/v//39Ccy4jLyJLL2BJEQhiGFkD03xDIALONDLiAqkAMAA)
# Bash, 89 bytes
```
c()(for e;{((e^$1||r++,2^r));});for x in $1 $2;{((x<r))||c $x $1||c $x $2||r=$x;};echo $r
```
[TIO](https://tio.run/##JYuxCsMwDER3f4UGDTbpUKlDG9T@SiAxLunSgLsY6ny7KjVwHA/u3TJ/VtUcU3xuFYp8YywTUu91GE481ZRkT@Jbg9cbkADZpXa3qfcM2MD1A9h@D2yyS8nrBlhVla6BA4/hMnofQDeLksGf@RzMcvgB)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
ċ@Ị¥Ðf`€f/Ṁ
```
[Try it online!](https://tio.run/##y0rNyan8//9It8PD3V2Hlh6ekJbwqGlNmv7DnQ3///@PjjbUUTDWUTDRUTADI8tYHYVoCx0FczAPImMcGwsA "Jelly – Try It Online")
[Answer]
# J, 23 bytes
```
>./@([-.-.)&(-.-.@~:#])
```
`(-.-.@~:#])` removes from a list any repeated elements
`&` do this to both args
`([-.-.)` We want A intersect B. This is the equivalent phrase: "A minus (A minus B)"
`>./` Take the max
[Try it online!](https://tio.run/##hUzLCsIwELz3KwYF24KNaWKbpFDpf4gnMYgXDz3rr9fZRMSDIJvNzs5jb0ucMQ7QYC8HtZuqY6MaVW8qGdNzWJ/qpS5WCmUchxJbPAbEuSgu5@sde4xoYWCJIrtDD5clZ6lpGdbDBMp5ktDfYYn2LHF4OCJhbLZ0tJhUQnc0mLeNOFuMD3LHoA1ofVoFOfo@JDc@SjlCPCYiwAb5M6AxpkA@pFPM/4v8Ti0v "J – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 94 bytes
```
param($a,$b)filter f($x){$x|group|?{$_.count-eq1}}
(f($a|sort|?{$_-in((f $b).Name)}))[-1].Name
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVRRyVJMy0zpyS1SCFNQ6VCs1qloia9KL@0oMa@WiVeLzm/NK9EN7XQsLaWSwOoILGmOL@oBCynm5mnoZGmANSv55eYm6pZq6kZrWsYC@b8///fQcPQXEfByFJHwdgSQsPYhhaaIFkQC8wDyhgAaXOwDAA "PowerShell – Try It Online")
Takes input `$a` and `$b` as arrays. Constructs a `filter` that `group`s the input array elements together and pulls out only those with a `count` `-eq`ual to `1` (i.e., only those that are unique in the input array).
The next line then constructs the algorithm. First we `sort` `$a`, then pull out those that are `-in` the unique items of `$b`. Those are then themselves unique-ified, the largest `[-1]` is chosen, and we take the `.Name` thereof. That's left on the pipeline and output is implicit.
[Answer]
# Java 8, 133 bytes
```
a->b->{long r;for(java.util.Collections c=null;;a.remove(r))if(b.contains(r=c.max(a))&c.frequency(a,r)*c.frequency(b,r)==1)return r;}
```
**Explanation:**
[Try it here.](https://tio.run/##xZNBb8IgGIbv/gpOCyyVWHWzprbJsmSn7uRx2QERTR1CB9TNGH@7@6g1mmUna7OEBvpRHt73ha7YhnV1IdRq/nHgklmLXlmudh2ErGMu52gFX9DS5ZIuSsVdrhV9qQeT89yTMWyb5dZNMq2WaXDtsqpLEUcJOrBuOuumOwklZOKFNvi88FlLKSqaRTxRpZRxzKgRa70R2BCSL/CMcq0cmLHYJJyu2TdmhNxxujDisxSKbzELDLm/LMygkCQhMcKVRsGu@0MMUUArypmENOpQNjqfozWw8dSZXC3f3hEjPjSEplvrxJrq0tECppxUmFNWFHKLlfhCf3lP8a@qpcz6GfyYEUKuXh1mQQUg8e2VAbufBYMsGDaSOMyCB68yGLUltAdskDmIQPC4kdYaUeF6LeZaheozgdZMceRz9ZgjctCW6H51GfqnreBEfVQ3kF6R2koa9IZwnKHXGo3rl1GzP@6CCajq8ey2LIyON3IwPvancRg1czG@SKZXO4n@wUTLRvad/eEH)
```
a->b->{                  // Method with two ArrayList<Long> parameters and long return-type
  long r;                //  Result-long
  for(java.util.Collections c=null; 
                         //  Create a java.util.Collections to save bytes
      ;                  //  Loop indefinitely
       a.remove(r))      //    After every iteration, remove the current item
    if(b.contains(r=c.max(a)) 
                         //   If the maximum value in `a` is present in `b`,
       &c.frequency(a,r)*c.frequency(b,r)==1)
                         //   and this maximum value is unique in both Lists:
      return r;          //    Return this value
                         //  End of loop (implicit / single-line body)
}                        // End of method
```
[Answer]
# Javascript (ES6), 102 86 75 71 bytes
```
a=>b=>Math.max(...a.map(e=>(g=x=>x.map(y=>y-e||x--,x=1)|!x)(a)*g(b)*e))
```
Thanks @justinMariner for getting from 102 to 86
Thanks @tsh for getting from 86 to 75
Thanks @Arnauld for getting from 75 to 71
[Try it online!](https://tio.run/##nVDdboIwFL7fU3R3rSmEtrhCTHkDn8DsorrK3FSIGFMS3p2d02pmNnYxE@Cc0@/vlA97sd3mtGvPSdfu3tzp0Bw/XT9uzWhNtTbV0p7f04P1NE1TC01LnalobbypfBh7U/WJGwafJNwbwYZnz6hls5qu2cwxNm6aY9fsXbpvarqlq5dXRleCE6jwYYunHzhAkhPFSY7EnJM50DjRSM9/0zOAgKwKkJWoiF08zVCk1WQIJgRneIIQdDpMEVF/BMqwn7wxYTsM/DbAA5TOJ1JBJWA1gYqivA46/JA7SOj4AgWNoExY6XhLVcZ660UR3Mq7oOzqGLYS@j9eD/pxyRVXKJQ8D1dgi/EL "JavaScript (SpiderMonkey) – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~57~~ 53 bytes
```
x?y|let v!x=filter(==v)x==[v]=maximum[a|a<-x,a!x,a!y]
```
[Try it online!](https://tio.run/##fYrPCoJAGMTvPsXXTUEj62CKi4dOQT7B4uED11raP7JtsoLvvq1G1waGmeE3D3w9mRCey1EbCxetrNFi32qFvXfNvAhmYdo5MnBhmYkJmRJHCJ06ItFx@ZYUF6wzl@Ju9dx5iVwBgV5HEOSgzkDwwbZgGPZwZ/bGFdvY/IeNhisLsYMm3KoKrsomnuZFCscyhVP5zV/Pz11E87VsI4BDyGIDHw "Haskell – Try It Online")
**UPD:** Thanks @Laikoni
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 40 bytes
```
Max@Cases[Tally@#⋂Tally@#2,{x_,1}:>x]&
```
[Try it online!](https://tio.run/##hY@9CsIwFIX3PkVAcMrQtLVpBaVQcBMc3EqRIIqF/kB/oBLawdW39EXiTZNInQoJubnnO@cmBWsft4K12ZWJe1fuxJH1UcyaW5OcWZ4/o9Xn/dKVg3l/wWTY7vt0LU51VrZRXOVdUR6quki4hRD3hxFiRk4w8gcsO1A5GLkYeVryMNqAihFVgA0VyG4AYKgZdVGC/cuRIZMTliEBpFNDia6CnWmoYwSYJwP/LLKnk4EjMIxIJgj1hZqfzFRC1QZKW6l6pxuq09QkMO5wlm3rhGDJvBxgDan4Ag "Wolfram Language (Mathematica) – Try It Online")
# How it works
`Tally@#` gives a list of the unique elements of the first input, together with their counts: e.g., `Tally[{2,2,2,6,3,5,8,2}]` yields `{{2,4},{6,1},{3,1},{5,1},{8,1}}`.
`Tally@#2` does the same for the second list, and `⋂` finds pairs present in both. Then we pick out (with `Cases`) pairs ending in `1`, taking the first element of each result, which gives us a list of all the unique twins. Finally, `Max` returns the largest unique twin.
[Answer]
# [SQLite](https://www.sqlite.org/), 118 bytes
```
SELECT MAX(x)FROM(SELECT X FROM A GROUP BY X HAVING COUNT(X)=1
INTERSECT
SELECT X FROM B GROUP BY X HAVING COUNT(X)=1)
```
[Try it online!](https://tio.run/##rZGxbsMgFEVn8xV3BInFdRK3ijqAQ1JUDBHGkf0BGSJ1qZLBf@/gqqqUxgodOnLveYDOO39@nC7HsfJKBIUgpFEQlADQm0zbgL3XtfA93lWfWRdgW2P41A9Tnf1khK0J0bZRPiAWDgJUbzgGhoMwrWpAc448Uo@hJ44iCRUciyS04FgloeVfoBXHSxIqOcrJwY1K@S8q5ZzK518/knMqyyRU3AuQcyqLJLS8X4qcU5m@qfyCxkYZVQXUoqMD23pX0@@kw3SKO9h51@4h@5i8iYO2O1SutYF27DWPbwTlm8iT2zH5cIyN4xU "SQLite – Try It Online")
First time in SQL, any help is welcome!
[Answer]
# [Röda](https://github.com/fergusq/roda), 48 bytes
```
{m={|n|sort|count|[_]if[_=n]};[_()|m 1]|m 2|max}
```
[Try it online!](https://tio.run/##JcZBCsMgEADAc/KKPSrsJWnTQIsvsYtIi9SDGoyBgOvbbaGXYXJ62x6sj1DHwcFdwbPXoCpH3lMu/EpHLKwNeaeNitQe2gjJASb6MXOwZ@vDln0sYjv2j9ATznjBKy64EOr/brjiShIYnJBybP0L "Röda – Try It Online")
Inspired by [jq170727's jq answer](https://codegolf.stackexchange.com/a/147110/66323).
Explanation:
```
{ /* Anonymous function, takes input from the stream */
  m={|n|        /* Local function m with parameter n: */
    sort|count| /*   Count unique values in the stream */
    [_]if[_=n]  /*   For each value, push it to the stream if its count is n */
  };
  [      /* For each list in the stream: */
    _()| /*   Flat it (push its values to the stream) */
    m 1  /*   Push values that appear only once to the stream */
  ]|
  m 2|   /* Push values that appear twice to the stream */
  max    /* Find the max value in the stream */
}
```
[Answer]
# [F# (.NET Core)](https://www.microsoft.com/net/core/platform), ~~117~~ ~~115~~ ~~114~~ ~~111~~ 108 bytes
## ~~115~~ 114 bytes
Another solution with `countBy` this time:
```
let u x=x|>Seq.countBy id|>Seq.filter(fun a->snd a=1)|>Seq.map fst|>set
let f x y=Set.intersect(u x)(u y)|>Seq.max
```
[Try it online!](https://tio.run/##PY7NCoMwEITvfYqhUIgHBe3fIcRDX8Fj6UE0CwEbrVkhQt/drgqFZWHmY4ahkDb9aJfOMkIOg2euUWicNS4ad7nXYWPFysS6atxWd0tMiCZ@y8p@sqafPD9muHbX5Dq2o6LJo07L4FvUJk929q4HRYFFBctbPSFiNpXlzHmJBduwkvJE3vwPxWUYBZPH8eSOULQuDkWy/AA "F# (.NET Core) – Try It Online")
## ~~117~~ 111 bytes
```
let u x=x|>Seq.filter(fun a->x|>Seq.filter((=)a)|>Seq.length=1)|>set
let f x y=Set.intersect(u x)(u y)|>Seq.max
```
[Try it online!](https://tio.run/##ZY7LCoMwEEX3/YqLUDALBdPXIo0/4bJ0oTJpBU1bEyFC/91ObHeFYWDO4c6McVn7GGnpycMV0LgUClJhp7BXOHFdN6uT0TE6KBwjXRMTgg7vsqJXbrre05iayaLOyn/YZGWja/HlPdmbv58lj478esAgYNYV@byznHHU@pTXC27zLzXUYXmOrI1Fsu0SpCb@7KRYPg "F# (.NET Core) – Try It Online")
100% F#! Any help is welcome!
6 byte won thanks to prefix notation!
## 108 bytes
```
let f a b=Set.intersect(set a)(set b)|>Seq.filter(fun x->a@b|>Seq.filter(fun y->y=x)|>Seq.length<3)|>Seq.max
```
`@` is the concat function! Thank you @Ayb4btu for this algorithm.
[Try it online!](https://tio.run/##ZY7LCsIwEEX3fsWlIDSLFtr6WMQG/6FLcZGWiRZq1CZCCv57TEJ3wsAw58wwV5lieM7kJ7IwFVpcKo6ao@HYcRxDXTfJ1dEFtOc4RJouFCT6tiNbjtrSbGiwuQlcstR69hUdvUs1TsHm6qPhCiHP/R9eCrG0bl2fSN/s/dSs40M6/5rDA6WRbccMuYpRTc38Dw "F# (.NET Core) – Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), ~~85~~ 84 bytes
```
x=>y=>x.Where(a=>x.Count(b=>b==a)<2).Intersect(y.Where(a=>y.Count(b=>b==a)<2)).Max()
```
[Try it online!](https://tio.run/##pZJRb4IwFIWf11/RR2oqCihIEF5MliyZyZI9@EB4QFY3ElcyWjeJ4be7tiiIUzFZAvS099yvl@QkrJ9kOdkPeqEdYRgaGNoR7AfQBlKbGFoYjmRlhOFYFDF0VH0EwqHQompNhM@VlkpVp0PlciyFkQzVKx7lFEZH7aqKdUSa6krzWBIXSmTTIQ@Udyy4wmaI2wxpmbiHjaP@4qRkONUrLKpTrKLXqSa13Go9amOi2t0T8vCAqO41nFvN9wF6A7BhKX2HrwXj5NNr7fTnlH55IFnHjMGXHWA85mkCv7P0Dc7jlGoI7MDjhibTlPIwwidSfIMArny4L/xgKx598UFyosVSzrIN5drSD5a@H6OpifQnyknOSMK1ojEWf41In8dbDe09AB5mGWXZmuiLPOVETEq0lUbJDwyjnV0iKaXCRomQd9PdZKtuawLW2d1KXg1oxe@eCVqxrDHn2ewkXQ7tGU@eds90OdI16kquu7lXE9ugL0b2H@R76SUo978 "C# (.NET Core) – Try It Online")
Naive solution with LINQ (`using System;using System.Linq;` +31chars so 116 bytes with header)
84! I forgot currying!
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~17~~ 16 bytes
```
MX{_Na=_Nb=1FIa}
```
This is a function that takes two lists as arguments. [Try it online!](https://tio.run/##K8gs@K/x3zeiOt4v0TbeL8nW0M0zsfZ/tKGCsYKJghkQWsYqRFsomANZIBHjWC7N/wA "Pip – Try It Online")
### Explanation
```
  {            }  Define function, args are a & b:
            FIa    Filter elements of a on this function:
   _Na              Count of element in a
      =_Nb          equals count of element in b
          =1        equals 1
                  This gives a function that returns a list of unique twins
MX                Modify it to take the max and return that instead
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 18 chars = 23 bytes\*
A full program body. Prompts for list of lists from STDIN. Works with any number of lists. Outputs to STDOUT.
```
⌈/∊∩/{⊂⍺⍴⍨1=≢⍵}⌸¨⎕
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKO9tOT/o54O/UcdXY86VupXP@pqetS761Hvlke9KwxtH3UuetS7tfZRz45DKx71TQWp/68ABqUlXEABr2B/P/XoaLNYHYVoQx0Fs9hYdS4s8kApIx0FYx0FE5BCEx0FU6BaHQVzHMoNgFJAxcYWQG2WIB0QFkTUALcdIAvABgMRWB9QmzmYB5ExxqHVCOw8I5hKoONA9iEMAAngshWoyxDoMkOQDgtLKMccHB5IUobmEAxUgssgc4gXjS0hNIxtaAE2yxLJGgOoeRYkG0XQOAA "APL (Dyalog Unicode) – Try It Online")
`⎕` prompt for evaluated input from STDIN
`{`…`}⌸¨` for each list, call the following function for each unique element in that list, using the unique element as left argument (`⍺`) and the list of indices of its occurrence as right argument (`⍵`):
 `≢⍵` the tally of indices (i.e. the number of occurrences)
 `1=` equal to 1
 `⍺⍴⍨` use that to reshape the specific element (i.e. gives empty list if non-unique)
Now we have two lists of unique elements for each input list (although each element is a list, and there are empty lists as residue from the non-unique elements).
`∩/` intersection (reduction)
`∊` **ϵ**nlist (flatten)
`⌈/` max (reduction)
---
\* in Classic, counting `⌸` as `⎕U2338`.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 13 bytes
```
,iSY'1=)]X&X>
```
[Try it online!](https://tio.run/##y00syfn/XyczOFLd0FYzNkItwu7//2hDcx0FI0sdBWNLCA1jG1rEckUbghhgDlDCAEibgyUA) Or [Verify all test cases](https://tio.run/##fU69CsIwEN59ikwW4YZcUr1k0Mk3qEOlFHQUdPP943e5VMShkHD3/XKv@/tZboUew7Xj424et@OpnC9lOsybicm1EchFcj1AT24PmpwAeAzwMcGRgW0x0ltSY9WPpxY4pAITIqhQ@8PCol5rvl7F2gUDo5tVTLkB@VNY7MOhitg9Mdtcdq6F@afQt2haTa0nPw).
### Explanation
```
,      % Do twice
  i    %   Take input: array
  S    %   Sort array
  Y'   %   Run-length encode: pushes array of values and array of run lengths
  1=   %   Compare each run length with 1
  )    %   Use as logical index. This keeps only values that have appeared once
]      % End
X&     % Intersection of the two arrays
X>     % Maximum of array. Implicitly display
```
[Answer]
# PHP, 98 bytes
```
<?foreach(($c=array_count_values)($_GET[a])as$a=>$n)$n-1||$c($_GET[b])[$a]-1||$a<$r||$r=$a;echo$r;
```
Provide arrays as GET parameters `a` and `b`.
[Answer]
# [R](https://www.r-project.org/), 73 bytes
```
function(A,B)max(setdiff(intersect(A,B),c(A[(d=duplicated)(A)],B[d(B)])))
```
[Try it online!](https://tio.run/##NY3NCsIwEITvPkWOu7CCscGYoof0NUoPJT8Q0ChtCr59TFKFhZnZ@ZZdsme3Y/ZbNCm8Imga8Dl/YHXJBu8hxOSW1ZnUGjKgR7B3u70fwczJWQSNEw2jhQEnRMweDPBeVFT0EvHQFpLYWRHr1K5/z6@V49W1VJpTUdma32khiQlilzaqHhROtrQ3XXn7BQ "R – Try It Online")
Computes `A` intersect `B`, then the maximum of the difference between that and the duplicated elements of `A` and `B`.
[Answer]
# JavaScript ES5, ~~122~~ ~~121~~ 114 bytes
```
function f(a,b){for(i=a.sort().length;--i+1;)if(a[i]!=a[i+1]&&a[i]!=a[i-1]&&!(b.split(a[i]).length-2))return a[i]}
```
I'm new here, so I don't really know if I can remove the function definition and just put its contents (which would save me 17 bytes)
Here's the working example: ~~[122](https://tio.run/##lVDdaoMwFL7fU6Q3bYJRjNpGEZ9EvFBn2xRJiqbbxdizu3NMLWVzsIEm@fL9Hb3Ub/XYDupqfW1eu2k63nRrldHkSGvesI@m2O28JldFHYxmsJQFfadP9py/n1XfUd9XnmAKxKWqNgWsnqi22wfyEW1oE4zXXtlZtST4EWNDZ2@DJnj9ObVGj6bvgt6c6JGWh4qXgpNDxWBh@cs3GqiIk5iTBHQJJ3tQcSJRnfxUh0CBNk7BlYHBHdxliB4Zr1Zg/hwMD/rAJmfgiPiXumgeLlqUMBv2PfyI0blf6QSTgMEEGtLsDiT@iydGSPeCAnNgW0mS7hPjzO3LWaQYlj3VhPfAeSYh/xP1p7jpCw)~~ ~~[121](https://tio.run/##lVDdaoMwFL7fU6Q3bYJRjNpGEZ9EvFCnbYYkRdPdjD27O8fUUjYHG2iSL9/f0bf6vZ7aUV2tr81rN8/9TbdWGU16WvOGffRmpE1xOHgNV0UdTGa0lAVDp8/2kvu@8kTOFGhLVe0KWD1R7fcP5CPa0SaYroOyi2o1@xFjY2dvoyZ4/Tm3Rk9m6ILBnGlPy1PFS8HJqWKwsPzlGw1UxEnMSQK6hJMjqDiRqE5@qkOgQBun4MrA4A7uMkSPjDcrMH8Jhgd9YJMLcET8S120DBetSpgN@x5@xOg8bnSCScBgAg1pdgcS/8UTI6R7QYE5sG0kSfeJceb29SxSDMueasJ74DKTkP@J@lPc/AU)~~ [114](https://tio.run/##lZBBboMwEEX3PYWzSWzFIAwkBqGcBLEgFBJXyI7A6SbK2el4HNqopVIrge3xvP//wFv9Xo/NoC420Oa1nabuqhurjCYdrfmR3TozUHWow9EMlrKwb/XJnosgUFtRMAVQqarVAdatqNbrzypw1Yoew/HSK4vULA5ixobWXgdN3PV9aoweTd@GvTnRjpb7im9Kwcm@2jBYWfHyDYBezEnCSerIlJMdYJxI5NOffAQ9oJMMdLmT@JO/jVAlk8UYl4He8KAShBIr30l@i4xxxHhGYUAX@eXgLlC7W8gFmYDphJNk@aOQ@FeeWkL6FxB0gn3BS/ovTXK/z2eRoV3@lBQ9LP1cQv7H7I@G0wc)
122 to 121 bytes: Wrapping initialization in a for
121 to 114 bytes: `b` has to be a string
[Answer]
# [Jq 1.5](https://stedolan.github.io/jq/), 76 bytes
```
def m(n):[.[indices(.[])|select(length==n)[]]]|unique[];[map(m(1))|m(2)]|max
```
Expanded
```
def m(n): # function to emit elements of multiplicity n
  [
    .[                         # select elements with
         indices(.[])          # number of indices in the array
       | select(length==n)[]   # equal to specified multiplicity
    ]
  ] | unique[]                 # emit deduped values
;
[
    map(m(1))   # collect multiplicity 1 elements from each array
  | m(2)        # collect multiplicity 2 elements
] | max         # choose largest of these elements
```
[Try it online!](https://tio.run/##hY/NboQgEIDvfQqSXiDBjYgr2mb7IoSD2aWtG0W3QtoDz147wOpuL22icX6@@WY8XxYpK0WRZBRVCoJHlL2g6kGGQkERp6gM7ZKiPRAUiQ0qAcqhAAivAW4Cl6JUzTdU8CQMtmiBJ@JAi5ilDv8lL@IFxdqH/UF@GwuFbWAfNgDLYDkLXN1cExF/767FRHoB2cYhDgKRrudN@q4xq6OjudPnV8/tAib@NPxnQX7VLCf9igZsyJPcyc6cuqOe8U4q4mfd66PFvTZv9v1wMEQqpbwz3cVpqZ7l0E54wIwQP@CCKD@0X8vyPU62G828ZJlxfZ91ZnIWko/2MxudheQH "jq – Try It Online")
Here is another solution which is the same length:
```
def u:[keys[]as$k|[.[$k]]-(.[:$k]+.[$k+1:])]|add;map(u)|.[0]-(.[0]-.[1])|max
```
Expanded
```
def u: # compute unique elements of input array
  [
      keys[] as $k                   # for each index k
    | [.[$k]] - (.[:$k]+.[$k+1:])    # subtract other elements from [ .[k] ]
  ]                                  # resulting in [] if .[k] is a duplicate
  | add                              # collect remaining [ .[k] ] arrays
;
  map(u)                             # discard duplicates from each input array
| .[0]-(.[0]-.[1])                   # find common elements using set difference
| max                                # kepp largest element
```
[Try it online!](https://tio.run/##hY/daoMwFIDv9xSB9aLSRIyxRh3sRQ65CNhBZ6tuGtpBnn3ZSVJtd7OBmvPznS/H9w8HUCpKgFNSKgyeCXsl5RP4Qk6JoKTw7YKSPRKUyBUqEMqwgIioEK49F6NYzVZUiij0tmDBJ@BIy5DFjvglz8MG@dLH@738PuYL68De34Asx8u556r6lsjwew8tLuOLyDqOsRfIuL2o47nEvAqO@kGf3Tz3Dbj80/CfhdhF49rDGzENdIevCZSeNp2FFDadUmybQoPBzqc73qhEWd22L2c9bk1iU8gCgt8UuErsWV@d@x7G@Tj0k2OsN6cTO/ajmTH51Bc2mBmTHw "jq – Try It Online")
[Answer]
# APL, 47 bytes
```
{1↑R[⍒R←((1={+/⍵=A}¨A)/A←⍺)∩(1={+/⍵=B}¨B)/B←⍵]}
```
Declares an anonymous function that takes two vectors, eliminates duplicate elements, then finds the biggest element in the intersection of the results.
`A←⍺` and `B←⍵` store the arguments passed to the function in `A` and `B`.
`a=b` returns a vector with 1 in each index in which `a` is equal to `b`. If `a` is a scalar (i.e. single quantity and not a vector) this returns a vector with 1 wherever the element in `b` is `a` and 0 when it is not. For example:
```
Input: 1=1 2 3
Output: 1 0 0
```
`{+/⍵=A}`: nested anonymous function; find the occurrences of the argument in vector `A` and add them up i.e. find the number of occurrences of the argument in `A`
`1={+/⍵=A}¨A`: apply the nested anonymous function to each element in A and find the ones that equal 1 i.e. unique elements
`((1={+/⍵=A}¨A)/A←⍺)`: having found the *location* of the unique elements, select just these elements in the original vector (`/` selects from the right argument elements whose locations correspond to 1 in the left argument)
`R←((1={+/⍵=A}¨A)/A←⍺)∩(1={+/⍵=B}¨B)/B←⍵`: repeat the process for the second argument; now that we have just the unique elements, find the intersection i.e. common elements and store this in vector `R`
`R[⍒R]`: access the elements of `R` in decreasing order
`1↑R[⍒R]`: take the first element of `R` when it's sorted in decreasing order
Test case:
```
Input: 17 29 39 29 29 39 18 18 {1↑R[⍒R←((1={+/⍵=A}¨A)/A←⍺)∩(1={+/⍵=B}¨B)/B←⍵]} 19 19 18 20 17 18
Output: 17
```
[Answer]
# [J](http://jsoftware.com/), 30 bytes
```
[:>./@,[*([*+/"1(1=*/)+/)@(=/)
```
How it works:
I start with testing where the two list overlap by `=/` (inserts equality test between all the members of the lists:
```
   a =. 1 3 4 6 6 9
   b =. 8 7 6 3 4 3
   ]c=. a =/ b 
0 0 0 0 0 0
0 0 0 1 0 1
0 0 0 0 1 0
0 0 1 0 0 0
0 0 1 0 0 0
0 0 0 0 0 0
```
More than one 1 in the same column means that the number is not unique for the left argument (6 in this case); in the row - for the right argument (3)
Then I sum up all rows and all columns to find where are the duplicates:
```
   +/ c
0 0 2 1 1 1
   +/"1 c
0 2 1 1 1 0
```
I find the cartesian product of the above lists and set the members greater than 1 to 0. 
```
    m =. (+/"1 c) (1=*/) +/c
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 1 1 1
0 0 0 1 1 1
0 0 0 1 1 1
0 0 0 0 0 0
```
I mask the equality matrix c with m to find the unique elements that are common to both lists and multiply the left argument by this.
```
]l =. a * m * c
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 4 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
```
Then I flatten the list and find the max element:
```
 >./,l 
4
```
[Try it online!](https://tio.run/##fU45DsMgEOz9ipEbnzKXbQ6JyP9wGQVFaVK4ztvJAnYXRQvL7BzAK4YD3oGDdtzdbWLbuPft3g@sFq3wPesG1m2tZ13sqnpCE7xrMOLjEI7qcX@@sSJAYC2DgITCTNSMhSRdaA6toAykJaWcRPArkxIrVVINNKHEqCLLXIlaSJSnhfCZlhAWghRjM9LpPxdJEy2STrNOTyubegHkCdlb7uA5Yf64fwfiFw "J – Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 66+31=97 65+31=96 bytes
```
a=>b=>a.Intersect(b).Where(x=>a.Concat(b).Count(y=>y==x)<3).Max()
```
[Try it online!](https://tio.run/##pZBRa4MwFIWfl1@RxwTupGpbFasvhcFghcE2@lD6kGZhC3SRmrhair/dJQ5t@7SWYTD3nuR@5xCu73lRirbSUn3gl4M24itF5533JNUuRXzLtMbPR6QNM5Ljh0rxmVRmtYaL2m55jt@U3FXidS@VxhluWZZvspx5j8qIUgtuyIZ6y09RClI7fV4ozjpxXlTKkEOWH7KsprOQegtWE9qmqDf@LuQ7XjCpCEVHdGdHdbEV3rKURtiogpx5EyX2q/Vx2tC@Ar@hNL1uzIcAQhgPw2OYwBSi6wEjiEIIYwiSgdF1Th7dksOmsM5TOHFiiGzv9PB6UADuc2MTsDkuYFa5IVEAfgK@ZcRJV0UDazjyI7fshRuwkXucMHH/38KPT@Ck9xx17Ph/3L/RDWraHw "C# (.NET Core) – Try It Online")
+31 bytes for `using System;using System.Linq;`
I took inspiration from @aloisdg's answer. However, instead of searching for unique values in both arrays, I inverted the order of operations so that `intersect` is first, and then find the max value of the items that occur twice when the arrays are concatenated and are in their intersect. I can use `<3` as `Count` will be at least 2 for any value, as it will be in both arrays.
### Acknowledgements
-1 byte thanks to @aloisdg and his suggestion to use `Func` currying.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~57~~ 56 bytes
```
@(x)max(intersect(cellfun(@(x){x(sum(x'==x)==1)},x){:}))
```
Anonymous function that takes as input a cell array of two numerical arrays.
[**Try it online!**](https://tio.run/##hY5BCoMwEEX3PcXsmkAQY6yJhUDvIS5EFAraQtUSEM@eThK17oSEzMx//0/e9Vh9G9vqKIrsgxjaV4Y8X2PzGZp6JHXTde30Ik6ZDRmmnpir1oZqzenCcHhfKLUtmYushIJDVi704lrOIGEgGKQlgyJlcGOQMZCbHmONqlDI5Q4JVZjGhxQX4a14PIic9F1QxMYmfmOySbjPJf4dbrDnIsZxGXeIytdGOvgocRkuIrtThm@KPLxbzZU354fceA1Q595Tv/0B "Octave – Try It Online")
### Explanation
For each (`cellfun(@(x)...)`) of the two input arrays, this creates a matrix of pairwise equality comparisons between its entries (`x.'==x`); keeps (`x(...)`) only the entries for which the column sum is `1` (`sum(...)==1`); and packs the result in a cell (`{...}`). The intersection (`intersect`) of the two results (`{:}`) is computed, and the maximum (`max(...)`) is taken.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 49 bytes
```
Last@Select[a=Join@##;Sort[#⋂#2],a~Count~#<3&]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2ar8d8nsbjEITg1JzW5JDrR1is/M89BWdk6OL@oJFr5UXeTslGsTmKdc35pXkmdso2xWqzaf01rroCizLwSh7ToakMjHQVDSyC20FEwsrCEcsxrdRRQpAzNIRiopDb2PwA "Wolfram Language (Mathematica) – Try It Online")
]