🔹 Day 39 – LeetCode Practice Problem: Perfect Number (LeetCode #507) 📌 Problem Statement: A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding itself. Return true if the given number is perfect, otherwise return false. ✅ My Approach (Java): Initialize sum = 0. Iterate from 1 to num / 2. For every divisor i such that num % i == 0, add it to sum. After the loop, if sum == num, it’s a perfect number. 📊 Complexity: Time Complexity: O(n/2) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 2108 ms Memory: 41.19 MB 💡 Reflection: This problem reinforced the importance of divisor-based iteration. While this brute-force solution works, optimizing divisor checks using square roots can greatly improve performance — a good next step for refinement! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
Perfect Number Problem Solution in Java
More Relevant Posts
-
🚀 Day 7️⃣7️⃣ of #100DaysOfCode Solved LeetCode Problem #1437 — Check If All 1’s Are at Least K Places Away 🔍✨ 🔧 Concept: Given a binary array, ensure that every 1 is separated by at least K zeros. The solution simply tracks the previous index of 1 and checks the distance. 🧠 Key Idea: Scan the array once When a 1 is found, verify: 👉 currentIndex - previousIndex > k If any pair violates this, return false ⚡ Efficient: Time Complexity: O(n) Space Complexity: O(1) Another clean and efficient logical problem solved. #LeetCode #Java #Arrays #ProblemSolving #DSA #CodingJourney #100DaysOfCode #DeveloperLife #Motivation
To view or add a comment, sign in
-
-
🚀Day 29/100 - Problem of the day :- Minimum Number of Increments on Subarrays to Form a Target Array. 🎯 Goal: Solve the “Minimum Number of Increments on Subarrays to Form a Target Array” problem efficiently on LeetCode. 💡 Core Idea: The key observation is that we only need to add operations when the current element is greater than the previous one. So, the total operations = target[0] + sum(max(target[i] - target[i-1], 0)). This approach ensures we only count necessary increments, avoiding redundant steps. 🎯 Key Takeaway: By focusing on the difference between consecutive elements, we transform a complex problem into a simple linear pass — achieving both clarity and top performance. ✅ Passed all 129 test cases 🚀 Runtime beats 100% of Java submissions 💾 Space Complexity: O(1) — constant extra space used. ⏱ Time Complexity: O(n) — single pass through the array. #Java #DSA #ProblemSolving #Day29 #Leetcode #CodingJourney #100DaysChallenge
To view or add a comment, sign in
-
-
🚀 Day 7️⃣0️⃣ of #100DaysOfCode Solved LeetCode Problem #2169 — Count Operations to Obtain Zero ⚙️💡 Logic: In this problem, we repeatedly subtract the smaller number from the larger one until one of them becomes zero. If num1 >= num2, subtract num2 from num1. Else, subtract num1 from num2. Increment the operation count each time. Continue until either num1 or num2 becomes 0. 💭 Simple yet logical — one of those problems that tests clarity of thought over complexity. #LeetCode #Java #100DaysOfCode #ProblemSolving #CodingJourney #LearnByDoing #DeveloperLife #LogicBuilding #TechCommunity #CodeDaily #KeepCoding
To view or add a comment, sign in
-
-
🗓 Day 6 / 100 – #100DaysOfLeetCode 📘 Problem: 3228. Maximum Number of Operations to Move Ones to the End Difficulty: Medium 💡 Problem Summary: Given a binary string s, you can repeatedly choose an index i where s[i] == '1' and s[i+1] == '0', and move that '1' to the right until it reaches the end of the string or hits another '1'. The goal is to find the maximum number of such operations possible. 🧠 My Approach: Instead of simulating the moves (which would be inefficient), I used a counting strategy: Keep a running count of the number of '1's seen so far (cnt). Whenever a '0' appears after one or more '1's, we can perform cnt operations involving those ones. Sum these up for the final result. 📊 Complexity Analysis: Time Complexity: O(n) Space Complexity: O(1) #LeetCode #Java #ProblemSolving #CodingChallenge #100DaysOfCode #DSA #LearningEveryday
To view or add a comment, sign in
-
-
NeetCode 35 | LeetCode #143 | Reorder Linked List This one’s all about mastering pointer manipulation! Steps I followed: 1️⃣ Find the middle using slow & fast pointers 2️⃣ Reverse the second half 3️⃣ Merge both halves alternately Such problems really sharpen understanding of linked list structure and in-place rearrangement. #NeetCode #LeetCode #Java #DSA #LinkedList #Algorithms #CodingJourney #ProblemSolving
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 68 of My LeetCode Journey 🚀 🔹 Problem: Delete Node in a Linked List (LeetCode 237) 🔹 Difficulty: Easy 🧩 What I Learned: This is one of those problems where you can’t access the head of the list — you’re only given the node that needs to be deleted. That means… you can’t actually “delete” it directly. So, the trick is to copy the data from the next node into the current one and skip over the next node. 💡 Key Idea: Instead of removing the given node, we overwrite its value and adjust the pointer — effectively removing the next node. ✅ Takeaway: Sometimes, solving a problem isn’t about following the usual rules — it’s about thinking creatively within constraints. 💭 #Day68 #LeetCode #CodingJourney #Java #LinkedList #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
🔹 Day 38 – LeetCode Practice Problem: Missing Number (LeetCode #268) 📌 Problem Statement: You are given an array nums containing n distinct numbers taken from the range [0, n]. Find the one number that is missing from the array. ✅ My Approach (Java): Calculated the expected sum using the formula total = \frac{n \times (n + 1)}{2} The missing number = total - actual sum. This method avoids sorting or extra space, keeping it optimal. 📊 Complexity: Time Complexity: O(n) Space Complexity: O(1) ⚡ Submission Results: Accepted ✅ Runtime: 0 ms (Beats 100%) 🚀 Memory: 45.51 MB (Beats 32.44%) 💡 Reflection: A great reminder that sometimes the most efficient solutions come from simple mathematical reasoning. Clean, elegant, and lightning-fast! #LeetCode #ProblemSolving #Java #DSA #CodingPractice #Learning
To view or add a comment, sign in
-
-
NeetCode 14 | LeetCode #11 | Container With Most Water Solved using the two-pointer approach — expanding and shrinking boundaries to find the maximum area efficiently in O(n) time. A great example of how logical movement can outperform brute force. #NeetCode #LeetCode #Java #DSA #Algorithms #TwoPointers #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
💻 Enhancing Problem-Solving Skills with LeetCode (Java) Recently solved a couple of fundamental algorithmic problems that helped strengthen my understanding of two-pointer techniques, array manipulation, and writing efficient solutions. 🔹 Container With Most Water Implemented an optimised two-pointer approach to find the maximum water area between vertical lines. Instead of checking every pair (which would be O(n²)), the solution smartly moves the pointer at the shorter height inward to explore potentially larger areas. Approach: Two Pointers, Greedy Time Complexity: O(n) Space Complexity: O(1) 🔹 3Sum Solved the classic triplet-finding challenge by sorting the array and using two pointers to efficiently search for combinations that sum to zero. Also handled duplicates to avoid repeated triplets. Approach: Sorting + Two Pointers Time Complexity: O(n²) Space Complexity: O(1) (excluding output list) These problems helped sharpen my understanding of pointer movement, edge-case management, and designing clean, efficient solutions. #LeetCode #Java #Algorithms #DSA #Coding #ProblemSolving #SoftwareEngineering #LearningJourney
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