🔹 Day 40 – LeetCode Practice Problem: Find Greatest Common Divisor of Array (LeetCode #1979) 📌 Problem Statement: Given an integer array nums, find the greatest common divisor (GCD) of the smallest and largest numbers in the array. ✅ My Approach (Java): 1. Find the minimum and maximum elements in the array. 2. Starting from the smaller number and going downwards, check for the highest integer that divides both min and max. 3. Return that integer as the GCD. 📊 Complexity: Time Complexity: O(n + min(a, b)) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory: 43.41 MB (Beats 41.55%) 💡 Reflection: This problem shows how basic math logic and loop optimization can lead to extremely efficient solutions. A simple and powerful way to practice number theory in coding! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
"LeetCode #1979: GCD of Array Elements in Java"
More Relevant Posts
-
📌 Day 4/100 - Minimum Size Subarray Sum (LeetCode 209) 🔹 Problem: Given an array of positive integers and a target value, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. If there’s no such subarray, return 0. 🔹 Approach: Used the Sliding Window technique for an optimized solution: Initialize two pointers (low, high) and a running sum. Expand the window by moving high until the sum ≥ target. Once valid, shrink the window from the left to find the smallest subarray. Keep updating the minimum length throughout. This reduced the time complexity from O(n²) (brute force) to O(n). 🔹 Key Learning: Sliding Window is ideal for problems with contiguous subarrays. Optimization often comes from adjusting the window efficiently. Each problem strengthens logical flow and pattern recognition. Another step forward in mastering DSA and problem-solving consistency! ⚡ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #SlidingWindow
To view or add a comment, sign in
-
-
📌 Day 18/100 - Valid Palindrome (LeetCode 125) 🔹 Problem: Determine whether a string reads the same forward and backward, ignoring case and non-alphanumeric characters. 🔹 Approach: Implemented a two-pointer technique. Skipped all non-alphanumeric characters. Compared characters from both ends in lowercase. Returned true if all matched, otherwise false. 🔹 Key Learning: Two-pointer method keeps logic clean and efficient. Character handling is key when data isn’t uniform. Time complexity: O(n), Space complexity: O(1). Sometimes, solving elegantly is better than solving fast. ✨ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney
To view or add a comment, sign in
-
-
🔥 Day 17 of My LeetCode Journey — Problem #377: Combination Sum IV (Dynamic Programming) Today’s focus was on Dynamic Programming — specifically tackling problems where order matters in combinations. 🧩 Problem Summary: Given an array of distinct integers and a target integer, the task was to compute the number of possible combinations that sum up to the target. 💡 Approach & Key Insights: Utilized bottom-up Dynamic Programming (1D array approach) to efficiently compute results. Base case: dp[0] = 1, representing one way to reach a sum of zero. Iteratively built combinations where the sequence order impacts the outcome, differentiating it from subset problems. ⚙️ Algorithmic Complexity: Time: O(n × target) Space: O(target) 📈 Performance Outcome: ✅ Accepted Solution ⚡ Runtime: 1 ms (Beats 67.14% of Java submissions) 💾 Memory: 41.19 MB Each day’s challenge continues to refine my analytical reasoning and problem-solving efficiency, bringing me one step closer to mastering algorithmic design patterns in Java. #LeetCode #Java #DynamicProgramming #CodingJourney #ProblemSolving #TechLearning #SoftwareEngineering
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 32/100 – Count and Say (LeetCode 38) 🔹 Problem: Given an integer n, return the nth term of the Count and Say sequence, where each term is generated by describing the digits of the previous term. 🔹 Approach: Used recursion to generate the previous sequence (n-1) and built the current one by counting consecutive identical digits. Utilized StringBuilder for efficient string formation during traversal. 🔹 Key Learning: Improved recursion and pattern recognition skills. Practiced string manipulation and efficient concatenation. Understood how to construct sequences based on descriptive logic. 🔹 Complexity: Time: O(m) per level (m = length of previous term) Space: O(n) due to recursion depth #100DaysOfCode #LeetCode #Java #Recursion #Strings #ProblemSolving #DSA #CodingPatterns #Motivation #descipline
To view or add a comment, sign in
-
-
💡 LeetCode 1929 – Concatenation of Array 💡 Today, I solved LeetCode Problem #1929: Concatenation of Array, a simple yet satisfying problem that tests your understanding of array manipulation and indexing in Java. ⚙️📊 🧩 Problem Overview: You’re given an integer array nums. Your task is to create a new array ans such that ans = nums + nums (i.e., concatenate the array with itself). 👉 Example: Input → nums = [1,2,1] Output → [1,2,1,1,2,1] 💡 Approach: 1️⃣ Find the length n of the given array. 2️⃣ Create a new array of size 2 * n. 3️⃣ Loop through nums once — place each element both at index i and index n + i. 4️⃣ Return the resulting array. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Single traversal of the array. ✅ Space Complexity: O(n) — For the concatenated array. ✨ Key Takeaways: Practiced index manipulation and array construction. Reinforced the importance of efficient iteration. A great warm-up problem that strengthens logical thinking and array fundamentals. 🌱 Reflection: Even the simplest problems build the foundation for solving more complex ones. Every bit of consistent practice helps in mastering problem-solving and clean coding habits. 🚀 #LeetCode #1929 #Java #ArrayManipulation #DSA #CodingJourney #CleanCode #ProblemSolving #AlgorithmicThinking #ConsistencyIsKey
To view or add a comment, sign in
-
-
💻 Day 69 of #LeetCode100DaysChallenge Solved LeetCode 264: Ugly Number II a dynamic programming problem that improves sequence generation and pointer-based optimization skills. 🧩 Problem: An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Given an integer n, return the n-th ugly number. 💡 Approach — Dynamic Programming with Three Pointers: 1️⃣ Maintain an array dp where dp[i] stores the i-th ugly number. 2️⃣ Use three pointers p2, p3, and p5 to track multiples of 2, 3, and 5 respectively. 3️⃣ At each step, choose the smallest of dp[p2]*2, dp[p3]*3, and dp[p5]*5 as the next ugly number. 4️⃣ Increment the corresponding pointer(s) to avoid duplicates. 5️⃣ Continue until the nth ugly number is found. ⚙️ Complexity: Time: O(N) — one pass to generate all ugly numbers Space: O(N) — for storing the sequence ✨ Key Takeaways: ✅ Strengthened understanding of pointer-based DP techniques. ✅ Learned how to efficiently generate sorted multiplicative sequences. ✅ Practiced optimization over brute-force factor checking. #LeetCode #100DaysOfCode #Java #DynamicProgramming #TwoPointers #Math #DSA #ProblemSolving #CodingJourney #WomenInTech
To view or add a comment, sign in
-
-
📌 Day 159 of Coding - Make Array Elements Equal to Zero (LeetCode - Easy) 🎯 Goal: Given an integer array nums, find the number of valid starting positions and directions such that by repeatedly decrementing and reversing direction (based on the rules), all elements eventually become 0. 💡Approach & Debugging: First computed total sum using Arrays.stream(nums).sum(). Maintained two prefix sums : left and right. For each index i where nums[i] == 0: Incremented left and decremented right progressively. Checked whether the left and right sums balance according to the movement rules. Counted valid selections when the balance was perfect or off by just one. ✔️ Time Complexity: O(N) - single pass through the array. ✔️ Space Complexity: O(1) - constant extra space. #Day159 #LeetCode #Simulation #Arrays #PrefixSum #Java #ProblemSolving #DSA #CodingChallenge #100DaysOfCode #Algorithms #InterviewPrep #SoftwareEngineering #DataStructures #CodeNewbie #ProgrammersLife
To view or add a comment, sign in
-
-
🧩 Day 78 of #100DaysOfCode Challenge 🧩 📘 LeetCode 56 — Merge Intervals Topic: Arrays & Sorting Today’s problem was about merging overlapping intervals — a real test of logical thinking and array manipulation skills! 💡 Problem Summary: Given multiple intervals, the goal is to merge all overlapping ones and return a list of non-overlapping intervals that cover all ranges in the input. ⚙️ Approach (Brute + Optimized): 1️⃣ Sort all intervals based on their start value. 2️⃣ Compare the current interval with the previous one: If they overlap, merge them by updating the end time. If not, add the previous interval to the result. 3️⃣ Continue until all intervals are processed. 🧠 Key Learning: Sorting simplifies overlapping detection. Interval-based problems help strengthen array and logic handling. Real-world application: scheduling problems and timeline merging! ✨ Each problem is another step toward mastering patterns in DSA. #Day78 #LeetCode #100DaysOfCode #Java #DSA #ProblemSolving #WomenInTech #CodingJourney #Arrays #Sorting
To view or add a comment, sign in
-
-
🚀 Day 47 of My LeetCode Journey 🚀 Problem: Sum of Square Numbers Topic: Math / Two Pointers 🧠 Approach: To check if a number c can be expressed as the sum of squares of two integers (a² + b² = c), we use the two-pointer technique: Start a = 0 and b = √c Calculate sum = a² + b² If sum == c → ✅ return true If sum < c → increase a If sum > c → decrease b Repeat until a <= b. ⏱️ Complexity: Time: O(√c) Space: O(1) This problem beautifully combines mathematical logic with an efficient two-pointer approach — clean and elegant! 💡 #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #DSA
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