💻 DSA – Day 8: Patterns (Part II – Advanced) Today I explored some of the most interesting and visually appealing pattern problems in Java. These patterns may look simple, but they’re powerful for improving logic, nested loop control, and thinking in terms of rows & columns. 🔶 What I covered today 🔹 Hollow Rectangle Pattern Learned how to combine borders + spaces using conditions. 🔹 Inverted & Rotated Half Pyramid Understanding how rotation affects alignment and spacing. 🔹 Inverted Half Pyramid (Numbers) Patterns that change not just shape, but also the values printed. 🔹 Floyd’s Triangle A classic pattern where numbers increase continuously row by row. 🔹 0–1 Triangle Pattern Great for applying simple mathematical logic to create alternating values. 🔹 Butterfly Pattern One of the most beautiful patterns—perfect symmetry with increasing and decreasing stars. 🔹 Solid Rhombus Pattern Focused on leading spaces + full rows. 🔹 Hollow Rhombus Pattern Combining spacing + boundary conditions for a clean hollow shape. 🔹 Diamond Pattern A combination of upward and downward pyramids to form a centered diamond. 🧠 Why these patterns matter? They sharpen: logical thinking loop flow understanding condition-based pattern design confidence before moving to arrays & recursion 🚀 Consistency is building momentum Loving how each pattern improves the way I think about problems. Next up: more DSA fundamentals. #DSA #Day8 #Java #Patterns #AdvancedPatterns #CodingJourney #100DaysOfCode #LearningInPublic #ProblemSolving
Exploring Advanced Patterns in Java for DSA Day 8
More Relevant Posts
-
DSA Practice – Day 48 🚀 Problem: Sort Array by Parity(LeetCode 905) Problem Statement: Given an integer array nums, move all even integers to the beginning of the array followed by all the odd integers. Return any array that satisfies this condition. ⚡ Brute Force Approach: Create a new array. First, add all even numbers from nums to it. Then, add all odd numbers. Return the new array. Time Complexity: O(n) Space Complexity: O(n) (because of the extra array) ⚡ Optimal Approach (Two Pointer Technique): Use two pointers — one at the start (left) and one at the end (right). If the left element is odd and the right is even, swap them. Move pointers accordingly until they meet. This sorts even and odd numbers in-place without extra space. Time Complexity: O(n) Space Complexity: O(1) ✨ What I Learned: How to use the two-pointer approach for in-place array rearrangement. Simple logic can drastically reduce space usage in problems like these. #DSA #LeetCode #Java #Arrays #TwoPointer #ProblemSolving #Coding #InterviewPrep
To view or add a comment, sign in
-
-
DSA Practice – Day 52 🚀 Problem: Happy Number (LeetCode 202) 📌 Problem Statement: A number is called happy if repeatedly replacing it with the sum of the squares of its digits eventually leads to 1. Return true if it’s a happy number, otherwise false. 🧩 Brute Force Approach: Keep track of all numbers seen in a set to detect loops. If you reach 1, Happy Number If a number repeats, Not Happy Time Complexity: O(log n) Space Complexity: O(log n) ⚡ Optimal Approach (Floyd’s Cycle Detection): Use two pointers — slow and fast. Move slow by one step and fast by two steps (using sum of squares). If they meet, there’s a cycle (not happy). If you reach 1, it’s a happy number. Time Complexity: O(log n) Space Complexity: O(1) ✨ What I Learned: How to detect cycles in number transformations. Applying Floyd’s cycle detection beyond linked lists. Improved logical problem-solving for number-based questions. #LeetCode #Java #ProblemSolving #DSA #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
-
DSA Practice – Day 54 🚀 Problem: Maximum Product Subarray Problem Statement: Find the contiguous subarray within an array (containing at least one number) which has the largest product. ⚡ Brute Force Approach: Generate all possible subarrays. Calculate the product of each subarray. Keep track of the maximum product found. Time Complexity: O(n²) Space Complexity: O(1) ⚡ Optimal Approach (Prefix–Suffix Product): Maintain two running products — prefix (left to right) and suffix (right to left). Reset the product to 1 whenever it becomes 0. Keep updating the maximum product found so far. Time Complexity: O(n) Space Complexity: O(1) ✨ What I Learned: Prefix–suffix logic can simplify problems that seem complex initially. Resetting counters or products helps handle zeros effectively. Great way to practice array traversal from both ends! #LeetCode #Java #DSA #ProblemSolving #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
🚀 Day 392 of #500DaysOfCode Today I solved LeetCode 661: Image Smoother 🖼️ This problem was all about applying a 3x3 smoothing filter on an image (represented as a 2D matrix). For each pixel, we calculate the average value of the surrounding pixels — considering only the valid neighbors — and take the floor of the result. It’s a great exercise for mastering matrix traversal and boundary condition handling in Java! 💡 🔍 Key Learnings: How to navigate a 2D grid using directional arrays. Handling edge cells carefully (like corners and borders). Efficiently applying averaging filters using nested loops. 🧠 Example: Input: [[100,200,100],[200,50,200],[100,200,100]] Output: [[137,141,137],[141,138,141],[137,141,137]] 💻 Language: Java 🔹 Difficulty: Easy Every problem like this strengthens my fundamentals in array manipulation and spatial algorithms — one step closer to writing cleaner, more efficient code. #Day392 #LeetCode #Java #CodingChallenge #100DaysOfCode #500DaysOfCode #ProblemSolving #SoftwareEngineering #MatrixAlgorithms
To view or add a comment, sign in
-
-
🚀 Day 398 of #500DaysOfCode 🔹 Problem: 914. X of a Kind in a Deck of Cards 🔹 Difficulty: Easy 🔹 Language Used: Java ☕ 🧩 Problem Summary: Given a deck of cards where each card has an integer, the goal is to check if we can divide the deck into groups such that: Each group has exactly X cards, where X > 1, and All cards in a group have the same integer. If such a partition is possible, return true — otherwise, return false. 💡 Key Idea: The solution relies on finding the greatest common divisor (GCD) of all card frequencies. If the GCD of all counts is greater than 1, we can form valid groups; otherwise, we can’t. ⚙️ Approach: 1️⃣ Count the frequency of each card using a HashMap. 2️⃣ Compute the GCD of all frequency values. 3️⃣ If GCD > 1, return true; else, false. 🧠 Concepts Used: HashMap GCD (Euclidean Algorithm) Frequency Counting ✅ Example: Input: [1,2,3,4,4,3,2,1] → Output: true Input: [1,1,1,2,2,2,3,3] → Output: false 📘 Lesson Learned: Even simple-looking problems can hide elegant mathematical patterns. Understanding GCD turned out to be the key! 💪 #Day398 #Java #LeetCode #ProblemSolving #CodingChallenge #LearnEveryday #Programming #Developer #100DaysOfCode #500DaysOfCode
To view or add a comment, sign in
-
-
DSA Practice – Day 51 🚀 Problem: Max Consecutive Ones III Problem Statement: Given a binary array nums and an integer k, return the maximum number of consecutive 1’s you can get if you can flip at most k 0’s. 🧩 Brute Force Approach: Try flipping each possible group of 0’s and count the consecutive 1’s after every flip. Track the maximum length obtained. Time Complexity: O(n²) Space Complexity: O(1) ⚡ Optimal Approach (Sliding Window): Use two pointers left and right to maintain a window of valid elements. Expand the window by moving right. If zero count exceeds k, move left to shrink the window. Update the maximum window size. Time Complexity: O(n) Space Complexity: O(1) ✨ What I Learned: Sliding window is great for problems involving subarrays with constraints. How to balance window size dynamically while keeping track of conditions. Improved logical thinking for optimization problems. #LeetCode #Java #SlidingWindow #ProblemSolving #DSA #CodingJourney #PlacementPrep
To view or add a comment, sign in
-
-
💡 Day 97 of My DSA Challenge – Single Element in a Sorted Array 🔷 Problem : 540. Single Element in a Sorted Array 🔷 Goal : Find the single element that appears only once in a sorted array where all other elements appear exactly twice, in O(log n) time and O(1) space. 🔷 Key Insight : The array is sorted, and elements appear in pairs — except for one. We can use Binary Search on Indices : Check the mid element and compare it with neighbors. If mid is unique → return it. Otherwise, depending on whether the pair is on the left or right and the parity of the remaining elements, move left or right. This works because the single element shifts the pairing pattern in the array, allowing us to discard half the search space each time. 🔷 My Java Approach : 1️⃣ Binary search over array indices. 2️⃣ Compare mid with neighbors to detect the single element. 3️⃣ Adjust search space using parity logic. 🔷 Complexity : Time → O(log n) Space → O(1) Binary search isn’t just for sorted numbers — it can also be applied to patterns and structural properties in arrays. Recognizing such patterns allows efficient solutions even when the array has special constraints. 🚀 #100DaysOfCode #Day97 #LeetCode #DSA #Java #ProblemSolving #BinarySearch #CodingChallenge #Programming #LearnToCode #CodingLife #SoftwareEngineering #Algorithms #DataStructures #TechJourney #CodeEveryday #EngineerMindset #DeveloperJourney #GrowthMindset #CodeNewbie #KeepLearning #ApnaCollege #AlphaBatch #ShraddhaKhapra
To view or add a comment, sign in
-
-
🚀Day 39/100 - Problem of the day :- Minimum Number of Operations to Make all Array Elements Equal to 1. 🎯 Goal: Solved a problem on LeetCode involving finding the minimum operations to make all elements equal using the GCD (Greatest Common Divisor) approach in Java. 💡 Core Idea: The key insight was to use the Euclidean algorithm to compute GCD efficiently and track how many operations are needed based on the number of 1’s and the resulting GCD values within the array. 📘 Key Takeaway: Optimizing logic with mathematical properties (like GCD) can simplify problems that seem complex at first. Understanding patterns in number theory helps unlock elegant solutions for array manipulation problems. 🧠 Time Complexity: O(n²) — due to nested iteration and repeated GCD calculations. 💾 Space Complexity: O(1) — only a few integer variables are used; no extra data structures needed. #100DaysChallenge #DSA #Java #Day39 #Leetcode #SolvingProblem #CodingJourney
To view or add a comment, sign in
-
-
Day 38 of #100daysOfCode Problem: 3542. Minimum Operations to Convert All Elements to Zero Difficulty: Medium Language: Java Status: Solved Problem Summary: You are given an integer array nums. In one operation, you can select a subarray [i, j] and set all occurrences of the minimum non-zero integer in that subarray to 0. Your goal is to make all elements zero in the minimum number of operations. Key Insight: This problem can be reduced to tracking how many times the current subarray’s minimum changes. A monotonic stack efficiently tracks the increasing sequence of elements. Each time a smaller element is encountered, it indicates that a set of operations can be completed (popped from stack). What I Learned: Monotonic stacks aren’t just for “next greater” or “next smaller” problems—they can also represent layers of operations or intervals. Elegant one-pass logic using stack simulation can drastically simplify range operation problems. #Day38 #100DaysOfCode #LeetCode #DSA #MonotonicStack #Java #Algorithms #ProblemSolving #CodingChallenge #SoftwareEngineering #LearnByCoding
To view or add a comment, sign in
-
-
💻 Day 11 of #100DaysOfLeetCode – Rotate Image Today’s challenge was “Rotate Image”, a classic matrix manipulation problem that tests both logic and spatial reasoning. 🔹 Problem Statement: Given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise) — all in place, without using extra memory for another matrix. 🔹 My Approach (in Java): I used a two-step in-place transformation technique: 1️⃣ Transpose the matrix — swap elements across the diagonal (matrix[i][j] ↔ matrix[j][i]). 2️⃣ Reverse each row — to achieve the 90° clockwise rotation. This approach ensures O(1) extra space and O(n²) time complexity, which is optimal for this problem. 🔹 Key Takeaways: ✅ Learned how matrix transformations can be broken down into simpler operations. ✅ Improved understanding of in-place algorithms and memory efficiency. ✅ Reinforced clean coding habits and edge case handling. Every rotation brings me one step closer to mastering problem-solving patterns! 💪 #100DaysOfLeetCode #CodingJourney #RotateImage #Java #DSA #ProblemSolving #LeetCode #CodingChallenge #LearningEveryday
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