One Challenging Neural Network Question and MATLAB Simulation
I believe the solutions should be a total of 3 neurons for each question. This is because two neurons are sufficient to calculate the lines that separate all the points. Then, an extra neuron can be used to decide to which class does a point belong to. Let's see why:
1st Question: Output of the neurons $=1$ or $=0$
First, we should note that both classes are separable if we use two lines:

Let's call these lines $l_1$ and $l_2$ (the order doesn't matter). Because of the fact that a line depends only on 2 parameters (let's call them $k$ and $c$), we know that the points $(x_1,x_2)$ that belong to these red and blue lines will  satisfy:
$$ l_1 = x_1 + k_1\,x_2 + c_1 = 0 \\
l_2 = x_1 + k_2\,x_2 + c_2 = 0$$
If a point $(x_1,x_2)$ doesn't belong to these red or blue lines (like all the points in the picture), then the above equalities would not hold.
In this situation, we have that the points lying at one side of the line will lead to a quantity $l_i &gt; 0$, and the points to the other side will lead to a quantity $l_i &lt; 0$ (with $l_i$ being $l_1$ or $l_2$).
Given this, we know that the first thing a neuron computes is the weighted sum of its inputs using its weights ($w_i$) and bias ($b_i$):
$$ w_ix_1+w'_ix_2+b_i$$
This means that we can calculate the previous lines using two neurons. This can be achieved by setting $w_i = 1$, $w'_i=k_i$ and $b_i = c_i$. Just like in the next NN:

So, for example, the first neuron will be calculating the value of $l_1$ and the second neuron will be calculating the value of $l_2$.
As said earlier, all the points that need to be classified will have values of $l_i$ $&gt;0$ or $&lt;0$, so we can use an activation function that returns a neuron output of $1$ if $l_i&gt;0$ and $0$ if $l_i&lt;0$.
This way, we will end up with four possible combinations of outputs:
$$ \begin{align}
(0,0)\,\, \text{and} \,\, (1,1)\quad &amp;\text{For one class}\\
   (1,0)\,\, \text{and} \,\,(0,1)\quad &amp;\text{For the other class}
\end{align}$$
Thereby we can use this to finally know to which class does a point belong to. Note that the first class has these values repeated $\Rightarrow$ If we substract them we will end up with a value of $0$. However, if we substract the values of the second class, we would end up with $1$ or $-1$.
Hence we can use an activation function at the output neuron that outputs a value of $1$ when the substraction of its inputs is $0$ and that outputs a value of $0$ otherwise, achieving the correct classification. Thereby, our final NN would be like:

2nd Question: Output of the neurons $=1$ or $=-1$
The only thing that changes w.r.t. the previous reasoning is that the neurons will output $-1$ when $l_i&lt;0$ (instead of outputing $0$). This way, we would have the next four cases with the hidden layer output:
$$ \begin{align}
(-1,-1)\,\, \text{and} \,\, (1,1)\quad &amp;\text{For one class}\\
(1,-1)\,\, \text{and} \,\,(-1,1)\quad &amp;\text{For the other class}
\end{align}$$
Where again, the first class has these values repeated and the second class doesn't $\Rightarrow$ we can still use the previous NN to correctly classify the data.
Edit regarding the comments
The above explanation respects the constraints given by the question (neuron outputs $\in\{0,1\}$ or $\in\{-1,1\}$), but it also assumes that we are able to choose freely how is the activation function w.r.t. its inputs.
Below in the comments we have talked about using simpler activation functions, concretely perceptrons, which have the next behaviour:
$$ \text{output} = \begin{cases}
1 \text{ if } \mathbf{w\cdot x}+ b &gt; 0\\
0 \text{ otherwise}
\end{cases}$$
Perceptrons have already been considered above in the answer for the first two neurons, which are able to transform our initial data to XOR data.
Given this, it's important to note that 3 perceptrons are enough to model any logical function (as argued in posts like this one from Medium). This means that with the above reasoning we would need 3 more neurons, making a total of 5 neurons needed.