DEV Community

Imaculate
Imaculate

Posted on

9

Leetcode with ChatGPT

I asked ChatGPT to solve leetcode hard DP problems. The results were well, interesting ...

I started with Frog Jump and the results were promising. Frog Jump is a classic DP problem that is solved by memoization and backtracking. ChatGPT produced python code that could easily be ported into leetcode.

Frog Jump Python

The solution had a trivial bug but passed most testcases. Given the signature of the helper recursive function, def

canCrossHelper(position, jump)

the initial call should have been canCrossHelper(0,0) and not canCrossHelper(0,1). After fixing the bug, the solution was faster than 90+% of Python solutions. Not bad.

I then tried something more convoluted, Count ways to make array with product. This is a complex problem that applies prime factorization and combinatorics on top of DP techniques. The results were less than stellar.

Count ways Java

It produced a DP solution with recurrence relation


 = (dp[i - 1][j] + dp[i - 1][j - 1])

``` which only sounds correct, but is infact wrong. Even after prompting to revise the solution, nothing fundamental changed.

These cases told me all I needed to know about interviewing with AI. Errors are to be expected since AI is only as good as the training data. ChatGPT already has the disclaimer in the footnote `ChatGPT can make mistakes. Consider checking important information.` Here is the [link](https://chat.openai.com/share/6ed19f25-3184-4e6c-90f8-10bf3df81860) to the full chat.

A candidate could have some success from asking ChatGPT in a live interview, essentially cheating. Or they could master algorithms with confidence. A resource I recommend to is [Ace the technical interviews courses](https://leanpub.com/c/acethetechnicalinterviewbitsedition2), DP course coming soon. They help you build intuition around algorithmic techniques and reduce time to optimal solution. I'm biased because I wrote them but they free at the moment and feedback is welcome.





Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay