Find the number of permutations of the set $\left\{ 1,2,3,4,5,6,7\right\}$ not containing four consecutive elements of ascending order

Let $A$ be the set of permutations of the sequence $1,2,3,4,5,6,7$ which have $4$ consecutive terms in ascending order.

  • The number of elements of $A$ whose first $4$ terms are ascending is $$\binom{7}{4}{\,\cdot\,} 3!=210$$ Explanation:

    • There are ${\large{\binom{7}{4}}}$ choices for the first $4$ terms.$\\[2pt]$
    • There are $3!$ ways to order the $3$ remaining terms.
    $\\[2pt]$
  • The number of elements of $A$ whose initial block of $4$ consecutive ascending terms are not the first $4$ terms, and which start with the value $1$ is $$\binom{6}{3}{\,\cdot\,} 3{\,\cdot\,} 3!=360$$ Explanation:

    • There are ${\large{\binom{6}{3}}}$ choices for the $3$ terms which follow the value $1$.$\\[2pt]$
    • There are $3$ positions where the value $1$ can be placed.$\\[2pt]$
    • There are $3!$ ways to order the $3$ remaining terms.
    $\\[4pt]$
  • The number of elements of $A$ whose initial block of $4$ consecutive ascending terms are not the first $4$ terms, and which start with the value $2$ is $$\binom{5}{1}\binom{4}{3}{\,\cdot\,} 3{\,\cdot\,} 2!=120$$ Explanation:

    • There are ${\large{\binom{5}{1}}}$ choices for the term immediately before the value $2$.$\\[2pt]$
    • There are ${\large{\binom{4}{3}}}$ choices for the $3$ terms which follow the value $2$.$\\[2pt]$
    • There are $3$ positions where the value $2$ can be placed.$\\[2pt]$
    • There are $2!$ ways to order the $2$ remaining terms.
    $\\[4pt]$
  • The number of elements of $A$ whose initial block of $4$ consecutive ascending terms are not the first $4$ terms, and which start with the value $3$ is $$\binom{4}{1}\binom{3}{3}{\,\cdot\,} 3{\,\cdot\,} 2!=24$$ Explanation:

    • There are ${\large{\binom{4}{1}}}$ choices for the term immediately before the value $3$.$\\[2pt]$
    • There are ${\large{\binom{3}{3}}}$ choices for the $3$ terms which follow the value $3$.$\\[2pt]$
    • There are $3$ positions where the value $3$ can be placed.$\\[2pt]$
    • There are $2!$ ways to order the $2$ remaining terms.
    $\\[2pt]$

hence we get $$|A|=210+360+120+24=714$$ so the number of permutations of the sequence $1,2,3,4,5,6,7$ which do not have $4$ consecutive terms in ascending order is $$7!-|A|=7!-714=4326$$


I'm going to relate to the question how I think you understood it, even though I think quasi's read is much more straightforward.

(If I'm reading your answer correctly, you're considering cyclic permutations and fixing "the beginning" at $1$.)

You haven't accounted for all the overcounting. Any case with $5$ ascending elements starting not at the beginning has been counted twice in the first step. By your method, there are $2\binom651!=12$ such cases, so we must add $12$.

Then there are the $5$ cases in which exactly $6$ elements appear in order (starting from $1$, with anything other than a $7$ omitted) and the $1$ case in which all appear in order. The former cases were subtracted $3$ times each, then added $2$ times each, so no further correction is needed. The latter case was subtracted $4$ times then added $3$ times, so again no correction is needed.

So the answer should be $552$. I don't know how you got $342$ -- perhaps you can post the Python code?