Mentioning the time and space complexity in answers

Leetcode is a great place to solve questions and get some very insightful solutions for questions. Some authors post detailed solutions, which helps in getting a clear idea of the question, and understand how to think of the approach to solve it. So kudos to the community!

Just had a suggestion for authors posting their solutions on the discussion section of the questions: if you could please also post the time and space complexity of the solution alongside the answer.

What is the need to specifically mention it, given it is a basic concept?
Well, complexity of the solution plays an important role in understanding the way the code works, especially for someone who is reading it for the first time. If these are mentioned in the answer itself, it will help understand how we are able to optimize the solution (brute force) and somewhere get clarity of the concepts and situations when a particular DS/Algo can be used. This will especially be very useful in the answers which mention the step by step approach.

Also, understanding it is a process which gets better with analysing as many solutions as possible. So, this can help the programmers in making it a habit to get more clarity of this concept and help the readers think of the ways to optimize the solution.

Yes, some authors do mention it, which is great. If we could make it a convention for our answers in the community, that would be beneficial to many.

Comments (0)