Find the next number with all different digits, and no 0 or 2 Task
Input - integer number (year)
Print one number - the next year, in which all digits are pairwise different, and there are no digits 2 and 0. If there will never be such a year, print -1.
My solution (correct)
Could you please recommend time / space complexity optimizations?
vector&lt;char&gt; toVec(int n) {
    vector&lt;char&gt; res;
    while (n &gt; 0) {
        res.push_back((n % 10) + '0');
        n /= 10;
    }
    return res;
}

int main(){
    int year;
    cin &gt;&gt; year;
    for (int i = year + 1; i &lt; pow(10, 8); ++i) {
        vector&lt;char&gt; v = toVec(i);
        if (find(begin(v), end(v), '2') == v.end() and
            find(begin(v), end(v), '0') == v.end()) {
            set&lt;char&gt; temp(v.begin(), v.end());
            if (v.size() == temp.size()) {
                cout &lt;&lt; i;
                return 0;
            }
        }
    }
    cout &lt;&lt; -1;
    
}
You seem to be missing some headers (&lt;vector&gt;, &lt;iostream&gt;, &lt;cmath&gt; and &lt;set&gt;), and also to be assuming the standard names are in the global namespace, rather than std.
After attempting to read from std::cin, it's important to ensure the read was successful before attempting to use the result.  (E.g. if (!(std::cin &gt;&gt; year)) { std::cerr &lt;&lt; &quot;Input failure\n&quot;; return EXIT_FAILURE; }).
A linear search will be inefficient, especially as we may have to skip long runs containing the banned digits 0 and 2.  It would be better to construct the result using the available digits than to consider and test every possible number.  The search is flawed anyway, since std::pow(10, 8) could be larger than the maximum int, leading to overflow (which is Undefined Behaviour).