🚀 𝗗𝗔𝗬 𝟭𝟮: 𝗔𝗣𝗣𝗟𝗬𝗜𝗡𝗚 𝗡𝗘𝗦𝗧𝗘𝗗 𝗙𝗢𝗥 𝗟𝗢𝗢𝗣𝗦 𝗧𝗢 𝗣𝗔𝗧𝗧𝗘𝗥𝗡𝗦 🚀 After understanding Nested for Loops on Day 11, today I focused on applying the concept through simple pattern programs ⭐ This is where the real clarity started. 🔹 𝗙𝗥𝗢𝗠 𝗖𝗢𝗡𝗖𝗘𝗣𝗧 𝗧𝗢 𝗖𝗢𝗗𝗘 💡 Yesterday I understood: • Outer loop → controls rows • Inner loop → controls columns Today I applied that knowledge to print a simple pattern like: * ** *** **** Instead of memorizing it, I asked myself: 👉 How many rows are required? 👉 How many stars in each row? 👉 When should the line break happen? Once these answers were clear, writing the nested loop became easy. 🔹 𝗪𝗛𝗔𝗧 𝗜 𝗥𝗘𝗔𝗟𝗜𝗭𝗘𝗗 🧠 Patterns are not about stars. They are about understanding how loops repeat work in a structured way. For every single iteration of the outer loop, the inner loop runs completely. That repetition creates the visual structure. ✨ 𝗞𝗘𝗬 𝗟𝗘𝗔𝗥𝗡𝗜𝗡𝗚 🚀 When the structure of loops is clear, patterns become logical instead of confusing. Small improvements every day lead to strong fundamentals. #Java #CoreJava #NestedForLoop #PatternPrograms #JavaLearning #LearningInPublic #100DaysOfCode
Applying Nested Loops in Java for Pattern Programs
More Relevant Posts
-
🚀 Day 36 of #100DaysOfLeetCode ✅ Solved: Plus One (LeetCode 66) Difficulty: Easy Status: Accepted (114/114 Testcases Passed) Runtime: 0 ms 💯 Today’s problem looked simple but reinforced an important concept — handling carry in arrays. 🧠 Problem Summary: We are given a large integer represented as an array of digits. We need to increment the number by one and return the updated array. 🔎 Key Insight: Start from the last digit (right to left): If digit < 9 → increment and return. If digit == 9 → set it to 0 and carry over. If all digits are 9 → create a new array with an extra digit at the beginning. 💡 Example: Input: [9,9,9] Output: [1,0,0,0] 🎯 What I Practiced Today: Reverse traversal of arrays Carry-forward logic Edge case handling (all 9s case) Writing optimized O(n) solution Even easy problems strengthen fundamentals when you focus on edge cases. Consistency > Complexity. 🔥 #Day36 #100DaysOfCode #LeetCode #Java #DataStructures #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Day 17/100 – LeetCode Challenge Problem Solved: Spiral Matrix Today’s problem required traversing a matrix in spiral order, starting from the top-left corner and moving right, down, left, and up repeatedly until all elements are visited. The key idea is to maintain four boundaries that represent the current layer of the matrix being processed: top, bottom, left, and right. We move in four directions step by step: ->Traverse from left to right across the top row. ->Traverse from top to bottom along the right column. ->Traverse from right to left across the bottom row. ->Traverse from bottom to top along the left column. After completing each direction, the corresponding boundary is adjusted inward so the traversal continues with the inner layer of the matrix. This process continues until the boundaries cross, ensuring every element is visited exactly once. Time Complexity: O(m × n) Space Complexity: O(1) (excluding the result list) Performance: Runtime 0 ms Key takeaway: Many matrix traversal problems become manageable when you define clear boundaries and shrink them step by step. Day 17 completed. Continuing the journey of strengthening algorithmic thinking through consistent practice. #100DaysOfLeetCode #Java #Algorithms #MatrixTraversal #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🔥 Day 97 of #100DaysOfCode Today’s problem: LeetCode – Search in Rotated Sorted Array 🔄🔍 📌 Problem Summary You are given a rotated sorted array and a target. Your task is to return the index of the target if it exists; otherwise return -1. Example: Input: nums = [4,5,6,7,0,1,2], target = 0 Output: 4 🧠 Approach Used: Linear Search In this solution, we simply iterate through the array and check if the current element equals the target. ⚙️ Logic for(int i = 0; i < nums.length; i++){ if(nums[i] == target){ return i; } } return -1; 💡 Explanation Traverse the array from start to end If the target is found → return the index If the loop finishes → return -1 ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) 🚀 Performance Runtime: 0 ms Memory: 43.68 MB 🧠 Learning This problem can also be solved using Binary Search in O(log n) by identifying which half of the rotated array is sorted. But for smaller inputs or quick validation, linear scan works correctly and is simple to implement. Only 3 days left to complete the #100DaysOfCode challenge 🚀 Consistency is the real win here! On to Day 98 🔥 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 20/60 Completed – LeetCode Problem of the Day Challenge Today’s challenge: Check if Binary String Has at Most One Segment of Ones The problem asks us to determine whether a binary string contains at most one continuous segment of '1's. 🧠 Approach & Key Learnings: • Traversed the string once from left to right. • Once a segment of '1's starts, we track it. • If we encounter '0' after the first segment of '1's, we mark that a break occurred. • If another '1' appears after that zero, it means there is more than one segment of ones → return false. • Otherwise, the string contains only one contiguous segment of ones → return true. ⚙️ Key Concepts Practiced: • String traversal • Segment detection in binary strings • Boolean flag tracking • Writing clean linear-time logic Small problem, but a good exercise in carefully tracking patterns while scanning a string. 20 days down. Consistency is getting stronger every day. ⚡ 40 days to go — staying locked in. 🔥 #LeetCode #60DaysChallenge #ProblemOfTheDay #DSA #Java #CodingJourney #Consistency #SoftwareEngineering
To view or add a comment, sign in
-
-
🔥 Day 87 of #100DaysOfCode Today’s challenge: LeetCode: Implement Stack using Queues 📚🔁 📌 Problem Summary Implement a stack (LIFO) using only queue operations: push(x) pop() top() empty() You can only use standard queue operations (offer, poll, peek, isEmpty). 🧠 Approach: Two Queues Since stack is LIFO and queue is FIFO, we simulate stack behavior by rearranging elements during push. ⚙️ Strategy Used: Move all elements from q1 → q2 Add new element to q1 Move everything back from q2 → q1 Now: The newest element is always at the front of q1 pop() becomes simple → just q1.poll() 🔁 Key Idea Make push() costly Make pop() O(1) ⏱ Time Complexity push() → O(n) pop() → O(1) top() → O(1) empty() → O(1) 💾 Space Complexity: O(n) ⚡ Performance Runtime: 0 ms 100% faster than other submissions 🚀 💡 What I Learned Data structures can simulate each other. The trick is choosing where to handle the complexity. Understanding internal behavior matters more than memorizing code. Stack → Queue → Simulation mastery growing stronger 💪 On to Day 88 🔥 #100DaysOfCode #LeetCode #Stack #Queue #Java #DSA #InterviewPrep
To view or add a comment, sign in
-
-
🚀 Day 17/100 – Sorted Squares (Two Pointer Approach) Today I solved the “Sorted Squares” problem on LeetCode. 🔹 Problem: Given a sorted array (non-decreasing order), return an array of the squares of each number, also sorted. 🔹 Brute Force Idea: 1. Square each element. 2. Sort the array again. Time Complexity: O(n log n) ❌ (Not optimal because sorting takes extra time.) 🔹 Optimal Approach (Two Pointer Technique): Since the array is already sorted, the largest square will come from either: - The leftmost negative number - Or the rightmost positive number So I used: • left pointer at start • right pointer at end • filled the result array from the back At each step: Compare absolute values Place the larger square at the current index Move the corresponding pointer ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) ✨ Key Learning: Instead of blindly sorting again, understanding the pattern of negative numbers helped me optimize the solution. #Day17 #100DaysOfCode #LeetCode #Java #DataStructures #Arrays.
To view or add a comment, sign in
-
-
🚀 Day 44 of #100DaysOfCode Solved 1011. Capacity To Ship Packages Within D Days on LeetCode 📦 🧠 Key Insight: We need to find the minimum ship capacity such that all packages can be shipped within D days. This is a classic case of Binary Search on Answer. ⚙️ Approach: 1️⃣ The minimum capacity = max(weight) (since one package must fit) 2️⃣ The maximum capacity = sum of all weights 3️⃣ Apply Binary Search between these bounds 4️⃣ For each capacity mid, simulate shipping: 🔹Keep adding weights until capacity exceeds 🔹Move to the next day when exceeded 5️⃣ If we can ship within D days → try smaller capacity 6️⃣ Else → increase capacity This helps us find the minimum valid capacity efficiently. ⏱️ Time Complexity: O(n log(sum)) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Algorithms #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 20 of #100DaysOfCode Solved 54. Spiral Matrix on LeetCode 🌀 🧠 Key insight: Spiral traversal is all about maintaining boundaries. By shrinking the top, bottom, left, and right limits after each pass, we can cover every element exactly once. ⚙️ Approach: 🔹Maintain four pointers: top, down, left, right 🔹Traverse: 🔹Left → Right (top row) 🔹Top → Bottom (right column) 🔹Right → Left (bottom row) 🔹Bottom → Top (left column) 🔹Update boundaries after each traversal ⏱️ Time Complexity: O(m × n) 📦 Space Complexity: O(1) (excluding output list) #100DaysOfCode #LeetCode #DSA #Matrix #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 523 of #750DaysOfCode 🚀 📌 Problem Solved: Check if Binary String Has at Most One Segment of Ones (LeetCode 1784) 🔎 Problem Summary: Given a binary string s (without leading zeros), we need to check whether the string contains at most one contiguous segment of 1s. If the 1s appear in more than one separate segment, we return false. (LeetCode) 💡 Key Insight: Since the string starts with 1, the only valid structure is: 111...000... If we ever encounter the pattern "01", it means a 1 appeared again after a 0, which creates multiple segments of ones. (AlgoMonster) ⚙️ Approach: Traverse the string or simply check if "01" exists. If "01" is found → more than one segment → return false. ⏱ Complexity: Time: O(n) Space: O(1) 📚 Takeaway: Sometimes string problems become much easier when we identify patterns instead of counting segments. Consistency > Motivation. On to Day 524 tomorrow. 💪 #LeetCode #Java #DataStructures #Algorithms #CodingChallenge #Consistency #ProblemSolving #100DaysOfCode #750DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 521 of #750DaysOfCode 🚀 🔎 1582. Special Positions in a Binary Matrix (LeetCode - Easy) Today I solved a simple yet interesting matrix traversal problem. 🧠 Problem Summary We are given an m × n binary matrix. A position (i, j) is called special if: ✔ mat[i][j] == 1 ✔ All other elements in row i are 0 ✔ All other elements in column j are 0 Our task is to count how many such special positions exist. 💡 Key Idea Instead of checking the entire row and column every time, we can: 1️⃣ Count the number of 1s in every row 2️⃣ Count the number of 1s in every column Then a cell (i, j) is special if: mat[i][j] == 1 rowCount[i] == 1 colCount[j] == 1 ⏱ Time Complexity O(m × n) We traverse the matrix twice. 🧩 What I Learned ✔ Efficiently using row and column counting ✔ Simplifying matrix conditions with precomputation ✔ Writing cleaner solutions for matrix-based problems Step by step progress every day. Consistency is the real key. 🚀 #LeetCode #Java #MatrixProblems #ProblemSolving #DataStructures #CodingJourney #750DaysOfCode #Day521
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