🎯 LeetCode Day 41/50 – Pascal’s Triangle Today’s challenge was about generating Pascal’s Triangle — a classic combinatorial structure where each number is the sum of the two numbers directly above it. 🔺 💡 Concepts used: Recursion to build rows step-by-step Dynamic List handling in Java Base case optimization for smaller triangles 🧩 Key insight: Each row can be constructed from the previous one by summing adjacent elements — a beautiful recursive pattern that reflects mathematical simplicity. 🕒 Runtime: 1 ms (Beats 85.89%) ⚡ 💾 Memory: 42.20 MB (Beats 26.63%) ✅ Result: 30/30 test cases passed — Accepted 🎉 #LeetCode #50DaysOfCode #Java #CodingChallenge #ProblemSolving #PascalTriangle
Generated title: "Solved Pascal's Triangle challenge in Java with recursion and dynamic lists"
More Relevant Posts
-
#Day-70) LeetCode #3234 – Count Substrings With Dominant Ones Just solved an interesting binary string problem where a substring is considered dominant if the number of 1s is greater than or equal to the square of the number of 0s. 🔍 Challenge: Efficiently count all such substrings in a given binary string. 🧠 My Approach (Java): Used a prefix sum array to track the balance between 1s and 0s Explored substring ranges with a smart condition check Focused on clean logic and edge case handling 📈 Why it matters: This problem blends math with string manipulation and highlights how preprocessing (like prefix sums) can drastically reduce brute-force overhead. 📎 Code snippet attached — open to feedback or alternate strategies! #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #CodingInPublic #TechJourney
To view or add a comment, sign in
-
-
23/30 days✅ Solved LeetCode Problem : #70 – Climbing Stairs The challenge was to determine how many distinct ways one can reach the top of a staircase with n steps, where at each step you can either climb 1 or 2 steps. The logic behind the problem is similar to the Fibonacci sequence, where each state depends on the sum of the previous two states. I implemented the solution in Java, using an iterative approach with three variables to optimize space complexity. Instead of using recursion or an array, the approach updates values in constant space (O(1)) while maintaining linear time complexity (O(n)). Here’s the logic in brief: Initialize a = 0, b = 1, and c = 1. For each step, compute c = a + b, then shift values forward (a = b, b = c). Return c as the total number of distinct ways to reach the top. #LeetCode #Java #DynamicProgramming #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 68 String Manipulation Problem 1:- Largest Odd Number in String Task:- Given a numeric string, return the largest-valued odd number (as a substring) or an empty string if none exists. Example: Input: num = "35427" → Output: "35427" My Approach: Started scanning the string from right to left. The first odd digit encountered marks the end of the required substring. Returned the substring from start to that index. Time Complexity:- O(N) Space Complexity:- O(1) Sometimes, it’s not about complex algorithms just a small logical observation can lead to an efficient solution. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #CodeNewbie #StringManipulation #LogicBuilding #CleanCode
To view or add a comment, sign in
-
-
📌 Day 16/100 - Reverse String (LeetCode 344) 🔹 Problem: Reverse a given string in-place — meaning you must modify the original array of characters without using extra space. 🔹 Approach: Used the two-pointer technique — one starting at the beginning and one at the end of the array. Swap characters at both pointers, then move them closer until they meet. Efficient, clean, and runs in linear time without additional memory allocation. 🔹 Key Learnings: In-place algorithms optimize space complexity significantly. The two-pointer pattern is a versatile tool for many array and string problems. Understanding mutable vs immutable structures in Java is crucial for memory efficiency. Sometimes, the simplest logic beats the most complex one. 🧠 “True efficiency lies in simplicity, not complexity.” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #TwoPointers
To view or add a comment, sign in
-
-
🔥 Day 20 | LeetCode Challenge – Decode Ways (Problem #91) Today’s challenge involved decoding an encoded numeric string where each number represents a letter (A–Z). The task was to determine how many possible ways the message can be decoded. 💡 Core Concept: Each number from 1–26 maps to letters A–Z, and the challenge lies in handling overlapping combinations and invalid encodings (like “06”). 📘 Approach: Implemented a Dynamic Programming (DP) solution in Java. Used an integer array dp[] to store the number of decoding ways up to each position. Considered both single-digit and two-digit decodings: Single-digit → valid if between 1 and 9. Two-digit → valid if between 10 and 26. The result was stored in dp[n], representing all valid decoding combinations. ⚙️ Algorithm Used: Dynamic Programming 🧾 Language: Java ⚡ Runtime: 1 ms (Beats 83.21%) 💾 Memory: 43.33 MB 🧠 Insight: Breaking the decoding process into smaller subproblems allowed efficient computation of possible message interpretations. This problem elegantly demonstrates how DP handles overlapping substructures in combinatorial challenges. #Day20 #LeetCode #DecodeWays #DynamicProgramming #JavaDeveloper #100DaysOfCode #ProblemSolving #CodingChallenge #DataStructuresAndAlgorithms #ProgrammingJourney #TechLearning #AlgorithmDesign
To view or add a comment, sign in
-
-
🚀#PostLog35 🧩 Problem: Frequency of the Most Frequent Element (LeetCode #1838) 🔹 Topic: Sliding Window 🔹 Language: Java Challenge was about maximizing the frequency of an element after performing at most k increment operations. The key idea was to use a sliding window combined with sorting: Sort the array to align potential targets. Expand the window while the total operations needed ≤ k. If it exceeds k, shrink the window from the left. Track the maximum frequency achievable. 💡 This approach efficiently balances elements using prefix sums and window logic — no need for nested loops or complex math tricks. ✅ Result: Accepted (Runtime: 33 ms) Another problem done — one step closer to mastering array and window patterns! #LeetCode #Java #CodingJourney #ProblemSolving #DSA
To view or add a comment, sign in
-
-
Solved: LeetCode Problem 922 – Sort Array By Parity II 📌 Difficulty Level: Easy 💻 Language Used: Java 🧠 Topics: Arrays, Index Manipulation, Two-Pointer 🧩 Problem Overview: Rearrange the array so that elements at even indices are even numbers and elements at odd indices are odd numbers. 🎯 Key Learnings: ✅ Practiced separate pointer movement for even/odd indices ✅ Learned how to skip indices in steps of 2 for efficiency ✅ Strengthened control flow in condition-based pointer increment ✅ Designed an O(n) solution without extra space 🛠 Skills Practiced: Index Management Array Rearrangement Two-Pointer Optimization In-place Logic Building ⚡️ Problems like this sharpen thinking about index constraints and help in mastering array partitioning & arrangement patterns. #LeetCode #Java #RotateArray #ProblemSolving #Arrays #LogicBuilding #100DaysOfCode #CodeNewbie #TechCareers #WomenInTech #LearningInPublic #BuildInPublic #DeveloperJourney #CleanCode #DSA #AlgorithmPractice #CodingInterviewPrep #SoftwareDevelopment #AfrozCodes #DailyCoding #CrackTheCodingInterview #TechForAll
To view or add a comment, sign in
-
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
#Day-71) Daily LeetCode – Problem #1513: Number of Substrings With Only 1s Just solved a neat binary string problem that blends math with string manipulation. Here's the challenge: 🧩 Problem: Given a binary string s, count all substrings made of only '1's. Return the result modulo 109+710^9 + 7. 📥 Input: "0110111" 📤 Output: 9 📌 Explanation: Substrings like "1", "11", "111"… all count! 💡 My Java Approach: Track consecutive '1's using a counter For each streak, use the formula n(n+1)2\frac{n(n+1)}{2} to count substrings Apply modulo to handle large results 🔍 Why it matters: This problem highlights how simple math tricks (like prefix sums or substring formulas) can drastically reduce brute-force overhead. 🧠 Always open to feedback or alternate strategies—let’s grow together! #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #CodingInPublic #TechJourney
To view or add a comment, sign in
-
-
💡 LeetCode #15 — 3Sum Today I solved LeetCode Problem 15: 3Sum 🔍 Problem Summary: Given an integer array nums, return all unique triplets (a, b, c) such that: a + b + c = 0 The solution must not contain duplicate triplets. Key Idea: Use sorting + two pointers to reduce the time from O(n³) to O(n²). Steps: Sort the array. Fix one number (nums[f]) in each iteration. Use two pointers (i and j) to find pairs whose sum equals -nums[f]. Skip duplicates for both the fixed index and the pointer values. This efficiently finds all unique triplets. #LeetCode #Java #DSA #TwoPointers #ProblemSolving #CodingChallenge #Algorithms
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