BQN, 1515 13 bytesSBCS
-2 bytes thanks to Marshall Lochbaum
-˜`⍟(≠-1˙)≡≠↑1˙˜`⍟≠≡1‿¯1⥊˜≠
Unlike many array languages, BQN doesn't have a binomial primitive, so a more creative solution is required.
-˜`⍟(≠-1˙)≡≠↑1˙˜`⍟≠≡1‿¯1⥊˜≠ #
-˜` # swapped minus scan
⍟(≠-1˙)⍟≠ # repeated input length-1 times
number of times
≡ ≡ # matches
≠↑1˙1‿¯1⥊˜≠ # inputalternating length1,-1 take.. 1extended (ex:to 1‿0‿0‿0the ≡input 4↑1)length