🚀 Cracked the “Between Two Sets” Problem using Java! I recently worked on a problem that really strengthened my understanding of number theory concepts like LCM (Least Common Multiple) and GCD (Greatest Common Divisor). 🔍 Problem Summary: Given two arrays, the task is to find how many integers satisfy: ✔️ All elements of the first array are factors of the integer ✔️ The integer is a factor of all elements of the second array 💡 Approach I Used: 👉 Calculated LCM of the first array 👉 Calculated GCD of the second array 👉 Counted multiples of LCM that perfectly divide the GCD ✨ This optimized approach avoids brute force and improves efficiency — a great example of applying core math concepts in coding! 🧠 Key Learnings: • Practical use of LCM & GCD • Optimization over brute force • Problem-solving mindset for coding interviews 💻 Implemented in Java and tested with multiple cases successfully. 📌 Always exciting to see how mathematical concepts power efficient algorithms! #Java #DataStructures #Algorithms #Coding #ProblemSolving
Cracking Between Two Sets Problem with Java using LCM and GCD
More Relevant Posts
-
Day 7 of Java with DSA Journey 🚀 📌 Topic: Missing Number (LeetCode 268) Quote: "Sometimes the best way to solve a coding problem is to put down the keyboard and pick up a calculator." ✨ What I learned today: 🔹 Mathematical Optimization: Instead of brute force, I used a simple formula to compute the expected sum. {Sum} = \frac{n(n+1)}{2} 🔹 Core Idea: Expected Sum − Actual Sum = Missing Number 🔹 Alternative Approach: Used XOR technique where duplicates cancel out → leaving the missing value. 🔹 Efficiency: ✔️ Time Complexity: O(n) ✔️ Space Complexity: O(1) 🧠 Problem Solved: ✔️ Missing Number 💡 Key Insight: We often jump to HashSet or Sorting, but this problem taught me to pause and think mathematically first. A simple formula reduced space complexity from O(n) → O(1) 🚀 ⚡ Interview Tip (Important!): Be careful of integer overflow in Java: n * (n + 1) can exceed int limit Use long OR switch to XOR method for safety Consistency is the real key 🔑 #DSA #LeetCode #Java #Mathematics #CodingJourney #ProblemSolving #Day7 #Algorithms #Optimization #Array #MCA #lnct #100DaysOfCode #Algorithms #SoftwareEngineering #InPlaceAlgorithms #TechLearning #JavaDeveloper
To view or add a comment, sign in
-
-
🚀 Day 50 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Permutation Logic 🧩 Problem Solved: Next Permutation Problem: Given an array representing a permutation, rearrange it into the next lexicographically greater permutation. If not possible, rearrange it to the lowest possible order. Approach: Identified the first decreasing element from the right, swapped it with the next greater element, and reversed the suffix to get the next permutation in order. Key Learning: ✔️ Understanding lexicographical order ✔️ Breaking complex problems into clear steps ✔️ Combining search, swap, and reverse techniques If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 73 of #100DaysOfLeetCode 💻✅ Solved #389. Find the Difference problem in Java. Approach: • Initialized a variable to store the sum • Added ASCII values of all characters in string t • Subtracted ASCII values of all characters in string s • The remaining value represents the extra character • Converted the result back to character and returned it Performance: ✓ Runtime: 1 ms (Beats 99.89% submissions) 🚀 ✓ Memory: 42.77 MB (Beats 97.03% submissions) Key Learning: ✓ Practiced optimized string traversal using enhanced for-loop ✓ Reinforced understanding of ASCII-based solutions ✓ Learned how mathematical approaches can simplify problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Math #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 7/100 – DSA Journey Today’s focus was on implementing a classic and important problem in number theory — Armstrong Numbers — using Java. 🔍 What I built: A program to find all Armstrong numbers within a given range (100 to 2000). 💡 Approach Breakdown: Iterated through each number in the range Counted the number of digits Extracted each digit and computed its power using Math.pow() Summed the results and compared with the original number Printed the number if it satisfies the Armstrong condition ⚙️ Key Concepts Used: Loops (while, for) Mathematical logic (digit extraction, power calculation) Function design for reusability Clean iteration over a range 📌 Output Observed: 153, 370, 371, 407, 1634 📈 Learning Insight: This problem strengthened my understanding of number manipulation and algorithmic thinking, which are fundamental in DSA and frequently asked in interviews. 🔥 Consistency is the key — building problem-solving skills step by step! #Day7 #100DaysOfCode #DSA #Java #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnInPublic 🙌 Tagging: 10000 Coders Pathulothu Navinder
To view or add a comment, sign in
-
-
🚀 Week 9 Completed – #100DaysOfCode | DSA in Java Continuing the journey with consistent progress and deeper problem-solving. This week I focused on advanced tree concepts and sliding window technique, which are crucial for coding interviews. 📌 Topics Covered This Week: 🔹 Binary Search Trees (BST) Learned BST properties and operations Solved problems like finding the largest BST in a Binary Tree 🔹 Binary Trees (Advanced) Practiced problems like sum of left leaves Strengthened recursive thinking and tree traversal logic 🔹 Sliding Window Technique Applied sliding window approach to optimize subarray problems Implemented maximum subarray sum using sliding window 📌 Previously Covered Foundation: ✔ Arrays, Strings, Bit Manipulation ✔ Recursion & Backtracking ✔ Linked List, Stack, Queue ✔ Greedy Algorithms & Binary Trees 🧠 Key Learnings • Tree-based problems require a strong understanding of recursion and structure • Sliding window significantly reduces time complexity from O(n²) to O(n) • Choosing the right approach is becoming more intuitive with practice • Focus is now shifting towards optimization and pattern recognition 💻 Maintaining a structured GitHub repository with all topics organized step-by-step and consistent commits. Step by step, moving closer to interview-ready DSA skills. #100DaysOfCode #DSA #Java #ProblemSolving #SlidingWindow #BinaryTree #LearningInPublic
To view or add a comment, sign in
-
-
Switched from Java to Python for DSA practice. First thing that broke my code? The modulo operator. Not because I didn't know how it works — but because it works differently depending on the language, and I had no idea. In Java/C++, % follows the sign of the dividend: -7 % 3 → -1 In Python, % follows the sign of the divisor: -7 % 3 → 2 I was solving a prefix sum problem. Logic was right, approach was right, wrong answers. Took me embarrassingly long to find it. Once I did, I started noticing more: → Division: Java's 7/2 = 3 (integer). Python's 7/2 = 3.5 (decimal). Use // for integer division. → Floor vs truncate: Java truncates toward zero. Python floors toward negative infinity. -7 // 2 → Java: -3 | Python: -4 Same symbols. Different contracts. No errors thrown. Fewer lines of code. More silent assumptions waiting to bite you. #Python #Java #DSA #LearningInPublic #CompetitiveProgramming
To view or add a comment, sign in
-
Just built Linear Regression from scratch in Java! Instead of using libraries, I implemented the core math behind the algorithm to truly understand how it works. This project helped me explore concepts like slope, intercept, and the least squares method in a practical way. 🔹 No external ML libraries 🔹 Pure Java implementation 🔹 Focus on fundamentals This was a great step in strengthening my machine learning basics. 🔗 Check out the project here: [https://lnkd.in/gp7RWNmk] #Java #MachineLearning #LinearRegression #Coding #AI #LearningByDoing
To view or add a comment, sign in
-
-
🚀 **Day 11 of My DSA Journey in Java** Today was all about **Pattern Problems** — one of the best ways to build strong logic and master nested loops 🔥 Here’s what I learned: 🔹 **Pattern Solving Trick** Instead of memorizing patterns, I learned to map them into **rows and columns** and find mathematical relationships. This makes even complex patterns easier to solve. 🔹 **Progression of Patterns** Started from basic and moved to advanced: ▪️ Solid shapes (square, rectangle) ▪️ Triangles and pyramids ▪️ Inverted patterns ▪️ Hollow patterns ▪️ Complex designs like diamond and mirror patterns 🔹 **Beyond Stars ⭐** Explored **numeric and alphabetical patterns**, which require deeper logic and understanding of character arithmetic. 🔹 **Core Learning** Used nested loops with conditions, learned code reusability, and improved problem-solving approach. 💡 **Key Takeaway:** Pattern problems are not about printing shapes — they train your brain to think logically and break complex problems into smaller parts. #Java #DSA #LearningInPublic #Programming #150DaysOfCode #JavaDeveloper
To view or add a comment, sign in
-
🚀 DAY 99/150 — BINARY SEARCH ON ANSWER! 🔥📊 Day 99 of my 150 Days DSA Challenge in Java and today I solved a very important problem that uses Binary Search in a 2D matrix 💻🧠 📌 Problem Solved: Kth Smallest Element in a Sorted Matrix 📌 LeetCode: #378 📌 Difficulty: Medium–Hard 🔹 Problem Insight The task is to find the kth smallest element in an n x n matrix where: • Each row is sorted • Each column is sorted 👉 Instead of flattening and sorting (O(n² log n)), we can do better using Binary Search on Answer. 🔹 Approach Used I used Binary Search on Value Range: • Set: low = smallest element high = largest element • Apply binary search: Find mid Count how many elements are ≤ mid 👉 If count < k → move right (low = mid + 1) 👉 Else → move left (high = mid) ✔️ Continue until low == high → answer found 🔹 Counting Logic (Optimized) • Start from bottom-left corner • If element ≤ mid: All elements above are also ≤ mid Move right • Else: Move up ✔️ This gives O(n) counting per iteration ⏱ Complexity Time Complexity: O(n log (max - min)) Space Complexity: O(1) 🧠 What I Learned • Binary Search is not just for arrays — it can be applied on answer space • Matrix properties can be used for efficient counting • Avoid brute force by leveraging sorted structure 💡 Key Takeaway This problem taught me: How to apply Binary Search on Answer pattern How to optimize 2D problems using structure Thinking beyond direct sorting approaches 🌱 Learning Insight Now I’m improving at: 👉 Recognizing when to use Binary Search beyond arrays 👉 Solving problems with optimized thinking 🚀 ✅ Day 99 completed 🚀 51 days to go 🔗 Java Solution on GitHub: 👉 https://lnkd.in/g-yhc7kH 💡 Don’t search the data — search the answer. #DSAChallenge #Java #LeetCode #BinarySearch #Matrix #Optimization #150DaysOfCode #ProblemSolving #CodingJourney #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
🚀 **Day 6 of My DSA Journey in Java** Today’s focus was on one of the most important building blocks of programming — **Data Types & Type Casting in Java**. 🔹 **What I Learned:** * A **data type** defines what kind of data a variable can store and how much memory it uses. * Explored **primitive data types**: * Numeric → `byte`, `short`, `int`, `long`, `float`, `double` * Non-numeric → `char`, `boolean` * Understood how **characters work with ASCII values**, and how they behave during calculations. 🔹 **Type Casting Concepts:** * **Implicit Casting (Widening):** Automatic conversion from smaller to larger data types (safe). * **Explicit Casting (Narrowing):** Manual conversion from larger to smaller types (can cause data loss). 💻 Practiced these concepts with hands-on coding in IntelliJ IDEA, which helped me clearly understand how Java handles data internally. 📌 **Key Takeaway:** A strong grasp of data types and type casting is essential because it directly impacts memory usage, performance, and accuracy in programs. #Java #DSA #LearningJourney #ProgrammingBasics #100DaysOfCode #CodingLife
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