🚀 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
Solving Sum of Square Numbers with Two Pointers in Java
More Relevant Posts
-
🔹 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
To view or add a comment, sign in
-
-
🚀 Day 8 of #45DaysOfLeetCode Challenge 😎 📌Today's problem: Palindrome Number (LeetCode #9) 💡 🔹 Concept: Check whether a given integer reads the same backward and forward — without converting it to a string! 🔹 Logic Used: Instead of reversing the entire number, I reversed only half of it to improve efficiency. This avoids unnecessary computation and eliminates integer overflow risks. 🔹 Key Learnings: ✅ Optimized logic using mathematical manipulation ✅ Improved understanding of number reversal techniques ✅ Importance of edge case handling (negative numbers, trailing zeros) ⚙️ Result: 💻 Runtime: 4 ms (Beats 100%) 💾 Memory: 44.84 MB 😎Small optimizations make a big difference in performance! 💪 📌Problem: https://lnkd.in/ef6AC2j6 🔥Each day is a step closer to writing cleaner and more optimized code. ✨ Let’s keep pushing forward and refining our problem-solving skills! 💻🔥 #LeetCode #Day8 #100DaysOfCode #ProblemSolving #Java #CodingChallenge #PalindromeNumber #DataStructures #Algorithms #LearningEveryday
To view or add a comment, sign in
-
-
💡 Day 19 of My LeetCode Journey — 3Sum Closest Today’s problem was “3Sum Closest”, a slight twist on the classic 3Sum challenge. 🧩 Problem Statement: Given an integer array nums and a target value, find three integers whose sum is closest to the target. Return the sum of those three numbers. Example: Input: nums = [-1, 2, 1, -4], target = 1 Output: 2 Explanation: (-1 + 2 + 1 = 2) ⚙️ Approach: Sort the array for easy pointer movement. Use a for loop to fix one element at a time. Apply the two-pointer technique to find the closest sum. Compare differences using Math.abs() to track which combination is nearer to the target. 📘 Key Learning: 🔹 Sorting simplifies pointer logic. 🔹 Math.abs() is crucial for measuring closeness. 🔹 Sometimes, you don’t need the exact answer — just the closest one. #30DaysOfCode #LeetCode #Java #CodingJourney #ProblemSolving #DataStructures #Algorithms #TwoPointers #TechLearning
To view or add a comment, sign in
-
-
🌳 Day 62 of 100 Days of LeetCode 🌳 Today’s challenge: LeetCode 226 – Invert Binary Tree 🔄 🧩 Problem Summary: Given the root of a binary tree, invert it — meaning swap the left and right children of every node. Essentially, you’re mirroring the entire tree! 🌲✨ 💡 Key Takeaways: 🔹 Strengthened understanding of tree traversal using recursion. 🔹 Learned how a simple DFS (Depth-First Search) can elegantly solve structural transformations. 🔹 Practiced reasoning about symmetry and recursion base cases. 🧠 Approach: 1️⃣ If the tree is empty, return null. 2️⃣ Recursively invert the left and right subtrees. 3️⃣ Swap the left and right children of the current node. 4️⃣ Return the root once the tree is fully inverted. 🚀 A great example of how recursion simplifies complex problems into smaller, intuitive steps! #LeetCode #100DaysOfCode #Java #DSA #BinaryTree #CodingJourney #Recursion #ProblemSolving
To view or add a comment, sign in
-
-
💥 Stop solving 500 random Leetcode questions! If you can master these 7 patterns, you can crack any DSA problem. Most developers don’t need more problems they need clarity on the patterns behind them. 🚀 Here’s what I wish I knew earlier: If you understand 1. Sliding Window 2. Two Pointers 3. Binary Search 4. Recursion 5. Dynamic Programming 6. Greedy 7. Backtracking ...then every new problem will start to look familiar. 💡 Save this post 🔖 and start with one pattern a week. Your consistency will matter more than your question count. 👇 Comment which pattern took you the longest to understand! #DSA #Java #BackendDevelopment #Leetcode #ProgrammersLife
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
-
-
NeetCode 29 | LeetCode #153 | Find Minimum in Rotated Sorted Array Used binary search to find the rotation pivot. Compared nums[mid] with nums[right] to shrink search space efficiently. Time complexity: O(log n) | Space: O(1) #LeetCode #NeetCode #Java #Algorithms #DataStructures #Optimization #Coding
To view or add a comment, sign in
-
🚀 Day 63 of My LeetCode journey 🚀 Problem : Custom Sort String Today’s problem was interesting because instead of sorting using normal alphabetical order, we sort the given string based on a custom priority order. 🧠 Problem Understanding Given: order → defines priority of characters. str → the input string which needs to be rearranged. Goal: ✅ Arrange characters of str based on the sequence defined in order. ✅ Characters not present in order should appear at the end (any order). 💡 Approach (Simple & Efficient) Count frequency of each character in str. First append characters following the order. Then append remaining characters. Time Complexity: O(n) Space Complexity: O(1) (fixed array size for 26 letters) ✨ Learnings Sometimes the problem isn't about sorting, but about following a custom priority. Frequency counting is extremely powerful for character-based problems. StringBuilder → best way to build strings efficiently in Java. #leetcode #coding #dsa #java #100DaysOfCode #day63 #learningEveryday #problemSolving
To view or add a comment, sign in
-
-
🚀 Day 40 of My #LeetCode Challenge 🚀 📘 Problem: Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold (LeetCode #1343) 💡 Approach: Implemented the Sliding Window technique to efficiently calculate the sum of each subarray of size k. First, compute the sum of the initial k elements. Then, slide the window forward — subtract the element leaving and add the new one entering. Check if the average of the current window meets or exceeds the given threshold. This method optimizes the time complexity to O(n) by avoiding repetitive summation. ⏱️ Concepts Used: Sliding Window | Arrays | Optimization | Time Complexity 🔥 Consistency and logic go hand in hand — every day adds a new layer to my problem-solving skills! #Day40 #LeetCode #100DaysOfCode #CodingChallenge #Java #DSA #ProblemSolving #CodingJourney #TechLearning #CodeEveryday #SoftwareEngineering #ProgrammerLife #CodingCommunity #Developer #JavaProgramming #LearnToCode #TechGoals #CodeNewbie #Algorithm #DataStructures #CodingPractice
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