Day 55: Root-to-Leaf Grinding 🌳 Problem 1022: Sum of Root To Leaf Binary Numbers Back to trees. The goal: sum binary paths from root to leaf. The Strategy: • DFS Brute Force: Stack-based traversal to explore every branch. • Path Tracking: Dragging binary strings down the tree like a heavy backpack. • Conversion: Hit a leaf, parse the string to base 2, add to sum. Ngl, string concatenation in a loop is a bit mid for efficiency, but it got the job done. Bitwise shortcuts are next on the menu. We move. 🚀 #LeetCode #Java #BinaryTree #DFS #Coding #DailyCode
Sum of Root to Leaf Binary Numbers in Java
More Relevant Posts
-
Day 65: The "One-Liner" Win 🎯 Problem 1784: Check if Binary String Has at Most One Segment of Ones Today was a lesson in simplifying logic. The challenge: check if a binary string contains more than one contiguous segment of '1's, given that the string starts with '1'. The Strategy: • Observation: If there are multiple segments of '1's, they must be separated by at least one '0'. • The Pattern: In a string starting with '1', any "new" segment of ones would look like "01" somewhere in the string. • The Execution: A simple !s.contains("01") handles the entire check. Sometimes we hunt for complex algorithms when a single string method is the ultimate counter. Clean, readable, and passed all test cases. 🚀 #LeetCode #Java #StringManipulation #Coding #Efficiency #DailyCode
To view or add a comment, sign in
-
-
Day 81/100 – LeetCode Challenge ✅ Problem: #11 Container With Most Water Difficulty: Medium Language: Java Approach: Two Pointers (Greedy Shrinking) Time Complexity: O(n) Space Complexity: O(1) Key Insight: Area = min(height[i], height[j]) × (j - i) Start with widest container (i=0, j=n-1). Move the pointer with smaller height inward — only this can potentially increase area. Solution Brief: Initialized two pointers at both ends. While i < j: Compute current area using smaller height Update max if current area larger Move the pointer with smaller height inward #LeetCode #Day81 #100DaysOfCode #TwoPointers #Java #Algorithm #CodingChallenge #ProblemSolving #ContainerWithMostWater #MediumProblem #Greedy #Array #DSA
To view or add a comment, sign in
-
-
Day 22 of Daily DSA 🚀 Solved LeetCode 66: Plus One ✅ Approach: Treat the array as a number and simulate addition from the last digit: • If the last digit is not 9, increment and return • Handle carry by setting 9 → 0 and moving left • If all digits are 9, create a new array with leading 1 This avoids converting the array into an integer and handles large numbers safely. ⏱ Complexity: • Time: O(n) • Space: O(1) (extra array only when overflow happens) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.58 MB (Beats 38.49%) A simple problem that tests edge-case thinking 💡 #DSA #LeetCode #Java #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 5 – Longest Consecutive Sequence. Today's problem focused on finding the longest consecutive sequence in an unsorted array, which helps strengthen understanding of sorting, edge cases, and sequence tracking. Approach Step 1 – Sort the Array Step 2 – Traverse the Array While iterating: 1️⃣ If elements are equal → skip duplicates 2️⃣ If nums[i] == nums[i-1] + 1 → increase sequence count 3️⃣ Otherwise → reset the count. Step 3 – Track Maximum Length. Github Code :- https://lnkd.in/gF8DqckJ #LeetCode #DSA #StriverA2Z #CodingJourney #Java #Arrays #ProblemSolving #CodingPractice #SoftwareEngineering #TechInterviewPrep #100DaysOfCode #DeveloperJourney #ComputerScience
To view or add a comment, sign in
-
-
🚀 Day 60 of DSA consistency Today I practiced a Binary Search Tree (BST) problem: Search in a Binary Search Tree. In this problem, we need to find a node with a given value in a BST and return the subtree rooted at that node. 🔹 Key Idea: A BST has the property: Left subtree values < root Right subtree values > root Using this property, we can efficiently search by moving left or right instead of traversing the entire tree. 📊 Complexity Analysis Time Complexity: O(h) → where h is the height of the BST Space Complexity: O(h) due to recursion stack If the tree is balanced, the complexity becomes O(log n). #DSA #Java #BinarySearchTree #CodingJourney #Consistency #LeetCode #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 LeetCode Problem || Count Submatrices With Equal Frequency of X and Y(3212) Today I worked on a problem where we need to count submatrices based on a condition involving characters in a grid. 🧩 Problem Idea We are given a grid containing: 'X' → treated as +1 'Y' → treated as -1 '.' → treated as 0 We need to count submatrices where: ✔ The total sum is 0 ✔ And at least one 'X' is present #Java #DSA #LeetCode #Matrix #Algorithms #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Day 56: Bit-Heavy Sorting 🔢 Problem 1356: Sort Integers by The Number of 1 Bits The mission: Sort an array based on the number of set bits (1s). If there’s a tie, the smaller number wins. The Strategy: • Custom Sort: Swapped a standard sort for a bit-count comparison. • Tie-Breaking: Used Integer.bitCount() to compare 1s, then fell back to raw values if counts were equal. • Bubble Logic: Implemented a nested loop to bubble the "heavier" bit counts to the end. Is O(n²) the fastest way? Definitely not. Does it get the green checkmark for today? Absolutely. Sometimes simple logic just hits different. 🚀 #LeetCode #Java #BitManipulation #Algorithms #Coding #DailyCode
To view or add a comment, sign in
-
-
🚀 Day 14/100 – #100DaysOfCode Challenge 🔍 Problem Solved: Single Number (LeetCode 136) Today’s problem was about finding the element that appears only once in an array where every other element appears twice. 💡 Key Insight: Used the power of XOR (^) bit manipulation Same numbers cancel out → a ^ a = 0 XOR with 0 gives the number → a ^ 0 = a 👉 By XOR-ing all elements, duplicates vanish, leaving the unique number! ⚡ Approach: Traverse the array once Apply XOR on each element Result = single number ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) 🔥 What I Learned: Bit manipulation can simplify problems drastically XOR is super powerful for pairing problems #Day14 #CodingChallenge #Java #DataStructures #Algorithms #BitManipulation #LeetCode #100DaysOfCode #CodingJourney
To view or add a comment, sign in
-
-
Day 37/100 🚀 | #100DaysOfDSA Solved Reverse String by Character Type – LC 3823 This problem required reversing characters in a string — but with a twist. Letters and special characters had to be reversed within their own groups while keeping their original positions relative to each other. Example idea: Letters reverse among letters, special characters reverse among specials. My Approach: • Converted the string to a character array for easier traversal. • Used two stacks — one for letters and one for special characters. • First pass: pushed characters into their respective stacks. • Second pass: rebuilt the string by popping from the correct stack depending on the character type. Time Complexity: O(n) Space Complexity: O(n) Key Learning: Breaking a problem into categories can simplify the logic significantly. Once characters were separated by type, reconstructing the result became straightforward. Small problems. Clear thinking. Consistent progress. 💪 #100DaysOfCode #LeetCode #DSA #Java #Strings #Stacks #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Solved a matrix problem : checking whether one matrix can be obtained from another using rotations. At first it looked a bit tricky, but the key idea was simple: 👉 A 90° rotation can be done using transpose + reverse each row This makes the solution clean and efficient (O(n²)) and is a useful pattern to remember for similar problems. #DataStructures #Algorithms #DSA #Java #LeetCode #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
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