🚀Day 97/100 #100DaysOfLeetCode 👩💻Problem: Valid Square✅ 💻Language: Java 💡Approach: To check if four given points form a valid square, I calculated all six pairwise distances between the points. 🔹A valid square must have two distinct distances — 4 equal smaller sides and 2 equal longer diagonals. 🔹Used a HashMap to count occurrences of each distance. 🔹If the map has exactly two distinct non-zero distances and the smaller one appears 4 times while the larger appears 2 times, it’s a square! 🧠Key Takeaways: 🔹Strengthened understanding of geometry-based problems. 🔹Reinforced hashing techniques for quick frequency checks. 🔹Improved logic for pairwise comparison and distance calculation. ⚙️Performance: ⏱️Runtime: 2 ms (Beats 27.27%) 💾Memory: 41.91 MB (Beats 22.03%) #100DaysOfLeetCode #Java #CodingChallenge #LeetCode #ProblemSolving #CodingChallenge
"Valid Square Problem Solved in Java with HashMap"
More Relevant Posts
-
Week 8 || Day 2💡 Reversing words in Java — step by step! Today I practiced reversing each word in a sentence using two different approaches: 🔹 Approach 1 — With .reverse() method: Split the sentence using split(" ") to separate words. Used StringBuffer for each word and applied .reverse() directly. Joined the reversed words back with spaces. 🔹 Approach 2 — Without using .reverse(): Again split the string into words. For each word, used a for loop running from the last character to the first. Appended each character manually into a new StringBuffer. Combined the reversed words carefully, avoiding extra spaces.⚡ #Java #StringBuffer #ProgrammingLogic #JavaFullStack
To view or add a comment, sign in
-
Another late-night success Solved a tricky binary search + sliding window problem efficiently in Java, optimizing power distribution logic in minimal runtime. 📊 Runtime: 31 ms 💡 Beats 89.29% of Java submissions 🧩 Concepts used: Binary Search, Prefix Sum, Sliding Window Each accepted solution reminds me that writing clean, efficient code isn’t just about passing tests — it’s about thinking like the system itself. #Java #LeetCode #ProblemSolving #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 95/100 #100DaysOfLeetCode 🔍Problem: Length of Last Word✅ 💻Language: Java 🧠Approach: 1️⃣ First, trim the string to remove trailing and leading spaces. 2️⃣ Initialize a counter to 0. 3️⃣ Traverse the string from the end. 4️⃣ Count characters until the first space is encountered. 5️⃣ Return the count as the length of the last word. 💡Key Takeaways: 🔹Trimming the input ensures no trailing spaces interfere. 🔹Backward traversal avoids splitting the entire string. 🔹Simple yet efficient one-pass solution. ⚡Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 41.58 MB (Beats 91.52%) #100DaysOfLeetCode #Java #CodingJourney #ProblemSolving #LeetCode #CodingChallenge
To view or add a comment, sign in
-
-
💻 Day 45 of #LeetCode Journey 🚀 ✅ Problem: Count and Say 📘 Language: Java 🔹 Status: Accepted (30/30 test cases passed) 🔹 Runtime: 4 ms | Beats 55.38% 🔹 Memory: 41.86 MB 🧠 Concept: This problem is about generating the n-th term in the “count and say” sequence. Each term is built by describing the previous term — count the number of digits and say them in order. 🧩 Approach: Start with "1". For each iteration, use a StringBuilder to construct the next sequence. Track consecutive digits using a counter. Append the count and digit when the sequence changes. 💡 Efficient string manipulation and iteration give optimal performance. 🔥 Every solved problem builds confidence. One step closer to mastering patterns in strings! #Day45 #LeetCode #Java #CodingChallenge #ProblemSolving #CountAndSay #50DaysOfCode
To view or add a comment, sign in
-
-
Day 46 of #100DaysOfLeetCode Challenge 🚀Today’s Problem: Remove Duplicate Letters (LeetCode - Medium) Language: Java In this problem, the goal is to remove duplicate letters from a string such that every letter appears once and the result is the smallest lexicographical order possible. Concepts Covered: Stack for maintaining order Greedy approach for smallest lexicographical sequence Tracking last occurrence index of each character Boolean array to keep track of visited characters Key Takeaways: Understanding when to remove elements from the stack is crucial for optimal ordering. The combination of stack + greedy ensures both uniqueness and lexicographical minimality. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingChallenge #DSA #DevelopersJourney
To view or add a comment, sign in
-
-
Hey everyone! Today, I explored one more important concept in Exception Handling in Java — called Rethrowing an Exception. In this concept, we use keywords like try, catch, throw, throws, and finally together to handle errors more effectively. It helps us catch an exception in one method and pass it to another for better control and clean code structure. Every day, I’m learning new features in Java to write more efficient and error-free programs that improve performance and user experience. #Java #ExceptionHandling #RethrowException #CodingJourney #Learning
To view or add a comment, sign in
-
-
🚀 Day 26 of 100 Days of LeetCode 📘 Problem: Search a 2D Matrix 💻 Language: Java ✅ Status: Accepted — Runtime: ⚡ 0 ms (Beats 100%) Today’s problem focused on searching efficiently within a 2D matrix — a great exercise for understanding nested loops, traversal logic, and time optimization. While this version used a simple brute-force approach, it served as a good refresher on matrix iteration patterns before moving on to more optimized binary search techniques in 2D grids. ✨ Key Learnings: Matrix traversal can be intuitive when visualized 🔢 Always consider both brute-force and optimized approaches — understanding both is key to depth of knowledge Writing clean, readable code matters as much as optimizing it Each problem solved is another small brick in the foundation of strong problem-solving skills 💪 #Day26 #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingJourney #SoftwareDevelopment #Matrix #KeepLearning #CodeEveryday
To view or add a comment, sign in
-
-
Day 9 of Java 50 Days of Code Challenge Imagine you’re checking your contact list — name and number — and you want to print them neatly, one by one. That’s exactly what I learned today: how to loop through a Map in Java. Maps store key–value pairs, and there are different ways to read them. Today I practiced using for-each loops to go through keys, values, and entries. Lesson of the Day: > Looping through a Map feels like flipping through your phonebook — one contact at a time. Next, I’ll explore ArrayLists with user input — to make my programs more dynamic and interactive. #Java #50DaysOfCode #Day9 #LearningJourney #CodingStory #MapIteration #JavaCollections Here’s my little example: Guess the output
To view or add a comment, sign in
-
-
🚀 Stream API Coding – 1: Check if a String is Palindrome Exploring the power of Java 8 Stream API with a simple yet elegant example — checking whether a string is a palindrome using functional style. 💡 String s = "racecar"; boolean isPalindrome = IntStream.range(0, s.length() / 2) .allMatch(i -> s.charAt(i) == s.charAt(s.length() - i - 1)); System.out.println(isPalindrome ? "String is Palindrome" : "String is not palindrome"); ✨ Key Learnings: ✅ Use IntStream.range() for index-based iteration ✅ allMatch() ensures all comparisons pass ✅ Clean and concise approach — no loops, no extra variables 📚 Output: 👉 String is Palindrome This is just the beginning — more Stream API challenges coming soon! 🔥 #Java #StreamAPI #CodingChallenge #JavaDeveloper #FunctionalProgramming #CleanCode #CodingSeries #InterviewPreparation
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