🚀Day 9 of #120DaysOfCode 📌 Problem: Largest Number At Least Twice of Others(747) 📌 Language: Java 🔍Approach 1. Traverse the array once to find the largest (max1) and second largest (max2) elements. 2. While updating the largest element, also store it's index. 3. After traversal, check if max >= 2 * max2 4. If true, return the stored index; otherwise, return -1. ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day9 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #DSA
Java Solution for Largest Number at Least Twice of Others
More Relevant Posts
-
🚀Day 13 of #120DaysOfCode 📌 Problem: Reverse String(344) 📌 Language: Java 🔍Approach(Two Pointer Technique) 1. Use two pointer . left --> start of the array index . right --> end of the array 2. While left < right: . Swaps[left] and s[right] . Move left forward (left++) . Move right backward (right--) 3. Stop when pointers meet or cross ⏱️ Time and Space Complexity Time Complexity: O(n) Space complexity: O(1) 🔥One problem closer to mastery #120DaysOfCode #Day13 #Java #Array #Leetcode #ProblemSolving #Consistency #LearningEveryday #LearningPublic #Akshay #DSA
To view or add a comment, sign in
-
-
Day 12 of #100DaysOfLeetCode 💻✅ Solved #326. Power of Three problem in Java. Approach: • Checked if the number is less than or equal to zero (not a power of three) • Continuously divided the number by 3 while it was divisible • Verified whether the final value becomes 1 • Avoided recursion and used iteration for better efficiency Performance: ✓ Runtime: 8 ms (Beats 86.60% submissions) ✓ Memory: 46.35 MB Key Learning: ✓ Strengthened understanding of number divisibility logic ✓ Learned efficient validation of power-based numbers ✓ Improved problem-solving using iterative reduction Learning one problem every day 🚀 #Java #LeetCode #DSA #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 6 of My 90 Days Java Full Stack Challenge Today, I focused on understanding the theory of String in Java and solved a few basic String problems to build a strong foundation. 📘 What I learned today: What is String in Java Why String is immutable String Constant Pool (SCP) == vs equals() Difference between String, StringBuilder, and StringBuffer How String works internally (memory & performance basics) 🧩 Practice (Basic Level): ✔ Reverse a String ✔ Check Palindrome ✔ Count vowels & consonants ✔ Remove whitespaces 💡 Key takeaway: Before jumping into advanced DSA problems, clarity of concepts matters more than speed. 📅 Plan for tomorrow: 👉 Solve more String DSA problems (intermediate level) and go deeper with hands-on practice. Learning step by step, one day at a time 💪 #Java #StringInJava #90DaysJavaFullStack #DSA #LearningInPublic #Consistency #DeveloperJourney
To view or add a comment, sign in
-
DSA journey 🚀 📌 LeetCode #167 – Two Sum II (Input Array Is Sorted) 💻 Language: Java 🔹 Approach (Two Pointer Technique): Initialize two pointers at the start and end of the sorted array Calculate the sum of both pointers If the sum equals the target → return 1-based indices If the sum is smaller than the target → move the start pointer forward If the sum is greater than the target → move the end pointer backward Efficient use of the sorted property 💡 ⏱ Time Complexity: O(n) 🧩 Space Complexity: O(1) Step-by-step clarity before optimization ✨ Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
Day 6/30 – LeetCode #242 (Valid Anagram) | Java My initial thought was to sort both strings and compare them, but that adds unnecessary overhead. The more efficient approach was to use a frequency count, since only character occurrences matter here. By using an int[26] array and incrementing/decrementing counts while iterating through both strings, I was able to solve this in O(n) time with O(1) space. This problem reinforced how fixed-size arrays in Java can outperform maps when the character set is known. #LeetCode #Java #DSA #Strings #Hashing #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
Day 5/30 – LeetCode #283 (Move Zeroes) | Java The naive approach involved shifting elements multiple times, which makes the logic messy and inefficient. The challenge was finding a way to move all zeroes without disturbing the order of non-zero elements. Using a two-pointer approach, I tracked the position for the next non-zero element and rebuilt the array in-place. This achieved O(n) time complexity with O(1) extra space while preserving the original order. This problem highlighted how pointer-based logic in Java can simplify array manipulation and improve performance. #LeetCode #Java #DSA #TwoPointers #Arrays #Consistency #LearningInPublic
To view or add a comment, sign in
-
-
#Day-132) Solved LeetCode Problem #136 – Single Number ✅ Implemented an efficient Java solution to find the unique element in an array where every other number appears twice. 🔹 Used HashSet to track duplicates 🔹 Time Complexity: O(n) 🔹 Space Complexity: O(n) 🔹 Strengthened understanding of Sets & iteration in Java Consistent practice to improve problem-solving and DSA fundamentals 🚀 #LeetCode #Java #DSA #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
Day 8 of #100DaysOfLeetCode 💻✅ Solved Number of 1 Bits (Hamming Weight) in Java. Approach: Used bitwise AND (n & 1) to check if the last bit is set Counted set bits while traversing through all bits Used unsigned right shift (>>>) to safely handle positive and large integers Continued until the number becomes zero Key Learning: ✓ Strengthened understanding of bit manipulation ✓ Learned how unsigned shift helps avoid sign-related issues Learning and improving one problem every single day 🚀 #Java #LeetCode #BitManipulation #ProblemSolving #CodingJourney #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 DSA Series – Episode 6 📌 Linear Queue in Java (Using Array) Today we implemented a Linear Queue in Java using a normal array. ✔️ enqueue() → insert at rear ✔️ dequeue() → delete from front ✔️ Handled overflow & underflow No built-in classes — just core logic 💻 Understanding implementation makes DSA stronger. Next: Circular Queue 🔄 #DSA #Java #Queue #CodingJourney
To view or add a comment, sign in
-
DSA journey 🚀 📌 LeetCode #231 – Power of Two 💻 Language: Java 🔹 Approach: - Handle base cases (n < 1 and n == 1) - Keep dividing the number by 2 while it is even - If the final value becomes 1, it is a power of two ⏱ Time Complexity: O(log n) 🧩 Space Complexity: O(1) Consistency over perfection 💯 #DSA #Java #LeetCode #ProblemSolving #LearningInPublic
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