[Question]
  [
Surprisingly we haven't had a simple "find the highest digit" challenge yet, but I think that's a *little* too trivial.
Given input of a non-negative integer, return the highest **unique** (ie not repeated) digit found in the integer. If there are no unique digits, your program can do anything (undefined behaviour), other than the numbers that are non unique in the input of course.
The input can be taken as a single integer, a string, or a list of digits.
## Test cases
```
12         -> 2
0          -> 0
485902     -> 9
495902     -> 5
999999     -> Anything
999099     -> 0
1948710498 -> 7
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so fewest bytes **in each language** wins!
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~4~~ 3 bytes
Saved 1 byte thanks to *Mr. Xcoder* notifying that a digit list is valid input.
```
¢ÏM
```
[Try it online!](https://tio.run/##MzBNTDJM/f//0KLD/b7//0eb6ChY6iiYgkkDHQWjWAA "05AB1E – Try It Online")
**Explanation**
```
¢     # count occurrences of each digit in input
 Ï    # keep only the digits whose occurrences are true (1)
  M   # push the highest
```
[Answer]
# [Python 3](https://docs.python.org/3/), 40 bytes
Saved 2 bytes thanks to [movatica](https://codegolf.stackexchange.com/users/86751/movatica).
```
lambda i:max(x*(i.count(x)<2)for x in i)
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHTKjexQqNCSyNTLzm/NK9Eo0LTxkgzLb9IoUIhM08hU/N/QVEmUDhNQ93Q0sTC3NDAxNJCXVNTQUHZnAsuZWJhamlgBBYGAWVLhJQBXBQiZYCQsrS0NLC0ROhClbJElgr1c3F18/RzdfkPAA "Python 3 – Try It Online")
### 42 bytes
Works for both String and list of digits parameter types. Throws an error for no unique digits, kind of abuses of that spec:
```
lambda i:max(x for x in i if i.count(x)<2)
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHTKjexQqNCIS2/SKFCITNPIVMhM00hUy85vzSvRKNC08ZI839BUSaQnaahbmhpYmFuaGBiaaGuqamgoGzOBZcysTC1NDACC4OAsiVCygAuCpEyQEhZWloaWFoidKFKWSJLhfq5uLp5@rm6/AcA "Python 3 – Try It Online")
---
## Explanation
* `lambda i:` - Declares a lambda function with a string or list of digits parameter i.
* `max(...)` - Finds the maximum value of the generator.
* `x for x in i` - Iterates through the characters / digits of `i`.
* `if i.count(x)<2` - Checks if the digit is unique.
[Answer]
## [Alice](https://github.com/m-ender/alice), 15 bytes
```
/&.sDo
\i-.tN@/
```
[Try it online!](https://tio.run/##S8zJTE79/19fTa/YJZ8rJlNXr8TPQf//f0NLEwtzQwMTSwsA "Alice – Try It Online")
### Explanation
```
/...
\.../
```
This is a simple framework for linear code that operates entirely in Ordinal mode (meaning this program works completely through string processing). The unfolded linear code is then just:
```
i..DN&-sto@
```
What it does:
```
i    Read all input as a string.
..   Make two copies.
D    Deduplicate the characters in the top copy.
N    Get the multiset complement of this deduplicated string in the input.
     This gives us a string that only contains repeated digits (with one
     copy less than the original, but the number of them doesn't matter).
&-   Fold string subtraction over this string, which means that each of
     the repeated digits is removed from the input.
s    Sort the remaining digits.
t    Split off the last digit.
o    Print it.
@    Terminate the program.
```
[Answer]
## [Retina](https://github.com/m-ender/retina), 16 bytes
```
O`.
(.)\1+
!`.$
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7w3z9Bj0tDTzPGUJuLSzFBT@X/f0MjLgMuEwtTSwMjLhNLMGVpaWlgacllaGliYW5oYGJpAQA "Retina – Try It Online")
### Explanation
```
O`.
```
Sort the digits.
```
(.)\1+
```
Remove repeated digits.
```
!`.$
```
Fetch the last (maximal) digit.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 18 12 bytes
```
Ｆχ¿⁼№θＩι¹ＰＩι
```
[Try it online!](https://tio.run/##NclLCoAgEADQq7icAQUFIaWltOwQEkgDkvnr@lObtu8dZ2xHiZk5lSbAaBSUBGx1xtwhlHkNqDLEPoAQpUEU@8yD7kbf/L4yG2/dYrT1jtXDqucX "Charcoal – Try It Online") (Link to verbose version)
Prints nothing if no solution is found. The trick is that the `for` loop prints every unique number in the input string, but without moving the cursor, thus the value keeps reprinting itself until the final solution is found.
The previous version printed the characters A to Z when no solution was found, hence the comments:
```
ＡααＦχＡ⎇⁼№θＩι¹Ｉιααα
```
[Try it online!](https://tio.run/##S85ILErOT8z5/9@xuDgzPU8jUUchUdOaKy2/SEHD0EBTASocklqUl1hUqeFaWJqYU6zhnF@aV6JRqOOcWFyikampqWOoqaMA5egkgpA1V0BRJlANkPX/v6GliYW5oYGJpcV/3bL/usU5AA "Charcoal – Try It Online") (Link to verbose version)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
→fo¬hgO
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8dC2/4/aJqXlH1qTke7///9/QyMuAy4TC1NLAyMuE0swZWlpaWBpyWVoaWJhbmhgYmkBEgECAA "Husk – Try It Online") (Test suite, crashes on the last test case since it has no unique digits)
This is a composition of functions in point-free style (the arguments are not mentioned explicitely anywhere). Takes input and returns output as a string, which in Husk is equivalent to a list of characters.
### Explanation
```
Test case: "1948710498"
      O    Sort:                             "0114478899"
     g     Group consecutive equal elements: ["0","11","44","7","88","99"]
 fo¬h      Keep only those with length 1*:   ["0","7"]
→          Take the last element:            "7"
```
\*The check for length 1 is done by taking the head of the list (all elements except the last one) and negating it (empty lists are falsy, non-empty lists are truthy).
[Answer]
## JavaScript (ES6), ~~46~~ ~~41~~ 40 bytes
Takes input as a string. Returns RangeError if there are no unique digits.
```
s=>f=(i=9)=>s.split(i).length-2?f(--i):i
```
-7 bytes thanks to Rick Hitchcock
-1 byte thanks to Shaggy
### Test cases
```
let f =
s=>g=(i=9)=>s.split(i).length-2?g(--i):i
console.log(f("12")())         // 2
console.log(f("0")())          // 0
console.log(f("485902")())     // 9
console.log(f("495902")())     // 5
//console.log(f("999999")())   // RangeError
console.log(f("999099")())     // 0
console.log(f("1948710498")()) // 7
```
[Answer]
## Haskell, 37 bytes
```
f s=maximum[x|x<-s,[x]==filter(==x)s]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02h2DY3sSIztzQ3uqKmwka3WCe6ItbWNi0zpyS1SMPWtkKzOPZ/bmJmnoKtQkFRZl6JgopCmoKSoaWJhbmhgYmlhdJ/AA "Haskell – Try It Online")
How it works:
```
  [  |x<-s   ]          -- loop x through the input string s
    x                   -- and keep the x where
     [x]==filter(==x)s  -- all x extracted from s equal a singleton list [x]
maximum                 -- take the maximum of all the x
```
[Answer]
# [R](https://www.r-project.org/), 41 bytes
```
function(x,y=table(x))max(names(y[y==1]))
```
An anonymous function that takes a list of digits, either as integers or single character strings. It precomputes `y` as an optional argument to avoid using curly braces for the function body. Returns the digit as a string. This takes a slightly different approach than [the other R answer](https://codegolf.stackexchange.com/a/128874/67312) and ends up being the tiniest bit shorter! looks like my comment there was wrong after all...
`table` computes the occurrences of each element in the list, with `names(table(x))` being the unique values in `x` (as strings). Since digits are fortunately ordered the same lexicographically as numerically, we can still use `max`.
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP0@jQqfStiQxKSdVo0JTMzexQiMvMTe1WKMyutLW1jBWU/N/mkayhomOqY4xGFoCobmOOVAcAA "R – Try It Online")
[Answer]
# Python 3, 40 bytes
```
lambda i:max(x+9-9*i.count(x)for x in i)
```
Only works for lists of digits. The edge case '990' works fine :)
[Try it online!](https://tio.run/##dc9NCsIwEAXgvacYyCbRqaSttR3Bk6iLqAQD9odSIZ4@piBttenMbvh4vGne3aOuUqePZ/dU5fWuwBxKZbndUERrs73Vr6rjVui6BQumAiNc0xp/0/wUY3IRAgLDIFkNTC6gnsmR7bDADAnlLJUBTRktsmxkhMPOWJTu/6EMwkm72IO@YY6xx32J4ssZ5L9p4X99mvsA)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 3 bytes
```
►≠O
```
[Try it online!](https://tio.run/##yygtzv7//9G0XY86F/j///8/2kTHUscUiA10jGIB "Husk – Try It Online")
## Explanation
```
►≠O
  O order the elements
►   max by
 ≠  inequality(selects least frequent elements)
    then returns the last of the least frequent elements
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
ọtᵒtᵍhth
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r//@Hu3pKHWycBcW9GScb//4aWJhbmhgYmlhb/owA "Brachylog – Try It Online")
### Explanation
```
Example input: 495902
ọ          Occurences:    [[4,1],[9,2],[5,1],[0,1],[2,1]]
 tᵒ        Order by tail: [[0,1],[2,1],[4,1],[5,1],[9,2]]
   tᵍ      Group by tail: [[[0,1],[2,1],[4,1],[5,1]],[[9,2]]]
     h     Head:          [[0,1],[2,1],[4,1],[5,1]]
      t    Tail:          [5,1]
       h   Head:          5
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 10 chars = 19 bytes
Method: multiply elements that occur multiple times by zero, and then fine the highest element.
```
⌈/×∘(1=≢)⌸
```
`⌸` for each unique element and its indices in the argument:
 `×` multiply the unique element
 `∘(`…`)` with:
  `1=` the Boolean for whether one is equal to
  `≢` the tally of indices (how many times the unique element occurs)
`⌈/` the max of that
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@NR24RHPR36h6c/6pihYWj7qHOR5qOeHUCJQys0DBWMNBU0dAyAhImChYKpgqWCAVjIBMhC8CwV4BDOM4DyDIE0SK@5giFQDKTPQhMA "APL (Dyalog Unicode) – Try It Online")
# [APL (Dyalog Classic)](https://www.dyalog.com/), 15 bytes
```
⌈/×∘(1=≢)⎕U2338
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v8/41HbhEc9HfqHpz/qmKFhaPuoc5Hmo76poUbGxhZA2UMrNAwVjDQVNHQMgISJgoWCqYKlggFYyATIQvAsFeAQzjOA8gyBNEivuYIhUAykz0ITAA "APL (Dyalog Classic) – Try It Online")
Identical to the above, but uses `⎕U2338` instead of `⌸`.
[Answer]
## [Husk](https://github.com/barbuz/Husk), ~~9~~ 8 bytes
*Thanks to Leo for suggesting a slightly neater solution at the same byte count.*
```
▲‡ȯf=1`#
```
[Try it online!](https://tio.run/##yygtzv7//9G0TY8aFp5Yn2ZrmKD8//9/JUNLEwtzQwMTSwslAA "Husk – Try It Online")
### Explanation
```
  ȯ       Compose the following thre functions into one binary function.
      `#  Count the occurrences of the right argument in the left.
    =1    Check equality with 1. This gives 1 (truthy) for values that 
          appear uniquely in the right-hand argument.
   f      Select the elements from the right argument, where the function
          in the left argument is truthy.
          Due to the composition and partial function application this
          means that the first argument of the resulting function actually
          curries `# and the second argument is passed as the second
          argument to f. So what we end up with is a function which selects
          the elements from the right argument that appear uniquely in
          the left argument.
 ‡        We call this function by giving it the input for both arguments.
          So we end up selecting unique digits from the input.
▲         Find the maximum.  
```
[Answer]
# Mathematica, 41 bytes
```
(t=9;While[DigitCount[#][[t]]!=1,t--];t)&
```
thanks @Martin Ender
here is Martin's approach on my answer
# Mathematica, 35 bytes
```
9//.d_/;DigitCount[#][[d]]!=1:>d-1&
```
[Answer]
## R, ~~45~~ 43 bytes
`function(x)max(setdiff(x,x[duplicated(x)]))`
[Try it online!](https://tio.run/##K/r/P802rTQvuSQzP0@jQjM3sUKjOLUkJTMtTaNCpyK6PCMzOUMjpbQgJzM5sSQ1BahEM1ZTkytNI1nDRMdUxxgMLYHQXMdcU/P/fwA)
Takes input as a vector of integers. Finds the duplicated elements, removes them, and takes the maximum. (Returns `-Inf` with a warning if there is no unique maximum.)
Edited into an anonymous function per comment
[Answer]
# [Python 2](https://docs.python.org/2/), 39 bytes
```
lambda l:max(1/l.count(n)*n for n in l)
```
[Try it online!](https://tio.run/##VYzNCoMwEITP@hRzTEqwiViqgk9iPdgfMRDXIJG2T59KAraFWZj5hh37duNMuR@aizf9dL33MPXUv5g6muw2r@QY8QNhmBcQNMFw/xy1eUDVaWIaTXZ1jKeJXTQ5DGzrWyWQd2krtysESoGTQCUgIy5C@ENVCF/9IrkjFVxcPAuo0MW1cv@Q3Qc "Python 2 – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 42 bytes
```
->x{(?0..?9).select{|r|x.count(r)==1}[-1]}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf166iWsPeQE/P3lJTrzg1JzW5pLqmqKZCLzm/NK9Eo0jT1tawNlrXMLb2f4FCWrS6oaWJhbmhgYmlhXosF1jExMLU0sAIxjOAMSwtLQ0sLZF4liDefwA "Ruby – Try It Online")
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + coreutils, ~~30~~ 28 bytes
-2 bytes thanks to [Digital Trauma](https://codegolf.stackexchange.com/users/11259/digital-trauma)
```
fold -1|sort|uniq -u|tail -1
```
[Try it online!](https://tio.run/##S0oszvifVpqXXJKZn6eQm1gRX5qXWahQrZCanJGvoGKoUPM/vSi1QEE3X0Gvpji/qKQGLK9bWlOSmJmjoGv4v5aLC67N0AjBNkAwTSxMLQ2QpEwsUfmWYIDCN0DmG1qaWJgbGphYWvyHaAUA "Bash – Try It Online")
---
### [Bash](https://www.gnu.org/software/bash/) + coreutils, 20 bytes
```
sort|uniq -u|tail -1
```
[Try it online!](https://tio.run/##S0oszvifVpqXXJKZn6eQm1gRX5qXWahQrZCanJGvoGKoUPM/LT8nRUHXsKY4v6ikBiyrW1pTkpiZAxT8X8vFBddkaIRgGyCYJhamlgZIUiaWqHxLMEDhGyDzDS1NLMwNDUwsLf5DtAIA "Bash – Try It Online")
If input is given as a list of digits, one per line, we can skip the fold stage. That feels like cheating though.
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 27 97 86 58 57 75 bytes
```
using System.Linq;
n=>n.GroupBy(i=>i).Where(i=>i.Count()<2).Max(i=>i.Key)-48
```
[Try it online!](https://tio.run/##TY7BCsIwEETv/Yo9JqBBpWCltgcFPaggevAc4qoL7UaTVCzit9dWEbzNDDOPMb5vrMOm8sRn2Nc@YJlG/06tiW9pZArtPWydPTtdPiMAH3QgA3dLR9hoYiG7FGBRsZn64FpCjzjkcIKs4SxntXS2us5qQVlOUh0u6PCj1dxWHIScjqTa6Mc3W2Et@3HSdMj0A55b9rZAdXAUUJzEz@9QH9uPKKSUXfMVvZrhJE7Gw0E8SdrhGw "C# (.NET Core) – Try It Online")
Thanks @CarlosAlejo
[Answer]
# [<>< (Fish)](https://esolangs.org/wiki/Fish), 93 bytes
```
0l1-l2-$:?v~~o;         
v&]{[-3lr <   |.!01~$r&\
>r$1-:?!v$rl3-[{]:&:&=?^
@&::&:$~/|.!01 $}&~$?(
```
[Try it in my interpreter](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoiMGwxLWwyLSQ6P3Z+fm87XG52Jl17Wy0zbHIgPCAgIHwuITAxfiRyJlxcXG4+ciQxLTo/IXYkcmwzLVt7XTomOiY9P15cbkAmOjomOiR+L3wuITAxICR9Jn4kPyhcbiAgICAiLCJpbnB1dCI6IiIsInN0YWNrIjoiMTQ0MjIiLCJtb2RlIjoiY2hhcnMifQ==)
[Found a fun bug in my interpreter testing this](https://github.com/mousetail/Fish/commit/aef7487c6fe7c54eee4659f9e04be968abd1c781)
Expects input pre-pushed to the stack
## Explanation
[![enter image description here](https://i.stack.imgur.com/a6zsC.png)](https://i.stack.imgur.com/a6zsC.png)
Top row: Setup. Push 0, the current maximum, l-1, the total number of iterations of the outer loop, and l-2, the total number of iterations in the inner loop. Initially both are the same.
Second row left: Shift left 1, then move the top item to the register. This is the candidate largest member.
Third row: Compare the register for each digit. If none match go down. Otherwise go up to second row right.
Second row right: Reset, then try another digit. This happens if the digit is equal to another.
Last row: We have found a unique digit! Now we check if it's better than the current max value, if so replace it. Then reset and jump to the start.
[Answer]
## JavaScript (ES6), ~~52~~ 50 bytes
Takes input as a list of digits. Returns `0` if there are no unique digits.
```
s=>s.reduce((m,c)=>m>c|s.filter(x=>x==c)[1]?m:c,0)
```
### Test cases
```
let f =
s=>s.reduce((m,c)=>m>c|s.filter(x=>x==c)[1]?m:c,0)
console.log(f([1,2]))                 // 2
console.log(f([0]))                   // 0
console.log(f([4,8,5,9,0,2]))         // 9
console.log(f([4,9,5,9,0,2]))         // 5
console.log(f([9,9,9,9,9,9]))         // (0)
console.log(f([9,9,9,0,9,9]))         // 0
console.log(f([1,9,4,8,7,1,0,4,9,8])) // 7
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), ~~89~~ ~~85~~ 79 bytes
```
a->{int i=10,x[]=new int[i];for(int d:a)x[d]++;for(;i-->0&&x[i]!=1;);return i;}
```
[Try it online!](https://tio.run/##nY8/b4MwEMX3fIrrEoFiLKhSNakLUpdKHTqlG/Lg8ic6SmyETUqE@OzURrR7kQfr7t3v3rtKXEWgmkJW@dfUdJ81ZpDVQmt4Fyhh2AAsXW2Esd9VYQ4Xq3kn06I8pxxEe9b@PApQ2X20M1jTspOZQSXph3qT5nWpnlGalCdQQjyJIBlsCRhHIelTHsviG5yOnJWq9ZyWPwm/T3O@280thkGQhNttb2fu4oj5rC1M10pANk7On80pTjdtigtVnaGNDWlq6ZVUNE19e9E2jPdrxIeI3I@@/18qXMHsyYE8kCMJVznuLbmePpK/t5oOV9KR5dztjySyO9wdh2XLuBmnHw "Java (OpenJDK 8) – Try It Online")
-6 bytes thanks to @KevinCruijssen's insight!
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 14 bytes
-2 thanks toTwiNight.
```
⌈/⊢×1=(+/∘.=⍨)
```
`⌈/` the largest of
`⊢` the arguments
`×` multiplied by
`1=(`…`)` the Boolean for each where one equals
 `+/` the row sums of
 `∘.=⍨` their equality table
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@NR24TqRz0d@o96twLxCkNbbf1HHTP0bIFsoFAtUMWhFRqGCkaaChoGQGyiYKFgqmCpYAAWMQGyEDxLBUswG0gCeYZAGqTaXMEQKAZSaaHJlQFTBYaaAA "APL (Dyalog Unicode) – Try It Online")
[Answer]
# [PHP](https://php.net/), 40 bytes
```
<?=array_flip(count_chars($argn))[1]-48;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRoMClkliUnmerZGhpYmFuaGBiaaFkzWVvB5S1TSwqSqyMT8vJLNBIzi/NK4lPzkgsKtYAa9DUjDaM1TWxsP7/HwA "PHP – Try It Online")
# [PHP](https://php.net/), 42 bytes
```
<?=chr(array_flip(count_chars($argn))[1]);
```
[Try it online!](https://tio.run/##K8go@G9jX5BRoMClkliUnmerZGhpYmFuaGBiaaFkzWVvB5S1Tc4o0kgsKkqsjE/LySzQSM4vzSuJT85ILCrWAGvS1Iw2jNW0/v8fAA "PHP – Try It Online")
[Answer]
# [Java (JDK)](http://jdk.java.net/), 67 bytes
```
s->{int i=9;for(s=" "+s+" ";s.split(i+"").length!=2;i--);return i;}
```
[Try it online!](https://tio.run/##jY6xboNADIb3PIV7E4hygYiqWFcyVurQKWPV4UqAml4OxJlIUcSz06uKsobFsvx/@v21@qzj9vgz9@OXoRJKo52Dd00WrhsAx5r9tfWUHJmMrEdbMnVWvi7Ly4EHss0jvFmummrYQw0FzC7eX8kyUIGq7obAFQJE5CI/lZOuN8QBRUKE0lS24e@HYqcojkM1VDwOFkhNs9p4g8VrETl3dISTtwv@3358gg7/RAEOF8fVSXYjy95HbGxQS9335hKIdCfCUN3FklVUlj9hsq4ww9UoIiaIq9AUs/w5TTLMb/h2e6cbb93TZpp/AQ "Java (JDK) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), ~~16~~ 12 bytes
```
0{\:~-.}./.~
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DapjrOp09Wr19PXq/msqcKUmZ@QrqJuqK9gqpCkoWSkYGhmbmBoZQ8UtkMQtLYEyFnApc4SUpYmFuaGBiaUFzDgDuJylpaWBpaXCfwA "J – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-h`](https://codegolf.meta.stackexchange.com/a/14339/), ~~12~~ ~~11~~ ~~10~~ 4 bytes
I/O as a digit array.
```
ü l1
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LWg&code=/CBsMQ&input=WzEsOSw0LDgsNywxLDAsNCw5LDhd)
[Answer]
**APL ([NARS2000](http://www.nars2000.org/)) 16 chars, 23(?) bytes**
```
{↑⌽⍸1=+⌿⍵∘.=⍳10}
```
(input as array of digits, e.g. {↑⌽⍸1=+⌿⍵∘.=⍳10}4 9 5 9 0 2)
[Answer]
# [Desmos](https://desmos.com/calculator), 113 bytes
```
U(l)=max([min([\left\{l[n]=l[i]:-1,l[n]\right\} for i=join([0...n-1],[n+1...l.length+1])]) for n=[1...l.length]])
```
Takes input as a list.
[Try it out and see versions that make slightly more sense](https://www.desmos.com/calculator/xy4naheu1w)
]