DEV Community

Rishitha Nallapureddy
Rishitha Nallapureddy

Posted on

Journal - 12-11-24

Hi, Folks! Today, I solved three problems on LeetCode: Combination Sum, Combination Sum II, and Partition Equal Subset Sum. For the first two problems, we use backtracking to find all the possible solutions. When the task is to explore all possible solutions, backtracking is often the preferred approach. Typically, in problems, we stop once we find a solution, but in backtracking, we must undo our choices and explore other possible solutions. The process of undoing choices and continuing the search is what we refer to as backtracking.

Backtracking is an important concept that can solve many difficult problems efficiently, such as N-Queens, Word Search, and Combination Sum, among others.

To solve the Partition Equal Subset Sum problem, we use dynamic programming rather than a hash map. We track whether it’s possible to form a subset with a given sum. It’s somewhat similar to a real-life scenario where you go grocery shopping and use a checklist to ensure you buy every required item. You mark off each item after purchase. Similarly, in dynamic programming, we mark the achievable subset sums as we process each element in the array.

I hope my experience will be helpful!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more