For what $n$ can we find a degree $\leq n-2$ polynomial such that $P(i) \in \{0 , 1 \}$ for $i \in [n]$, but not all identical. For what $n$ is the following statement true:

There exists a choice of $ a_1, a_2, \ldots a_n \in \{ 0, 1 \}$, not all identical, such that there is a polynomial $F(x) \in \mathbb{R}[x]$ of degree at most $n-2$ such that $F(i ) = a_i$ for $i = 1 $ to $n$.

From my solution to this problem, the statement is false for prime $n$.
I was then considering the composite numbers case, but wasn't able to push through to get useful constraints. Clearly, for any values of $a_i$, we can find a unique polynomial of degree at most $n-1$ that satisfies it. The question boils down to whether the coefficient of $x^{n-1}$ can be 0.
I've tested specific cases:
If $n = 4$, then $1, 0, 0, 1$ gives us $\frac{x^2}{2} - \frac{5x}{2} + 3$.
If $n = 6$, then $1, 0, 0, 0, 0, 1$ gives us $\frac{ x^4}{24} - \frac{7x^3}{12} + \frac{71x^2}{24} - \frac{77x}{12} + 5$.
If $n = 9$, then $0, 0, 1, 1, 0, 0, 1, 0, 0$ gives us $\frac{x^7}{720} - \frac{2 x^6}{45} + \frac{203 x^5}{360} - \frac{65 x^4}{18} + \frac{8869 x^3}{720} - \frac{983 x^2}{45} + \frac{1117 x}{60} - 6$.
These are specific cases of the following:

*

*If $ n = 2k$, then $1, 0, 0, \ldots, 0, 1 $ works.

*If $n = 3k$ with $k$ odd, then $a_{k} = a_{k+1} = a_{2k+1} = 1 $ with the rest 0 works.

To see why they work without explicitly finding such a polynomial, we use the method of differences to show that the coefficient of $x^{n-1}$ is indeed 0 if it satisfies the equation
$${n-1 \choose 0 } a_1 - {n-1 \choose 1} a_2 + {n-1 \choose 2} a_3 + \ldots + (-1)^{n+1}{n-1 \choose 0} a_n = 0. $$
For $n = 2k$, we have ${n-1 \choose 0} = 1, {n-1 \choose n-1} = 1$, so we can set $ a_0 = a_n = 1$.
For $n = 3k$ with $k$ odd, we have ${ 3k-1 \choose k-1} = \frac{1}{2} {3k-1 \choose k} = {3k-1 \choose 2k}$, so we can set $a_{k} = a_{k+1} = a_{2k+1} = 1 $.
The polynomial can be recovered from the Method of Differences, or using Lagrange Interpolation.
My conjecture is that it's true for composite $n$, but I don't know how to proceed with the general case.
Note: For $n = 25$, $1,1,1,1,0,1,1,1,1,1,0,0,0,0,0,0,1,0,1,1,0,0,1,1,1$ works. I found it by playing with the binomial coefficients.
For $n = 35$, Sil found ${34 \choose 13 } - { 34 \choose 14} + {34 \choose 15} - {34 \choose 20} = 0$.
The cases of $ n = 49, 55$ are listed in Sil's solution.
 A: The search can be performed more efficiently if we first limit it to the residues modulo primes right below $n$. If $\frac n2\lt p\lt n$ with $p$ prime, then $\binom{n-1}k\equiv0\bmod p$ for $n-1-p\lt k\lt p$ (because $p$ appears in the numerator but not in the denominator). Thus, for primes right below $n$, only the first $n-p$ terms (and their mirror images) contribute to the residue, so the even and odd sums of those terms must be equal mod $p$.
Another optimization is available due to the symmetry. Instead of allowing separate values of $0$ and $1$ for $\binom{n-1}k$ and $\binom{n-1}{n-1-k}$, we can allow values of $0$, $1$ and $2$ only for $\binom{n-1}k$, which reduces the size of the search space from $2^n$ to roughly $3^{\frac n2}\approx1.732^n$. Still, without the residue approach, there would be roughly $3^{\frac n4}\approx1.316^n$ even and odd sums to compute and store, which is prohibitive e.g. for $n=125$, where $3^{\frac{125}4}\approx8\cdot10^{14}$.
Here’s Java code that performs the search by iterating over the primes $p$ from $n$ downward, in each step retaining only the configurations of the first $n-p$ variables that have matching even and odd sums modulo the product of all primes encountered so far.
The result (obtained in a few seconds) is that there is no lower-degree polynomial for any composite numbers coprime to $6$ from $65$ to $125$. At $n=133$ and higher, the search runs out of memory because too many configurations have to be retained due to the large prime gaps between $113$ and $127$ and between $83$, $89$ and $97$ that prevent a sufficient reduction of the search space. It’s unclear whether this effect could lead to the existence of solutions for higher $n$.
A: The conjecture that this is possible for all composite $n$ is false, the smallest composite $n$ that fails this condition is $n=65$.
This is done by computer search. I've used the equivalent form by checking sums of binomial numbers. In a spirit of @DavidESpeyer's comment, I've evaluated all possible sums given by proper subsets of $\{\binom{n-1}{0},\binom{n-1}{2},\binom{n-1}{4}, \dots, \binom{n-1}{n-1} \}$ and $\{ \binom{n-1}{1},\binom{n-1}{3},\binom{n-1}{5}, \dots, \binom{n-1}{n-2} \}$ and then checked if the two sums sets intersect. Following is a quick & dirty implementation in Python, I am sure it could be optimized (it uses a lots of memory!).
import math

def check(n):
    even_combs = [math.comb(n-1, i) for i in range(0, n, 2)]
    odd_combs = [math.comb(n-1, i) for i in range(1, n, 2)]

    even_sums = {0}
    for comb in even_combs:
        to_add = set()
        for s in even_sums:
            to_add.add(s+comb)
        even_sums = even_sums.union(to_add)
    even_sums.remove(0)
    even_sums.remove(sum(even_combs))

    odd_sums = {0}
    for comb in odd_combs:
        to_add = set()
        for s in odd_sums:
            to_add.add(s+comb)
        odd_sums = odd_sums.union(to_add)
    odd_sums.remove(0)
    odd_sums.remove(sum(odd_combs))

    return even_sums.intersection(odd_sums)

print(check(65))

The output given is an empty set, so there is no choice possible.
Still there could be a mistake, independent verification is welcome.

To show this is indeed the smallest counterexample, consider following solutions for $n=49$ and $n=55$:
$$
\sum_{x \in \{1, 3, 5, 7, 11, 13, 15, 17, 19, 35, 43, 47\}} \binom{48}{x}=\sum_{y \in \{0, 2, 6, 8, 12, 14, 20, 46, 48\}} \binom{48}{y}
$$
and
$$
\sum_{x \in \{15, 17, 21, 33, 39\}} \binom{54}{x}=\sum_{y \in \{14, 20, 22\}} \binom{54}{y}.
$$

Next unresolved cases, i.e. composites coprime to $6$, are
$$
77, 85, 91, 95, 115, 119, 121, 125, 133, 143, 145, 155, 161, 169, 175, 185, 187,\dots
$$
Perhaps the optimized version of the above approach can find more counterexamples, then maybe some pattern emerges (or not and these might be more of a "random" occurrences).
