📅 Day 95 of #100DaysOfCode Problem: Path Sum (LeetCode 112) Approach (Recursion / DFS): 1️⃣ Traversed the binary tree using Depth First Search (DFS). 2️⃣ Subtracted the current node value from the target sum. 3️⃣ When reaching a leaf node, checked if remaining sum equals node value. 4️⃣ Recursively checked both left and right subtrees. 5️⃣ Returned true if any root-to-leaf path matched the target sum. #100DaysOfCode #LeetCode #DSA #BinaryTree #DFS #Recursion #ProblemSolving #Cplusplus #CodingChallenge #Programming #DeveloperLife #DailyDSA #KeepLearning #TechCommunity #GrowthMindset #Motivation
Path Sum LeetCode 112 Solution
More Relevant Posts
-
📅 Day 97 of #100DaysOfCode Problem: Is Graph Bipartite? (LeetCode 785) Approach (BFS + Graph Coloring): 1️⃣ Assigned colors to nodes while traversing the graph using BFS. 2️⃣ Started coloring an unvisited node with color 0. 3️⃣ Colored all adjacent nodes with the opposite color. 4️⃣ If two connected nodes had the same color → graph is not bipartite. 5️⃣ Repeated for all disconnected components. #100DaysOfCode #LeetCode #DSA #Graphs #BFS #GraphTheory #ProblemSolving #Cplusplus #CodingChallenge #Programming #DeveloperLife #DailyDSA #KeepLearning #TechCommunity #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
🚀 Day 47 of DSA Problem: Longest Palindromic Substring A palindrome reads the same forward and backward. The challenge was to find the longest such substring inside a given string. 💡 Key Idea: Expand around each character (center) and check both odd and even length palindromes. ⏱ Time Complexity: O(n²) 💾 Space Complexity: O(1) This problem reinforced how choosing the right approach can drastically reduce complexity compared to brute force solutions. Consistent practice is sharpening my problem-solving skills step by step. 💪 #DSA #Java #CodingPractice #LeetCode #Programming #ProblemSolving
To view or add a comment, sign in
-
-
LeetCode Daily – #1784 Check if Binary String Has at Most One Segment of Ones [Easy] The Insight: Since the string always starts with '1' (no leading zeros), the only way a second segment of ones can appear is if a '0' comes BEFORE another '1' — i.e., the substring "01" exists in the string. So the entire problem reduces to one check: → Does "01" appear in the string? If yes → false. If no → true. Time: O(N) | Space: O(1) This is one of those problems where stripping away the noise leads to an almost trivially elegant solution. The key was recognizing the constraint — no leading zeros — which guarantees the string always opens with a '1', making "01" the only possible signal of a broken segment. Sometimes the best code is the code you don't write. 🚀 #LeetCode #CodingChallenge #CPlusPlus #ProblemSolving #Programming #SoftwareEngineering #POTD #DSA
To view or add a comment, sign in
-
-
#Day56 solved LeetCode 169 Majority Element Problem: Find the element that appears more than ⌊n/2⌋ times in an array. Approach: Instead of using extra space like HashMap, I learned a very efficient method called the Boyer-Moore Voting Algorithm. The idea is simple: 1.Keep a candidate and a count 2.Increase count if same element appears 3.Decrease count if different element appears 4.The final candidate will be the majority element Time Complexity: O(n) Space Complexity: O(1) This problem taught me how powerful optimized logic can be compared to brute force solutions. #DSA #LeetCode #Coding #ProblemSolving #100DaysOfCode #Programmer #LearningJourney
To view or add a comment, sign in
-
-
📅 Day 98 of #100DaysOfCode Problem: Delete and Earn (LeetCode 740) Approach (Dynamic Programming — House Robber Pattern): 1️⃣ Converted the array into a points array where each index stores total value earned from that number. 2️⃣ Choosing a number deletes its adjacent values (num - 1 and num + 1). 3️⃣ Recognized the pattern similar to the House Robber problem. 4️⃣ At each step, decided whether to take or skip the current value. 5️⃣ Used dynamic programming to maximize total earned points. Many DP problems become easier once you recognize familiar patterns 🧠 #100DaysOfCode #LeetCode #DSA #DynamicProgramming #DP #Arrays #ProblemSolving #Cplusplus #CodingChallenge #Programming #DeveloperLife #DailyDSA #KeepLearning #TechCommunity #GrowthMindset #Motivation
To view or add a comment, sign in
-
-
🚀 Day 182 of #200DaysOfCoding 📌 Problem: Check if Binary String Has at Most One Segment of Ones (LeetCode 1784) Today’s challenge was about checking whether a binary string contains at most one continuous segment of '1's. 🧠 Problem Understanding We are given a binary string s that starts with 1 and contains only 0 and 1. We need to verify that all 1s appear in one contiguous block. ✔ Valid Examples 111000 110 1000 ❌ Invalid Example 1001 → Here, the segment of 1s breaks and appears again later. 💡 Key Idea If we ever encounter 0 followed by 1, it means a new segment of 1s has started, which violates the condition. ⏱ Complexity Time Complexity: O(n) Space Complexity: O(1) Consistent practice like this is helping me strengthen my problem-solving and data structure skills every day. #Day182 #200DaysOfCoding #LeetCode #DSA #Programming #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
When you miss a base case🧠 What is the best way to check it, what do you guys think??💬 When working with recursion, the most important step is often the simplest one: 💻Define your base case first. Before thinking about the recursive calls, pause and ask, like what’s the worst or simplest condition where the function should stop? Most of the time, that’s your base case. A small reminder from experience: 👉 Start with the base case 👉 Think about edge conditions first 👉 Then build the recursive flow Strong foundations make complex problems manageable. You can also check out✨, and learn CPP from the basics💻: https://lnkd.in/gdPC4D6f #Recursion #Programming #CPP #DSA #problemSolving #leetcode #basecase #lpu
To view or add a comment, sign in
-
-
I wrote a beginner-friendly article explaining 10 Pattern Problems in C++ with diagrams and code. Pattern problems are a great way to improve logic and understanding of loops. Check it out here: https://lnkd.in/grVA7Ggb #Programming #CPP #Coding
To view or add a comment, sign in
-
-
DAY->7 Solved "Sort Array By Parity II" on LeetCode using the Two Pointer Approach in C++. -> Runtime: 0 ms (Beats 100%) -> Optimized time complexity: O(n) -> Practicing efficient array manipulation and pointer techniques. Consistency in Data Structures & Algorithms is the key to improving problem-solving skills. #LeetCode #DSA #Programming #Cpp #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Leetcode POTD : Find Unique Binary Strings... Given an array that contains n unique binary strings, each of length n, and some possible strings are missing. Target: find a binary string of length n that is not present in the array. Thought process... Initially I thought of generating all possible binary strings of length n. Since the constraint was small, it passed all the test cases. But then I felt generating all 2^n strings just to find one missing is not really optimal, so I started thinking about a better approach 🤔 If we observe the examples carefully, we notice something interesting. There are n strings and each string has length n. Ohh yes, here is the trick 👀 Since the ansmust also be a string of length n, we can construct a new one ourselves. All the given strings are already unique, so if we flip the bit at index i from the i-th string (0 -> 1 or 1 -> 0), the newly formed string will differ from every string at least at one position. That guarantees the string will be unique and missing from the array ✨ Using this idea, the missing binary string can be found in O(n) time. #leetcode #potd #binary #strings #programming #problem_solving #consistency
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development