DEV Community

Dawn Zhao for MarsCode

Posted on

User Story EP3: How to Practice LeetCode Problems

LeetCode is an online platform for coding interview preparation. The service provides coding and algorithmic problems intended for users to practice coding. LeetCode has gained popularity among job seekers and coding enthusiasts as a resource for technical interviews and coding competitions.

In the past, when using LeetCode, I preferred to write down my problem-solving thoughts using a txt editor or plain paper, and then code using VS Code. When I encountered problems that I couldn't understand, I needed to consult Google or ChatGPT. Although this method helped to clarify my thoughts, solving a single problem required frequent switching between multiple tools. This not only consumed a lot of time but also interrupted the continuity of my thinking, resulting in low overall efficiency. Therefore, I have been looking for a solution that could simplify this process and improve my practice efficiency.

Recently, a friend recommended an AI-powered Cloud IDE product called MarsCode to me. The overall experience is quite similar to VS Code, while also providing a ready-to-use development environment that supports debugging and running. The best part is that the built-in AI assistant can provide more accurate answers by fully understanding the context. Next, I will share my experience of using MarsCode.

Preparation

You need an account for MarsCode, which is very easy to get. Visit the MarsCode official website at MarsCode, and then register (or log in) to your account.

MarsCode offers various development templates, allowing users to start coding without worrying about setting up the programming environment. For instance, I chose Node.js here.

After creating, you can code just like you do with a local IDE.⬆️


You can run the index.js by clicking the 'Run' button or executing node index.js in the terminal.⬆️

Experience with MarsCode

Usually, when I encounter a problem, I first jot down my thoughts on scratch paper. This time, to test MarsCode's capabilities, I jumped directly into the coding phase. Let's take a look at a classic LeetCode problem: the "Longest Palindromic Substring"!

For LeetCode problems, we can write code with the assistance of MarsCode, or we can directly copy the LeetCode answer into the IDE and use AI capabilities to help us understand the problem and solution. MarsCode's AI assistant is very powerful, supporting features like code generation and code explanation. MarsCode can help me learn LeetCode in several key ways.

Coding

When writing code, MarsCode provides three ways to assist with coding:

  • While coding in the editor, the AI assistant infers your intentions based on the project context and comments, auto completing your code.
  • Generate code directly in the editor through the Inline AI Chat.
  • Chat with the AI assistant in the Side chat bar to get the AI to directly output the code.

For example, in the Node.js project created in the previous section, we can invoke Inline AI Chat in index.js.


When we input the problem, the AI assistant will infer the implementation of the function, even including the function call code!⬆️


After accepting the code, click the Run button to test the code and see the results.⬆️

If there are parts we don't understand, we can ask the AI assistant to explain them.⬆️

Writing test cases

Even though MarsCode has excellent coding capabilities, whether the code is completed by AI or by ourselves, we can use test cases to verify the correctness of the code.

In fact, with the help of AI, our test cases can be more comprehensive. Taking the "Longest Palindromic Substring" as an example, we can use the AI assistant to generate test cases using Mocha.

This way, we can easily and quickly verify accuracy through the test cases.⬆️

Debug

MarsCode provides templates that already support debugging capabilities. If there are any doubts about the code execution process, we can also use the Debug feature to understand the code execution step by step.

Open the Debug panel on the right side and click the "Start Debugging" button.⬆️

Exploring Better Solutions with AI

We can explore more solutions by conversing with MarsCode's AI assistant. For example, in the previous example, we used the center expansion algorithm for the longest palindromic substring, but another common solution is dynamic programming.


If we are not familiar with dynamic programming, we can ask further: What is dynamic programming?⬆️

We can also ask the AI assistant to provide some examples of dynamic programming. ⬆️

As you can see, on MarsCode, the AI assistant acts like a teammate, helping us gradually increase our understanding of the problem through conversation.

Conclusion

Overall, my experience with MarsCode has been excellent. Features like hassle-free setup, free AI, and resource environments are very helpful for validating ideas and boosting efficiency. However, when practicing LeetCode, your own thought process is paramount. I recommend first organizing your ideas and then using MarsCode to solve the problems. This approach maintains the flow of thought while leveraging the powerful tools MarsCode offers, ensuring you effectively and solidly grasp algorithms and coding techniques.

Wishing you great success in your LeetCode practice!🎉

Top comments (0)