[Question]
  [
You deal cards labeled 0 to 9 from a deck one a time, forming stacks that start at 0 and count up by 1.
* When you deal a 0, you place it on the table to start a new stack.
* When you deal any other card, you stack it atop a card that's exactly
one lower in value, covering it. If there's no such card, the deck isn't stackable.
Given a deck, determine whether it can be stacked when dealt in the order given. Equivalently, given a list of digits, decide whether it can be partitioned into disjoint subsequences each of the form `0,1,..,k`
**Example**
Take the deck `0012312425`. The first two cards are `0`, so they go on the table:
```
Stacks: 00
  Deck: 12312425
```
Next, we deal a `1`, which goes on a `0`, doesn't matter which:
```
        1
Stacks: 00
  Deck: 2312425
```
We then deal a `2` atop the just-placed `1`, and the `3` on top of it.
```
        3
        2
        1
Stacks: 00
  Deck: 12425
```
Next, the `1`, `2` and placed atop the first stack and `4` atop the second one. 
```
        4
        3
        22
        11
Stacks: 00
  Deck: 25
```
Now, we need to place a `2`, but there's no `1` atop either stack. So, this deck was not stackable.
**Input:** A nonempty list of digits 0-9, or a string of them. You can't assume that 0 will always be in the input.
**Output**: One of two distinct consistent values, one for stackable sequences and one for non-stackable ones
**Test cases:** 
Stackable:
```
0
01
01234
00011122234567890
012031
0120304511627328390
```
Not stackable:
```
1
021
0001111
0012312425
012301210
000112223
```
For convenience, as lists:
```
[0]
[0, 1]
[0, 1, 2, 3, 4]
[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 0]
[0, 1, 2, 0, 3, 1]
[0, 1, 2, 0, 3, 0, 4, 5, 1, 1, 6, 2, 7, 3, 2, 8, 3, 9, 0]
[1]
[0, 2, 1]
[0, 0, 0, 1, 1, 1, 1]
[0, 0, 1, 2, 3, 1, 2, 4, 2, 5]
[0, 1, 2, 3, 0, 1, 2, 1, 0]
[0, 0, 0, 1, 1, 2, 2, 2, 3]
```
Grouped:
```
[[0], [0, 1], [0, 1, 2, 3, 4], [0, 0, 0, 1, 1, 1, 2, 2, 2, 3], [0, 1, 2, 0, 3, 1], [0, 1, 2, 0, 3, 0, 4, 5, 1, 1, 6, 2, 7, 3, 2, 8, 3, 9, 0]]
[[1], [0, 2, 1], [0, 0, 0, 1, 1, 1, 1], [0, 0, 1, 2, 3, 1, 2, 4, 2, 5]]
```
**Leaderboard:**
```
var QUESTION_ID=144201,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/144201/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~45~~ 43 bytes
*-2 bytes thanks to [@TFeld](https://codegolf.stackexchange.com/users/38592/tfeld)*
```
s=[]
for c in input():s+=c,-1;s.remove(c-1)
```
[Try it online!](https://tio.run/##ZU/LboMwELz7K1ZcAuqmws6rpeLYP6hyQRyIu1VQKUbGJM3XU7CDQxNr5H3NjHabizmqWvRSfVIaBEHfplnOvpQGCWU9oOlMGCXtUypxyd/aZ00/6kShXPKoH/jsfCwrgg/dUcIAjL6MYXj0SxJGV1c2uqxNuGhNIb@LQ0WLiI0cSY2BfVF19K610sk/cq0MzAR9FucsixH4NSAIhBXC2tUOfIKYMDIQNghbhB3CC8LrwJx7xJbEH1vxJHWWWzva2ZGwTitvdlUL73O3zq3r93bJ2v6bu5t8zv2uc8Pbcfkf "Python 2 – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
Λ¬ḞS:o-→ø
```
[Try it online!](https://tio.run/##yygtzv5/aFuuxqOmxtxMzUPb/p@bfWjNwx3zgq3ydR@1TTq84////wZcBoZAZGRswmVgYGBoaGhkBGSbmplbWIKkjAyMDSGUgYmpoaGZkbmxkYUxUAooamQI1QKigSYYGpkYmYLNAmJDA4gkyDgA "Husk – Try It Online")
Returns `1` for stackable decks and `0` for non-stackable decks.
It looks like Ørjan Johansen in [his Haskell answer](https://codegolf.stackexchange.com/a/144214/62393) already came up with the same algorithm, but in Husk this is obviously much more concise.
### Explanation
We takle the problem from another side: flip the deck and make descending piles. If after going through all the deck all the piles have a 0 on the top, the deck is stackable.
```
Λ¬ḞS:(-→)ø
         ø    Starting with the empty list (each element of this list will be the top card
              of a stack)
  ḞS          Traverse the input from right to left. For each card:
      -→        Remove the successor of this card from our list (if present)
    :           Add this card to our list
Λ¬            At the end, check if all the cards in our list are zeroes (falsy)
```
[Answer]
# [Haskell](https://www.haskell.org/), 55 bytes
An anonymous function taking a list of integers and returning a `Bool`.
Usage: `(all(<1).foldr(?)[]) [0,1,2,3,4]`.
```
all(<1).foldr(?)[]
m?l|(p,r)<-span(/=m+1)l=m:p++drop 1r
```
[Try it online!](https://tio.run/##ZY9da4MwFIbv8ysO7S4SEp2xX5tUSxmjDMYojF1ZL8LUVhajRMcutv12Z2O1pQsvOd8P5xxE9ZFI2XxbY3hev2ze1ptHeNhuYWz9IpSLTPmZqhMt3uubTyUzlVR2LkqMoH14J62gOhRfICkdgRXAiNJjjFOQhNhYJyL2vNdaZ2pvBeFTS9onOiJmmtgGh1Dq7xohJV5yYqeFjDVekTBC@Ur@4JJpsrSqUih86@eUE@nnXklprIsSuG6a0IlQ6DDgJ8PAZTBhMO3iTryX2@vYwWDGYM5gweCOwX3beclwTBP/n3L60Q45N6WFKbmGNBlgp2l34Fytc84Oe3fO1Pyzq5sGnw@7XgLPx0XoDw "Haskell – Try It Online")
# How it works
* `foldr(?)[]` folds its list argument from right to left using `?`, starting with an empty list. The result is the list of numbers in the list that didn't fit on top of a previous number.
* `all(<1)` tests if the only numbers not fitting on top of a previous number are zeroes.
* `m?l` prepends a number `m` to a list `l` of non-fitting numbers. If `m+1` is already in the list, it can now be removed as it fits on top of `m`.
	+ `(p,r)<-span(/=m+1)l` splits the list `l` into two parts `p` and `r` at the first instance of the number `m+1`. If there aren't any, the right part `r` will be empty.
	+ `m:p++drop 1r` prepends `m` to the split parts. If `r` is nonempty, then it must start with `m+1`, which is removed by `drop 1`.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~15~~ 11 bytes
```
‘Ṭ€+\I>0FS¬
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw4yHO9c8alqjHeNpZ@AWfGjN/8PtQO7//9HRBrE6XNEGOgqGMFpHwUhHwVhHwQQqAEGGMGQEQyAlOgqmOgpmOgrmOgoWOgqWQJUophiAVRliETOAaYYYagaWMgdLGYHNMoYbxxUNM8AIYRaao5CE4e6HMEzApCm65@BsQ4Sbkc1E@DI2FgA "Jelly – Try It Online")
[Answer]
## [Retina](https://github.com/m-ender/retina), 42 bytes
```
O$#`(.)(?<=(\1.*?)*)
$#2
.
$*1,
^(,|1\1)+$
```
[Try it online!](https://tio.run/##LYwxDsIwDEV3X6NBckIV@TtJWyRQR0YuUKEyMLAwIEbuHhyKZOt/@cnvdX8/nre64/NaL65bOXqejydeEMPsgyfXKUVyAT1duf9ggd@7WoUENpoyiQgAVetlGKdDQyoJW0guwKBj0ikZsqvi/9LSDNCs5eeyhWyw6b4 "Retina – Try It Online")
### Explanation
```
O$#`(.)(?<=(\1.*?)*)
$#2
```
This sorts the digits, stably, by how often that same digit has occurred before. In effect, this collates the various candidate subsequences together. The resulting string will first have the first occurrence of each digit, and then the second occurrence of each digit and so on. In a stackable input, the result will look something like `0123...0123...0123...`, where each of these substrings may terminate at any point.
It's easiest to determine whether the input has this kind of pattern in unary.
```
.
$*1,
```
We replace each digit **n** by **n** `1`s, followed by a comma to separate individual digits.
```
^(,|1\1)+$
```
Finally we make use of a forward reference to match consecutively increasing runs of digits. We try to match the entire string either by matching a single comma (representing a **0**, which starts a new run) or by matching the previous thing preceded by an additional `1`, which only works if the current digit is the successor of the previous one.
[Answer]
# C (gcc), 74 73 bytes
```
f(int*l){int s[10]={},r=1;for(;~*l;s[*l++]++)r*=!*l||s[*l-1]--;return r;}
```
Requires the input array to mark the end with -1. Example usage:
```
int main(int argc, char** argv) {
    int a[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 0, -1};
    printf("%d\n",  f(a));
    return 0;
}
```
[Answer]
# JavaScript (ES6), 39 bytes
*-1 thanks to [@tsh](https://codegolf.stackexchange.com/users/44718/tsh)*
```
a=>a.every(k=>a[a[~k]=-~a[~k],-k]--|!k)
```
[Try it online!](https://tio.run/##fVDLDoIwELz7F3KCZEvKW2Pw6Bd4qz00WF8QagBJSAy/jqVI1FjIpt1mZjqbnRurWZkU13uFcnHk3SnuWLxlNq950ZipfBJG2pTGqFUdUEoRei5Tq0tEXoqM25k4mwbZF4/q0lDD2iy@iZNJMLWsPwwcPQoueOBrub4cVa4qqYMAQohgBWvAk35YKp1ZFiun3jmUSCQRV3p6o@vPR@OQkx3LSu2q@jHuxPjPQlP8EEd/@/IEM5EN3ZmIYZz0Dk5quhc "JavaScript (Node.js) – Try It Online")
---
# JavaScript (ES6), ~~61~~ ~~45~~ 40 bytes
Takes input as a list.
```
a=>a.every(k=>a[~k]=!k|a[-k]--&&-~a[~k])
```
[Try it online!](https://tio.run/##fVDLDoIwELz7F3IgkGxJy1Nj8OgXeKscGgQfEGoASUgMv46lSNRYzKaPzMzOZufKGlbF5eVWo4Ifkz4NexZumZU0SdkamfjSLovCZfZgFGURQrqOOomZfcyLiueJlfOTodF9ea/PbaSZm8UnkRoUR6b5gwFRo2CDA66SG4rIsmUJHXjgQwArWAOe9cNCSf6yWDoNzr5AAoHYwtOZXL8atUNBdyyvlKuqx9gz498LzfFjHMPtiuP9iWx8yUwM06RXcELTPwE "JavaScript (Node.js) – Try It Online")
## How?
For each value ***0...9***, we keep track of the number of available stacks with the preceding card atop. These counters are stored in ***a[-9]*** to ***a[0]***, where ***a[]*** is the original input array. The only counter that collides with the input data is ***a[0]***, but we don't really care about this one because 1) cards labeled ***0*** are always allowed and have to be processed separately anyway and 2) the input value ***a[0]*** is processed before it has a chance to be updated.
```
a => a.every(k =>  // given the input array a, for each card k in a:
  a[~k] =          // the card is valid if:
    !k |           //   - it's a 0 or
    a[-k]-- &&     //   - there's at least one stack with the card k-1 atop
    -~a[~k]        // in which case we allow a new card k+1 and go on with the next card
)                  // otherwise, every() fails immediately
```
[Answer]
# TI-Basic (83 series), 25 bytes (49 characters)
```
:min(seq(min(cumSum(Ans=I)≤cumSum(Ans=I-1)),I,1,9
```
## How it works
Takes input as a list in `Ans`. Outputs `1` for stackable inputs, `0` otherwise.
For each `I`, `cumSum(Ans=I)` computes a list of the number of times `I` has occurred in each initial segment, so `min(cumSum(Ans=I)≤cumSum(Ans=I-1))` is only 1 if, at every position, we've seen `I-1` at least as many times as `I`. The overall expression is `1` whenever this holds for each `I`.
[Answer]
# Nim, 133 bytes
```
proc s(d:seq[int]):int=
 var
  t= @[0]
  r=1
 for c in d:(t.add(0);var f=0;for i,s in t.pairs:(if s==c:(t[i]=c+1;f=1;break));r*=f)
 r
```
`1` if it works; `0` if it doesn't.
Had to pull some funky business to deal with mutability of variables in for-loops, oh well.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 16 bytes
```
0*GQ"@yQy=f1)(]a
```
Input is an array of numbers.
The code outputs `1` in STDOUT if input is stackable, or exits with an error and empty output in STDOUT if input is not stackable.
[**Try it online!**](https://tio.run/##y00syfn/30DLPVDJoTKw0jbNUFMjNvH//2gDHQVDHQUjHQUgwxhMmugomIIFgcgMLGUOlgIyLMAMS6CyWAA "MATL – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), 110 bytes
```
+`0((.*?)1((.*?)2((.*?)3((.*?)4((.*?)5((.*?)6((.*?)7((.*?)8((.*?)9)?)?)?)?)?)?)?)?)?
$2$4$6$8$10$12$14$16$+
^$
```
[Try it online!](https://tio.run/##Xcy9DsIwDATgPc9hpJRKyHf5aTp15C1QGRhYGBDvH5yaCcXRF/mUez8@z9e9n@J17/OuMV7O2wSHTnKyU5zqLE5z1mn7P0EoWao0gQooyIIqc7hJ7xoUNkw5qCoA0t6lLm0dETXB0VyAyiWxJYtsS/y@DK0BzCxHl12oh6PuCw "Retina – Try It Online") Link includes test cases. I don't often get to use `$16`...
[Answer]
# Mathematica, 80 bytes
```
Catch[Fold[#~Join~{-1}/.{{p___,#2-1,q___}:>{p,#2,q},-1:>Throw[1<0]}&,{},#];1>0]&
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~69~~ ~~61~~ ~~55~~ ~~47~~ 46 bytes
```
s=[]
for c in input():s+=-1,;s[s.index(c-1)]=c
```
[Try it online!](https://tio.run/##K6gsycjPM/r/v9g2OpYrLb9IIVkhMw@ICkpLNDStirVtdQ11rIuji/Uy81JSKzSSdQ01Y22T//@PNtBRMNRRMNJRADKMwaSJjoIpWBCIzMBS5mApIMMCzLAEKosFAA "Python 2 – Try It Online")
Output is `error`/ `no error`.
[Answer]
# [R](https://www.r-project.org/), 88 bytes
```
function(d){s={}
for(e in d)if(!e)s=c(s,0)else{k=match(e,s+1)
if(is.na(k))T=F
s[k]=e}
T}
```
[Try it online!](https://tio.run/##NYq7CsMwDAB3f4W6SdQNSR9btOYLspUOwZGpcetAlE7G3@6GQuE4bri1euhP1X@S28KScKasnIvxy4oCIcFMweNBSNmh2pbkpZIjv6fNPVGsHjsy@xG0SRNGopEHo/f4YClmLNWjw9bCTmfhbOHyj@vPN6L6BQ "R – Try It Online")
Function that takes an R vector; returns `TRUE` for stackable and `FALSE` for unstackable.
Explanation:
```
function(d){
 s <- {}              # initialize the stacks as empty
 for(e in d){         # iterate over the deck
  if(!e)              # if e is zero
   s <- c(s,0)        # start a new stack
  else {              # otherwise
   k <- match(e,s+1)  # find where e should go in s, NA if not there
   if(is.na(k))       # if no match (unstackable)
    T <- F            # set T to F (False)
   s[k] <- e          # set s[k] to e
  }
 T                    # return the value of T, which is TRUE by default and only gets changed in the loop to F.
}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
ċṪƊƤ⁺⁼
```
[Try it online!](https://tio.run/##y0rNyan8//9I98Odq451HVvyqHHXo8Y9/x/u3Gf9qGGOgq6dwqOGudaH27ke7t5ydFLYo6Y1h9uBROT//0pKStEGsVzRBjoKhlBKR8FIR8FYR8EEwocgQxgygiGQCh0FUx0FMx0Fcx0FCx0FS6BKZDMMwIoMMYUMYFohRpqBpczBUkZgk4zhhkF1G8HNQXMOQhTubgjDBEyaovkJzjaEuxXZQITnYoEBAwA "Jelly – Try It Online")
A monadic link taking a list of integers and returning 1 for stackable and 0 for not. Based on [my answer to @WheatWizard’s near-duplicate puzzle](https://codegolf.stackexchange.com/a/268548/42248).
[Answer]
# [Haskell](https://www.haskell.org), 53 bytes
```
(a:b)#x=sum[1|i<-x,a==i]:b#(a:x)
y#x=y
f x=x#[]#[]==x
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ8GCpaUlaboWN001Eq2SNJUrbItLc6MNazJtdCt0Em1tM2OtkpSBUhWaXJVAyUquNIUK2wrl6FggsrWtgGi-xXgkNzEzT8FWISWfS0GhoCgzr0RBRSFNIdogFo2vo2CIRUhHwUhHwVhHwQRTDoIMYcgIhkCqdRRMdRTMdBTMdRQsdBQsgSpxmW0A1oDTaoi0AcxIiFVmYClzsJQR2AZjmCUgY0pLgkuKfPIUlHR1dZW4UA3GYpERVuvRfIddBTx4IAwTMGmKJxjhbEOsQYJsKSI8Y7kgkQlLEQA)
Inches out [the former best Haskell answer](https://codegolf.stackexchange.com/a/144214/56656) by implementing an algorithm from [my challenge](https://codegolf.stackexchange.com/questions/268543/is-it-stuck-in-a-counting-loop) which turned out to be a duplicate of this.
We implement a function `(#[])` which replaces each value in a list with the number of times that value has already occurred.
If applying this function twice to a list gives back the original list it is stackable.
[Answer]
# [Nekomata](https://github.com/AlephAlpha/Nekomata) + `-e`, 5 bytes
```
Oᵐ{x=
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iLzU7PzexJHFNtJJurpKOgpJuqlLsgqWlJWm6Fsv9H26dUF1hu6Q4KbkYKrbgFqNYtEEsV7SBjoIhlNJRMNJRMNZRMIHwIcgQhoxgCKRCR8FUR8FMR8FcR8FCR8ESqBLZDAOwIkNMIQOYVoiRZmApc7CUEdgkY7hhUN1GcHPQnIMQhbsbwjABk6ZofoKzDeFuRTYQ4blYSPgAAA)
```
Oᵐ{x=
O       Find a set partition such that:
 ᵐ{     For each part:
   x=     The part is equal to [0,...,length(part)-1]
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~77~~ 75 bytes
```
import Data.List
g[]=1<3
g(x:r)|s<-r\\[x-1]=g r&&(x<1||s/=r&&g s)
g.reverse
```
[Try it online!](https://tio.run/##bU/LasMwELzrK4YcjA2KY9lO0wbr1mN66lHRQRBHNYkfSGrxwf/uGqXqi8CwO8zu7ONN2Ut9vc5z0w69cXhWTqWHxjqiheSsKoiOx71JJlutzfEoxjWTXMNEUTxWbJrshi9cwybkzHVq6o/a2HpuVdOB49QTtGp4QTyYpnNIcU4gRCYpREbBQqbIKQqK8ku4gQXkAcUfQ@Y97I62xJJiG/wPvrTzpYU8evK0tElJMLy7V2cOHVaru8eG@fnPqn/n/ZK/P7mR0setlPMn "Haskell – Try It Online") Usage: `g.reverse $ [0,1,2]`. Returns `True` for stackable inputs and `False` otherwise.
This is a recursive solution which traverses a given list from back to front. It implements the observation that
* the empty list is stackable.
* a non-empty list with prefix `r` and last element `x` is stackable if `r` is stackable and either `x` is zero or both `x-1` appears in `r` and `r` with `x-1` removed is also stackable.
[Answer]
# C, 248 bytes
Note: To print return status, type "echo $status" into the terminal
Return status 0: Not stackable
Return status 1: Stackable
Explanation: Increments array element with the index equivalent to the current-most digit in the stack. Then, the program checks if this just-now-incremented array element is larger than the element preceding it. If so, returns 0. Else if program makes it to the end of the array returns 1.
```
 main(int argc, char ** argv)
{
    static int stack[10];
    while ( *++argv != 0x0 )
    {
        stack[**argv - 0x30]++;
        if ( **argv - 0x30 > 0 )
        {
            if ( stack[**argv - 0x30] > stack[**argv - 0x30 - 1] )
            {
                return 0;
            }
        }
    }   
    return 1;
}
```
[Answer]
# Java 8, ~~168~~ ~~150~~ ~~142~~ 136 bytes
```
a->{int x[]=new int[a.length],s=0,i;A:for(int n:a){if(n<1)s++;else{for(i=s;i-->0;)if(x[i]==n-1){x[i]=n;continue A;}return 0;}}return 1;}
```
-6 bytes thanks to *@ceilingcat*.
Returns `0`/`1` whether it is correctly stackable or not.
**Explanation:**
[Try it here.](https://tio.run/##pVLLboMwELznK/YIikFAXm1cIuUDmkuOiINLnNQpWRA2aSrkb6dgShr1FFJptVp7dsczto/szJws53jcfdRJyqSEVyawGgEIVLzYs4TDpl2aDUisJkcxMJs2e3rUJKmYEglsACGEmjmrqm28RHGI/LMdipibcjyo95jI0COCrpf7rGiJAJfMrsTewhffluMx5anklQFDSYXjrDxqN/AlEnEYouPblSmRJhkqgSWHNdUFV2WB4FHdlz7VNW215eVb2mj7kXjOxA5OjT1rqwqBB@Oj87b9koqf3KxUbt5AKkUL3cTqHcQVeKBtY/quZgL@0H4CAYEJgenAwS78PoI@WioCMwJzAgsCTwSeyXAXhsozbP4/Zr1eTCdybqCFgQKjbXIr784zhgoKhnv4c7kPjF/ftSumJs8e/RzX2h/@lrdefn9JT6JHuv4G)
```
a->{                        // Method with integer-array parameter & integer return-type
  int x[]=new int[a.length],//  Array for the stacks, (max) size equal to input-size
      s=0,                  //  Amount of stacks, starting at 0
      i;                    //  Index integer
  a:for(int n:a){           //  Loop A over the input
    if(n<1)                 //   If the current item is a zero:
      s++;                  //    Increase amount of stacks `s` by 1
    else{                   //   Else:
      for(i=s;i-->0;)       //    Inner loop (2) over the stacks
        if(x[i]==n-1){      //     If a top item of a stack equals the current item - 1:
          x[i]=n;           //      Set this item in the stacks-array
          continue A;}      //      And go to the next iteration of loop A
    return 0;}}             //    If we haven't encountered a `continue`, return 0
  return 1;}                //  Return 1 if we were able to correctly stack everything
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
‘Ṭ€+\I’Ȧ
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw4yHO9c8alqjHeP5qGHmiWX/D7cfnfRw5wzNyP//o6MNYnW4og10FAxhtI6CkY6CsY6CCVQAggxhyAiGQEp0FEx1FMx0FMx1FCx0FCyBKlFMMQCrMsQiZgDTDDHUDCxlDpYyAptlDDeOKxpmgBHCLDRHIQnD3Q9hmIBJU3TPwdmGCDcjm4nwZWwsAA "Jelly – Try It Online")
Essentially a port of [my other answer](https://codegolf.stackexchange.com/a/231388/66833), but with `‘` to handle zero-indexing
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
œp@ŒQẎµ0rṀ⁼Qµ¿Ẹ
```
A monadic link taking a list of non-negative integers and returning `0` if stackable or `1` if non-stackable.
**[Try it online!](https://tio.run/##y0rNyan8///o5AKHo5MCH@7qO7TVoOjhzoZHjXsCD209tP/hrh3///@PNtBRACJDHQUjHQVjGMMETJrGAgA "Jelly – Try It Online")**
### How?
```
œp@ŒQẎµ0rṀ⁼Qµ¿Ẹ - Link: list
             ¿  - while loop:
      µ     µ   - ...condition chain:
       0        -      literal zero
         Ṁ      -      maximum of current list
        r       -      inclusive range = [0,1,2,...,max(list)]
           Q    -      de-duplicate list (unique values in order of appearance)
          ⁼     -      equal?
                - ...do:
   ŒQ           -      distinct sieve (1s at first occurrences 0s elsewhere)
  @             -      use swapped arguments:
œp              -        partition (the list) at truthy values (of the distinct sieve)
     Ẏ          -      tighten (makes the list flat again ready for the next loop)
              Ẹ - any truthy? 1 if the resulting list has any non-zero integers remaining
                -           - effectively isNotEmpty for our purposes since a list of only
                -             zeros gets reduced to an empty list via the loop.
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 16 bytes
```
£=k_¥T©°T}T=0ÃUd
```
[Test it online!](https://ethproductions.github.io/japt/?v=1.4.5&code=oz1rX6VUqbBUfVQ9MMNVZA==&input=WzAsIDEsIDIsIDAsIDMsIDAsIDQsIDUsIDEsIDEsIDYsIDIsIDcsIDMsIDIsIDgsIDMsIDksIDBd) Outputs `false` for stackable, `true` for non-stackable.
### Explanation
```
 £   = k_  ¥ T© ° T}T=0Ã Ud
UmX{U=UkZ{Z==T&&++T}T=0} Ud    Ungolfed
                               Implicit: U = input array
UmX{                   }       For each item X in the array:
                    T=0          Set T to 0.
      UkZ{         }             Remove the items Z where
          Z==T&&++T              Z == T (and if so, increment T).
                                 This has the effect of removing the largest stack.
    U=                           Reset U to the result.
                               This process is repeated U.length times, which is
                               evidently enough to handle any U.
                         Ud    Return whether there are any truthy items in U.
                               Any items not part of a stack are non-zero/truthy,
                               so this works for every possible case.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 25 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ηε[DõQ#ZƒDNåiNõ.;Dëˆ#]¯OĀ
```
The challenge doesn't look all that difficult, but it's quite hard in 05AB1E (for me at least..)
Outputs `0` if stackable, and `1` if not stackable.
[Try it online](https://tio.run/##ATcAyP8wNWFiMWX//863zrVbRMO1USNaxpJETsOlaU7DtS47RMOry4YjXcKvT8SA//8wMDEyMzEyNDI1) or [verify all test cases](https://tio.run/##MzBNTDJM/W9o5ObpYq@k8KhtkoKS/f9z289tjXY5vDVQOerYJBe/w0sz/Q5v1bN2Obz6dJtyLRAcWu9/pOG/zqEt/w24DAyByMjYhMvAwMDQ0NDICMg2NTO3sARJGRkYG0IoAxNTQ0MzI3NjIwtjkBRYMVAOpNfQyMTIFGwKEBtCJUEGcQEVGBkCAA).
**Explanation:**
```
η             # Prefixes of the (implicit) input
              #  i.e. '012031' → ['0','01','012','0120','01203','012031']
              #  i.e. `021` → ['0','02','021']
 ε            # Map each to:
  [           # Start an infinite inner loop
   D          # Duplicate the current value
    õQ#       # If it's an empty String, stop the infinite loop
   Z          # Get the maximum (without popping)
              #  i.e. '01203' → 3
              #  i.e. '02' → 2
    ƒ         # Inner loop `N` in the range [0,max]
     D        # Duplicate the current value
      Nåi     # If it contains the current digit `N`
              #  i.e. '01203' and 1 → 1 (truthy)
              #  i.e. '02' and 1 → 0 (falsey)
         Nõ.; # Remove the first one (by replacing the first `N` with an empty string)
              #  i.e. '1203' and 1 → '203'
         D    # And duplicate it again for the next iteration of the inner loop
      ë       # Else (does not contain the digit `N`):
       ˆ      # Push `N` to the global stack
        #     # And break the infinite loop
 ]            # Close the if-else, inner loop, infinite loop, and mapping (short for `}}}}`)
  ¯           # Push the global stack
   O          # Take the sum
              #  i.e. [] → 0
              #  i.e. ['2'] → 2
    Ā         # And get the trutified value of that (which we implicitly output as result)
              #  i.e. 0 → 0
              #  i.e. 2 → 1
```
[Answer]
# Java 8, 87 bytes
Instead of building the stacks I just calculate if an element is unstackable on the previous elements, and return 0 when an unstackable element is encountered. If I reach the end, the entire string is stackable and 1 is returned:
```
s->{int l[]=new int[10];for(int n:s)if(n!=0&&l[n]>=l[n-1]||l[n]++<0)return 0;return 1;}
```
[Try it online!](https://tio.run/##pVI9b8IwEN3zK64LSoSJ7PDV1oSxUodOjJEHNyTI1DhR4lAhyG9PnUAAdcNYJ@t85/func9bvuejLE/Udv3TiF2eFRq2JuZXWkg/rVSsRab8j4tDnVjysoQvLtTRASg11yKGPr0QSkcMfSqdbJJiCTF1wIG8@pbm0uXuPhNr2Bm8u9KFUJuIAfdaLoghhKYcLY@GBWTEQpX8QstIMKNpVrhtXL2Xnkhd9RLiwUBGii1Ds48IO53a03C4wF6R6KpQgOnFIbRuqNNKMWt1KHWy87NK@7mpr6VyY5/nuTy4fT12BAy159FHAAiIDQZBgGCMYGIBPhvpLeitpUMwRTBDMEfwiuAN2XXU0eGOkTyJx72os9hZl5p3qaDTOL6X@UAdG2GBXT//HtyS4jrzszPp9ukzn@fqE7s53/d1@0U9Ue3UzR8 "Java (OpenJDK 8) – Try It Online")
**Explanation:**
```
s->{
  int l[]=new int[10];                # initialise the counts of each digit encountered prefix of element, all initialised to 0
  for(int n:s)                        # Iterate over all entries in input
    if(n!=0&&l[n]>=l[n-1]||++l[n]<0)  # Check if the element is stackable on the previous elements. Last check is always evaluated and false, but the sideeffect is to add the element to the handled, prefixed element og the next element.  
      return 0;                       # Unstackable
  return 1;                           # No unstackable elements, so the result is stackable
}
```
[Answer]
# J, 25 23 bytes
```
{{(-:\:~"1)+/\y=/i.10}}
```
-2 bytes thanks to Bubbler
Note: No TIO for this version as it relies on newer J feater called direct definition `{{...}}`
[Working 24 byte TIO link](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o600dK1irOqUDDWjrbT1Y2Jt9TP1HAwN/mty@TnpKaBLaxjq1CmrGWgqaXOlJmfkK6QBjUKwDFHYRgrGCiZIIgZgUUOwjBFU1lTBTMFcwULBEs0cIyBpjGEeSMwArAtkihlQxBwoYgTUbwwxAaJc3S0xp7hSnQumGdkYIxQewkmoohDHg0gTIDbF8BaENkRxNMwsmOf@AwA "J – Try It Online")
Just a port of [caird's great answer](https://codegolf.stackexchange.com/a/231388/15469) to make sure I understood it.
[Answer]
# [Uiua](https://www.uiua.org), 75 bytes
```
=0⋅⋅⋅⧻⍢⍜▽⍜⊢(□⊐⊂:)(((⊙⊙⊙⊙(⊂1)|∘).⊙⊙⊙◌⊃∊≡=:≡⊢,,⊙(-1.⊃⋅⊢↘1)|..0)=0⧻,)▽:□[¯1]⧻.
```
[Test pad](https://uiua.org/pad?src=0_8_0__RiDihpAgPTDii4Xii4Xii4Xip7vijaLijZzilr3ijZziiqIo4pah4oqQ4oqCOikoKCjiipniipniipniipko4oqCMSl84oiYKS7iipniipniipnil4ziioPiiIriiaE9OuKJoeKKoiws4oqZKC0xLuKKg-KLheKKouKGmDEpfC4uMCk9MOKnuywp4pa9OuKWoVvCrzFd4qe7LgojIFRydXRoeQpGIFswXQpGIOKHoTIgIyAwXzEKRiDih6E1ICMgMF8xXzJfM180CkYgMF8wXzBfMV8xXzFfMl8yXzJfM180XzVfNl83XzhfOV8wCkYgMF8xXzJfMF8zXzEKRiAwXzFfMl8wXzNfMF80XzVfMV8xXzZfMl83XzNfMl84XzNfOV8wCiMgRmFsc3kKRiBbMV0KRiAwXzJfMQpGIOKWvTNfNCDih6EyICMgMF8wXzBfMV8xXzFfMQpGIDBfMF8xXzJfM18xXzJfNF8yXzUKRiAwXzFfMl8zXzBfMV8yXzFfMApGIOKWvTNfMl8zXzEg4oehNCAjIDBfMF8wXzFfMV8yXzJfMl8zCg==)
]