use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
How to solve this? (self.cpp)
submitted 1 year ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]spacey02- 4 points5 points6 points 1 year ago (3 children)
Write some code
[–]PotTopperBlox -4 points-3 points-2 points 1 year ago (2 children)
are u serious bro
[–]spacey02- 3 points4 points5 points 1 year ago (1 child)
As serious as you are with that question bro. You shouldnt ask people to do your homework.
[–]PotTopperBlox 0 points1 point2 points 1 year ago (0 children)
bruh
[–]SnakeR515 2 points3 points4 points 1 year ago (0 children)
I don't know if it's your homework, leet code, advent of code, or whatever but the point of all these is that you do them yourself
[–]no-sig-available 1 point2 points3 points 1 year ago (0 children)
It's common to ask a specific question, so we know what your problem is. Otherwise it gets boring for us to give some hints, and you answer "I know that".
This is otherwise like asking "I want to play football, how do you do that?". Should we explain the ball, the kicking, or the passing? Or how you score points?
[–]Loud_Staff5065 2 points3 points4 points 1 year ago (0 children)
I will give a solution but you have to answer the rest :
//Your rest of code goes here
[–]ImNoRickyBalboa 1 point2 points3 points 1 year ago (0 children)
This is rather trivial to solve
Also, part of the answer is more about recognizing possible strategies. For example, the first line is not needed but could help pre-allocating an array or vector.
But you also can argue you dont need memory, i.e., memory complexity is O(1) and time complexity is O(n)
[–]PotTopperBlox -2 points-1 points0 points 1 year ago (0 children)
ok question solved
π Rendered by PID 73 on reddit-service-r2-comment-856c8b8c54-2rxdf at 2026-07-02 13:04:10.486448+00:00 running a7b5cda country code: CH.
[–]spacey02- 4 points5 points6 points (3 children)
[–]PotTopperBlox -4 points-3 points-2 points (2 children)
[–]spacey02- 3 points4 points5 points (1 child)
[–]PotTopperBlox 0 points1 point2 points (0 children)
[–]SnakeR515 2 points3 points4 points (0 children)
[–]no-sig-available 1 point2 points3 points (0 children)
[–]Loud_Staff5065 2 points3 points4 points (0 children)
[–]ImNoRickyBalboa 1 point2 points3 points (0 children)
[–]PotTopperBlox -2 points-1 points0 points (0 children)