theorem next_getLast_cons (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y)
    (hx : x = getLast (y :: l) (cons_ne_nil _ _)) (hl : Nodup l) : next (y :: l) x h = y := by
  rw [next, get, ← dropLast_append_getLast (cons_ne_nil y l), hx, nextOr_concat]
  subst hx
  intro H
  obtain ⟨⟨_ | k, hk⟩, hk'⟩ := get_of_mem H
  · rw [← Option.some_inj] at hk'
    rw [← get?_eq_get, dropLast_eq_take, get?_take, get?_zero, head?_cons,
      Option.some_inj] at hk'
    exact hy (Eq.symm hk')
    rw [Nat.zero_eq, length_cons, Nat.pred_succ]
    exact length_pos_of_mem (by assumption)
  suffices k.succ = l.length by simp [this] at hk
  cases' l with hd tl
  · simp at hk
  · rw [nodup_iff_injective_get] at hl
    rw [length, Nat.succ_inj']
    refine' Fin.veq_of_eq (@hl ⟨k, Nat.lt_of_succ_lt <| by simpa using hk⟩ ⟨tl.length, by simp⟩ _)
    rw [← Option.some_inj] at hk'
    rw [← get?_eq_get, dropLast_eq_take, get?_take, get?, get?_eq_get, Option.some_inj] at hk'
    

Proof state:
case h.intro.mk.succ.cons
α : Type u_1
inst✝ : DecidableEq α
y : α
k : ℕ
hd : α
tl : List α
hl : Function.Injective (get (hd :: tl))
h✝ : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ hd :: tl
h : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ y :: hd :: tl
hy : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ≠ y
H : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ dropLast (y :: hd :: tl)
hk : Nat.succ k < length (dropLast (y :: hd :: tl))
hk'✝ : get? (hd :: tl) k = some (getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []))
hk' : get (hd :: tl) { val := k, isLt := ?h.intro.mk.succ.cons } = getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ [])
⊢ get (hd :: tl) { val := k, isLt := (_ : k < length (hd :: tl)) } =
    get (hd :: tl) { val := length tl, isLt := (_ : length tl < Nat.succ (length tl)) }
case h.intro.mk.succ.cons
α : Type u_1
inst✝ : DecidableEq α
y : α
k : ℕ
hd : α
tl : List α
hl : Function.Injective (get (hd :: tl))
h✝ : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ hd :: tl
h : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ y :: hd :: tl
hy : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ≠ y
H : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ dropLast (y :: hd :: tl)
hk : Nat.succ k < length (dropLast (y :: hd :: tl))
hk' : get? (hd :: tl) k = some (getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []))
⊢ k < length (hd :: tl)
case h.intro.mk.succ.cons
α : Type u_1
inst✝ : DecidableEq α
y : α
k : ℕ
hd : α
tl : List α
hl : Function.Injective (get (hd :: tl))
h✝ : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ hd :: tl
h : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ y :: hd :: tl
hy : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ≠ y
H : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ dropLast (y :: hd :: tl)
hk : Nat.succ k < length (dropLast (y :: hd :: tl))
hk' : get? (hd :: tl) k = some (getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []))
⊢ k < length (hd :: tl)
case h.intro.mk.succ.cons
α : Type u_1
inst✝ : DecidableEq α
y : α
k : ℕ
hd : α
tl : List α
hl : Function.Injective (get (hd :: tl))
h✝ : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ hd :: tl
h : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ y :: hd :: tl
hy : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ≠ y
H : getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []) ∈ dropLast (y :: hd :: tl)
hk : Nat.succ k < length (dropLast (y :: hd :: tl))
hk' :
  get? (take (Nat.pred (length (y :: hd :: tl))) (y :: hd :: tl)) (Nat.succ k) =
    some (getLast (y :: hd :: tl) (_ : y :: hd :: tl ≠ []))
⊢ Nat.succ k < Nat.pred (length (y :: hd :: tl))

Next tactic:
rw [hk']