Determining whether one vector is a prefix of the other
Ok first, we want to determine if some condition is true or not based on some input. That calls for a boolean function! In particular, our inputs are two vectors. :

bool isPrefixOf(const std::vector&lt;int&gt;&amp; smaller, const std::vector&lt;int&gt;&amp; larger) 
{
    ...
}


I named the first variable smaller, but it might not actually be smaller! Let's make sure that it is:

    if (smaller.size() &gt; larger.size())
    {
        std::swap(smaller, larger); // this very efficiently swaps our vectors
                                    // in constant time
    }


Now once we got that, the algorithm in your j == k is exactly correct, but pretty hard to read. The convention is to use variables like i, j, k solely as indices in loops, not as important variables. So I'll rewrite it like this:

    for (int i = 0; i &lt; smaller.size(); ++i) 
    {
        if (smaller[i] != larger[i]) 
        {
            return false; // clearly not a prefix
        }
    }

    return true; // we match up, so we must be done!
}


So cool, we got our function that checks if a smaller vector is a prefix of a larger vector, so now our main just has to determine which way we call it:

int main() 
{
    vector&lt;int&gt; vec1{0, 1, 1, 2};
    vector&lt;int&gt; vec2{0, 1, 1, 2, 3, 5, 8};

    cout &lt;&lt; "vec1 is a prefix of vec2?: " &lt;&lt; isPrefixOf(vec1, vec2) &lt;&lt; endl;
}


Which should print true. So in general, your variable names don't line up with convention, and you coded the same logic twice - don't repeat yourself! Take advantage of functions to encode conceptually distinct functionality.