Count frequencies of elements in array
This seems over-complicated.  A simpler solution would use a std::map or std::unordered_map for the counting:

std::unordered_map&lt;int, std::size_t&gt; counts;
for (auto const &amp;element: container) {
     ++counts[element];
}




Instead of being tied to std::vector&lt;int&gt;, we could make the code much more flexible as a template, taking a pair of iterators (or, from C++20, a std::range) with any appropriate element type.  The signature might look something like:

template&lt;typename Iter&gt;
auto getFrequencies(Iter begin, Iter end)
   -&gt; std::unordered_map&lt;decltype(*Iter), std::size_t&gt;;


We might use constraints or SFINAE to choose whether to return an ordered or unordered map, based on whether *Iter is ordered and/or hashable.