4 AnswersNew Answer
https://code.sololearn.com/cqfF14AkOwBv/#cpp Let me know if you need an explanation :)
How was my code overcomplicated? It is the basic algorithm, for beginners. You are using a vector and a pre-made algorithm.
@Maya Don't over complicate. Just give him what he wants: https://code.sololearn.com/ctj1ZADU20ZZ/#cpp
@Maya For a 'beginner' your code looks too intimidating and you don't have proper indentation or spacing to make the code readable. Coding is about simplicity and clean code. Adding the libraries I provided reduced the complexity of the code. Also, we live in a world of modern C++. New aspiring programmers need to keep with the current standard. If you ever attended university, a coding boot camp, or have a vast library of resources like I do you would know that the automatic 'go to' array is the vector and the algorithm library is the first of the libraries that are taught to new programmers to use at an early stage before pointers are introduced and dynamic memory allocation. Seeing that it is obvious you are a novice I will give you credit for your good question. +1 @Maya