🌟 Day 85 of My #100DaysOfCode Challenge 🧩 Problem: LeetCode 119 – Pascal’s Triangle II 🧠 Understanding the Problem We need to return the rowIndexth (0-indexed) row of Pascal’s Triangle. Each number is formed by adding the two numbers directly above it from the previous row. 📘 Example: Input: rowIndex = 3 Output: [1, 3, 3, 1] ⚙️ Approach Start with [1] as the first row. For each new row, update the list from right to left (so we don’t overwrite values that we still need). Append 1 at the end of each iteration to complete the row. 🕒 Complexity Time Complexity: O(n²) Space Complexity: O(n) ✅ (optimized — we use only one list) 💡 Key Learning This problem emphasizes in-place updates — a technique often used to optimize space in dynamic programming problems. ✨ Takeaway Building Pascal’s Triangle row by row mirrors how small consistent steps lead to structured growth — just like progress in coding! 🚀 💬 “Each layer of learning strengthens the next — one row at a time.” 💛 #Day85 #LeetCode #Java #DSA #DynamicProgramming #ProblemSolving #100DaysOfCode #CodingChallenge
Solved LeetCode 119 – Pascal’s Triangle II with Java
More Relevant Posts
-
📌 Day 24/100 - Maximum Points You Can Obtain from Cards (LeetCode 1423) 🔹 Problem: You’re given an array of card points where each card has some value. You can take exactly k cards — but only from the beginning or end of the row. The goal is to maximize your total score. 🔹 Approach: This problem is a perfect case for the sliding window technique. Start by taking the sum of the first k cards (left side). Then, gradually move one card from the left side to the right side — each time removing one card from the start and adding one from the end. Track the maximum sum at each step. ✅ This gives an O(k) time solution — efficient and clean! 🔹 Key Learning: Use sliding window when you need to balance two ends dynamically. Prefix sums aren’t always needed — direct window manipulation works wonders. Optimization often lies in reducing repeated work, not complex math. A simple yet powerful logic: “Take, replace, compare — repeat!” #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #SlidingWindow #CodingJourney
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode 30 – Substring With Concatenation of All Words. 🧩 What was the problem? Given a string and a list of words (all same length), you have to find every starting index where all the words appear together as a continuous substring, in any order. Basically a sliding-window puzzle with fixed word sizes and frequency matching. 🛠️ What was my approach? • Counted all words using a map • Used multiple sliding windows based on word length • Expanded the window word by word • If a word appeared more than needed, I moved the left pointer forward • Added the index when the window matched every word exactly The key was treating the string in equal chunks, not character by character. 📚 What I learned Working with strings becomes much easier when you break the problem into predictable pieces. Managing window boundaries is the real challenge here, and walking through tiny examples helps more than you think. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 68 of #100DaysOfChallenge Today's problem: 3461. Check If Digits Are Equal in String After Operations I (LeetCode - Easy) This problem was a fun blend of pattern observation and modular arithmetic — a great reminder that even simple-looking questions can strengthen your logical flow and coding discipline on LeetCode. 🧩 Problem Overview: We’re given a string of digits, and in each step, we repeatedly calculate the sum of every pair of consecutive digits modulo 10, until only two digits remain. Finally, we check whether those two digits are equal. 💡 My Approach: Used a straightforward simulation approach — repeatedly computing new strings of digits using modular arithmetic until only two digits were left. It’s simple, direct, and performs efficiently for short strings. ⚙️ Language: Java ⚡ Runtime: 8 ms (Beats 72.03%) 💾 Memory: 44.67 MB (Beats 69.77%) ✅ Result: Accepted — 706 / 706 test cases passed Every daily problem adds another layer of precision and confidence. Consistency isn’t just about coding every day — it’s about learning something new with every attempt. 🌱 On to the next challenge 💪 #100DaysOfCode #LeetCode #ProblemSolving #Java #CodingChallenge #Programming #DeveloperJourney #LearningEveryday #TechMindset #Consistency
To view or add a comment, sign in
-
-
✅ Day 54 of LeetCode Medium/Hard Edition Today’s challenge was “Maximum Sum of 3 Non-Overlapping Subarrays” — a brilliant mix of prefix sums, dynamic programming, and optimization logic 🎯 📦 Problem: You’re given an integer array nums and a fixed length k. You must select three non-overlapping subarrays of length k such that their total sum is maximized, and return the starting indices of these subarrays. 🔗 Problem Link: https://lnkd.in/g76A35cZ ✅ My Submission: https://lnkd.in/gB-nDGqu 💡 Thought Process: First, precompute the sum of every k-length window using prefix sums. Then, maintain two helper arrays: left[i] → index of best (maximum sum) window from the left up to i right[i] → index of best window from the right starting at i For each possible middle window, combine it with the best left and right windows to form the maximum total sum. Track and update the maximum configuration across all possible middle positions. ⏱ Complexity: Time: O(n) Space: O(n) 🔥 Key Takeaway: This problem highlights the power of prefix sums and precomputation — turning what could be a brute-force O(n³) nightmare into a sleek, linear-time solution. Sometimes, the smartest code isn’t recursive… it’s prepared! 💪 #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #PrefixSum #ProblemSolving #Java #CodingJourney
To view or add a comment, sign in
-
-
💡 LeetCode 3467 – Transform Array 💡 Today, I solved LeetCode Problem #3467: Transform Array, which focuses on array manipulation and the use of conditional logic in Java — a neat problem that strengthens core programming fundamentals. ⚙️ 🧩 Problem Overview: You’re given an integer array nums. Your task is to: Replace even numbers with 0 Replace odd numbers with 1 Then, sort the transformed array in ascending order. 👉 Example: Input → nums = [4, 7, 2, 9] Output → [0, 0, 1, 1] 💡 Approach: 1️⃣ Iterate through the array. 2️⃣ Use a ternary operator to transform each element (even → 0, odd → 1). 3️⃣ Sort the array to arrange all zeros before ones. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n log n) — due to sorting. ✅ Space Complexity: O(1) — in-place transformation. ✨ Key Takeaways: Practiced logical thinking and ternary operations in Java. Strengthened understanding of array transformations and sorting. Reinforced the value of writing clean, concise, and efficient code. 🌱 Reflection: Even simple transformation problems like this one sharpen the habit of thinking algorithmically. Consistency in small challenges leads to big growth in problem-solving skills. 🚀 #LeetCode #3467 #Java #ArrayManipulation #LogicBuilding #ProblemSolving #CodingJourney #DSA #CleanCode #ConsistencyIsKey
To view or add a comment, sign in
-
-
🚀 Day 412 of #500DaysOfCode 🔹 LeetCode 474: Ones and Zeroes Difficulty: Medium | Topic: Dynamic Programming Today’s problem was all about balancing limits and maximizing choices — a classic 0/1 Knapsack twist! 🎒 🧩 Problem Summary: Given a list of binary strings and two integers m and n, find the largest subset of strings such that the total number of 0s ≤ m and the total number of 1s ≤ n. Example: Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3 Output: 4 Explanation: Subset = {"10","0001","1","0"} ⚙️ Key Idea: Think of it like a two-dimensional knapsack problem: Each string "costs" a certain number of 0s and 1s. You have two limits — m zeros and n ones. Goal → pick the maximum number of strings without exceeding limits. We use a 2D DP table where: dp[i][j] = max number of strings we can form with i zeros and j ones. Update rule: 💡 Learning: This problem beautifully shows how Dynamic Programming can handle problems with multiple constraints. Just like in life — when you have limited time and energy, plan your choices smartly to maximize growth 🔥 💻 #DynamicProgramming #LeetCode #CodingChallenge #Java #ProblemSolving #CodeNewbie #100DaysOfCode #500DaysOfCode #LearningEveryday
To view or add a comment, sign in
-
-
📌 Day 12/100 – 100 Days of Code Challenge 🚀 Today’s LeetCode challenge: “Trapping Rain Water” (LeetCode #42) – one of the most popular Hard-level problems that strengthens logic building and array manipulation skills. 🔹 Approach: Used precomputed leftMax and rightMax arrays to determine how much water each bar can trap. For every index, the trapped water = min(leftMax[i], rightMax[i]) - height[i]. 🔹 Key Learnings: Improved understanding of prefix and suffix computations. Reinforced problem-solving using array-based preprocessing. Time Complexity: O(n) Space Complexity: O(n) #100DaysOfCode #LeetCode #Java #DSA #Arrays #TwoPointer #ProblemSolving #CodingJourney #DynamicProgramming #DailyChallenge
To view or add a comment, sign in
-
-
✅ Day 50 of LeetCode Medium/Hard Edition Today’s challenge was Solving Questions With Brainpower 🧠✨ — a fascinating DP problem about maximizing total points while managing cooldown constraints! 📦 Problem: You’re given an array questions[i] = [points, brainpower], where: Solving question i gives you points points, But you must skip the next brainpower questions. You can either solve or skip each question in order. Your task: find the maximum total points you can earn. 🔗 Problem: https://lnkd.in/gqgx6Di8 ✅ My Submission: https://lnkd.in/geCmW628 💡 Approach: This is a Dynamic Programming problem, solved efficiently in reverse order. We define dp[i] as the maximum points achievable starting from question i. 1️⃣ Iterate backwards from the last question. 2️⃣ For each question, we have two choices: Skip it: take dp[i + 1]. Solve it: earn points[i] + dp[i + brainpower[i] + 1]. 3️⃣ Take the maximum of both options and store it in dp[i]. 4️⃣ The answer will be dp[0] — the max score starting from the first question. 📈 Key Observations: The problem exhibits optimal substructure — each decision depends on future outcomes. Bottom-up DP avoids recursion and ensures efficiency. We balance immediate rewards with future opportunities (a classic “skip or take” DP pattern). ⏱ Complexity: Time: O(n) Space: O(n) 🚀 A great example of planning ahead — just like solving real-life problems strategically! #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #ProblemSolving #CodingJourney #Java
To view or add a comment, sign in
-
-
🚀 Day 73 of #100DaysOfCode Today I solved LeetCode 3346 – Maximum Frequency of an Element After Performing Operations I 🧩 This problem was all about logical range manipulation — figuring out how many elements could be converted into the same number when each element can be modified by ±k, but with a limited number of allowed operations. At first, it felt similar to the “most frequent element” sliding window problem, but the twist here was controlling how many elements can be changed, not just the total cost. After a few failed attempts (and a battle with edge cases 😅), I finally implemented a correct solution using the difference array + prefix sum approach. 💡 Key Takeaways: Think in terms of ranges, not just differences. Prefix-sum (difference map) logic is incredibly powerful for interval counting. Always recheck constraints — “number of operations” vs “total cost” makes a huge difference! Here’s a snippet from my final Java solution: int achievable = Math.min(running, same + numOperations); ans = Math.max(ans, achievable); It’s small details like these that make problem-solving such a rewarding process 💪 #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving #DSA #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Just solved LeetCode 648 – Replace Words. 🟩 What was the problem? You’re given a list of root words and a sentence. For every word in the sentence, you need to replace it with the shortest root that matches its prefix. If multiple roots match, you pick the smallest one. If none match, you leave the word as it is. 🛠️ What was my approach? • Grouped all roots in a HashMap based on their first character • Split the sentence into individual words • For each word, checked only the relevant roots (same starting character) • Picked the shortest matching root if multiple matched • Built the final updated sentence using a StringBuilder This avoided checking every root against every word and kept things pretty efficient. 📚 What I learned Working with strings becomes simpler when you organize the data around predictable patterns. Grouping roots by their first letter saved a lot of unnecessary comparisons. Small structural changes make the whole solution cleaner. #LeetCode #Java #DSA #CodingPractice #ProblemSolving
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