When does an algorithm run in $O(1)$ time?
If you follow the definition of $\mathcal O$, a function $f(x)\in\mathcal O(1)$ when there's an $x_0$ and $M$ such that for all $x&gt;x_0$, $f(x) \leq M$.

For both algorithms you mention, there clearly is an upper bound on the number of steps a machine has to take to compute the result. Therefore, the time complexity for either problem will be some function $T(n)$, where $n$ is the length of the input, such that $T(n)\leq M$ for some $M$ for all $n$. Therefore $T(n)\in \mathcal O(1)$.

Note that the $\mathcal O$ notation has to do with asymptotic behavior of functions, i.e. their behavior as their input grows beyond all bounds. It doesn't care about tiny inputs, whether their length is $1$, $2^7$, or $10^{100}$.