[Haskell], 102 98 95 9594 bytes
import Data.List
f(x:r)=length r>=x&&x>=0&&(f.reverse.sort$(pred<$>takesort$take x r(pred<$>r)++drop x r)
f x=1<3
Try it online! UsageTry it online!
Usage: f [3,3,2,2,1,1]
, returns True
or False
. Assumes that the input contains no zeros and is sorted in descending order, as allowed in the challenge.
Explanation:
import Data.List -- import needed for sort
f (x:r) = -- x is the first list element, r the rest list
length r >= x -- the rest list r must be longer or equal x
&& x >= 0 -- and x must not be negative
&& (f . -- and the recursive call of f
reverse . sort $ -- with the descendingly sorted list
(pred<$>taketake x r(pred<$>r) -- of the first x elements of r subtracted by 1
++ drop x r -- and the rest of r
) -- must be true
f [] = True -- if the list is empty, return True
Edit: This seems to follow the Havel-Hakimi mentioned in other answers, though I did not know of this algorithm when writing the answer. [Haskell]: https://www.haskell.org/