💡 Day 57 of #100DaysOfCode 💡 Today, I solved LeetCode Problem #217 – Contains Duplicate 🧩 Given an integer array, the task is simple yet fundamental: 👉 Determine whether any value appears at least twice in the array. 💻 Language: Java ⚡ Runtime: 13 ms — Beats 87.70% 🚀 📉 Memory: 58.28 MB — Beats 63.02% 🧠 Key Learnings: Reinforced my understanding of HashSet and its O(1) lookup time. Learned how sets help efficiently identify duplicates in large datasets. Strengthened array traversal and data structure optimization skills. 🧩 Approach: 1️⃣ Initialize an empty HashSet. 2️⃣ Iterate through each element in the array. 3️⃣ If an element already exists in the set → return true. 4️⃣ Else, add it to the set. 5️⃣ If loop completes, return false. ✅ Complexity: Time: O(n) Space: O(n) ✨ Takeaway: Even basic problems like these teach the power of hash-based structures — simple yet powerful for building optimized systems and preventing redundant computations. #100DaysOfCode #LeetCode #Java #DataStructures #HashSet #ProblemSolving #CodingChallenge #CleanCode #Programming #SoftwareEngineering #TechLearning #Algorithms
Solved LeetCode Problem #217 with Java and HashSet
More Relevant Posts
-
🌟 Day 44 – LeetCode Practice Problem: Product of Array Except Self (LeetCode #238) 📌 Concept: Given an integer array, create a new array where each element equals the product of all other elements except itself, without using division. 🧠 My Approach: First pass → compute prefix products (multiply everything before current index) Second pass → compute suffix products (multiply everything after current index) Combine both to get the result for each index efficiently No extra multiplication array used — optimized and clean logic ⚡ This avoids division and runs in linear time — exactly what the problem demands ✅ 📈 Result: ✅ Accepted ⚡ Runtime: 2 ms (Beats ~87%) 📦 Memory: Efficient usage 💡 Key Learning: This problem reinforces the power of prefix & suffix computation — a common trick in array manipulation + interview favorite. Great way to improve problem-solving without relying on brute force or division. --- 🚀 Growing stronger every day in DSA! #LeetCode #DSA #Java #ProblemSolving #PrefixSuffix #CodingJourney #ArrayProblems #LearningMindset
To view or add a comment, sign in
-
-
🔥 Day 83 of #100DaysDSAChallenge 📌 Topic: String — Most Common Word ✅ Problem Solved on #LeetCode: 819. Most Common Word (🟢 Easy) 💡 Key Learnings: • Practiced text normalization by removing punctuation and handling case sensitivity. • Strengthened understanding of frequency counting using HashMap and HashSet. • Improved efficiency by eliminating nested loops and using optimized data structures. • Enhanced clarity in writing clean, readable, and optimized Java code. 🚀 Consistency Builds Clarity: Each problem enhances your logical thinking and improves your code precision. Keep learning and growing — one problem at a time 💪 🏷️ #Day83 #100DaysChallenge #100DaysDSAChallenge #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #Strings #Programming #LearningJourney #10kCoders #10000Coders #Consistency #LogicBuilding
To view or add a comment, sign in
-
-
#Day5 of #100DaysOfCode Challenge! 🔥 Today’s focus is on strengthening array fundamentals through two challenging problems: Missing Number and First Repeating Element. Problem 1: LeetCode 268 – Missing Number Objective: Identify the missing number in an array containing n distinct numbers ranging from 0 to n. Approach: Utilized the sum formula, n*(n+1)/2, to calculate the expected sum. By subtracting the actual sum of the array elements, the missing number was readily identified. Time Complexity: O(n) | Space Complexity: O(1) This solution is concise, elegant, and exemplifies a clean approach to solving interview problems. Problem 2: First Repeating Element (GFG) Objective: Determine the first repeating element with the smallest index (1-based). Approach: Traversed the array from right to left, utilizing a HashSet to store elements. Whenever a number was encountered that was already present in the HashSet, the index was updated to ensure the smallest possible value. Time Complexity: O(n) | Space Complexity: O(n) Key Takeaway: Recognizing when a mathematical shortcut, such as the sum formula, is applicable versus when a data structure, like a HashSet, is necessary, cultivates strong problem-solving intuition. Balancing simplicity and optimization is crucial for achieving significant growth in problem-solving skills. Thank you Rajesh Gupta for your assistance in guiding me through this process. #100DaysOfCode #LeetCode #DSA #ProblemSolving #Arrays #CodingChallenge #LearningInPublic #Java #Programming
To view or add a comment, sign in
-
-
✅Day 62 of #100DaysOfLeetCode 📌Problem: You are given a sorted array consisting of only integers where every element appears exactly twice, except for one element which appears exactly once. 🟠 Difficulty: Medium 📍Topic: Array, Binary Search 🎯 Goal: Return the single element that appears only once in O(log n) time and O(1) space. 🧠key idea: Approach 1: The problem can be efficiently solved using a modified binary search. The core logic relies on the properties of the sorted array. If we are at an even index, its duplicate pair should be at the next (odd) index. If we are at an odd index, its pair should be at the previous (even) index. By examining the middle element and its neighbor, we can determine if the single, non-duplicated element lies in the left or right half of the array, allowing us to discard one half in each step and achieve a logarithmic time complexity. #100DaysOfCode #LeetCode #CodingChallenge #Java #DataStructures #Algorithms #BinarySearch #ProblemSolving #SoftwareDeveloper #TechJobs #DeveloperLife #CodeNewbie #Programming #LearnToCode #JobSeekers
To view or add a comment, sign in
-
-
📅 Day 81 of #100DaysOfLeetCode Problem: Insert into a Binary Search Tree (LeetCode #701) Approach: The task is to insert a new node with a given value into a Binary Search Tree (BST). Start from the root and recursively find the correct position: If the new value is smaller than the current node’s value, go to the left subtree. Otherwise, go to the right subtree. When a null spot is found, insert a new node there. The BST property is preserved throughout this process. Complexity: ⏱️ Time: O(h) — where h is the height of the tree. 💾 Space: O(h) — recursive call stack. 🔗 Problem Link: https://lnkd.in/dCS7zxVG 🔗 Solution Link: https://lnkd.in/dxB4ZNtV #LeetCode #100DaysOfCode #BinarySearchTree #Recursion #Java #TreeTraversal #DSA #Algorithms #CodingChallenge #ProblemSolving #CodeNewbie #StudyWithMe #BuildInPublic #LearnToCode #DailyCoding
To view or add a comment, sign in
-
-
🔥 Day 84 of #100DaysDSAChallenge 📌 Topic: Array — Squares of a Sorted Array ✅ Problem Solved on #LeetCode: 977. Squares of a Sorted Array (🟢 Easy) 💡 Key Learnings: • Strengthened understanding of the two-pointer technique for sorted array manipulation. • Learned to efficiently handle both negative and positive numbers when squaring values. • Optimized time complexity from O(n²) to O(n) by eliminating nested loops. • Enhanced focus on writing clean, readable, and efficient Java code. 🚀 Consistency Builds Clarity: Every problem you solve sharpens your logical thinking and builds confidence. Keep learning, improving, and moving forward — one problem at a time 💪 🏷️ #Day84 #100DaysChallenge #100DaysDSAChallenge #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #Arrays #Programming #LearningJourney #10kCoders #10000Coders #Consistency #LogicBuilding
To view or add a comment, sign in
-
-
🔢 Day 47 of #LeetCode100DaysChallenge Solved LeetCode 79: Word Search — a classic backtracking problem that beautifully blends recursion and grid traversal. 🧩 Problem: Given a 2D grid of characters and a word, determine if the word can be formed using sequentially adjacent cells (up, down, left, right), where each cell can be used only once. 💡 Approach Used — Backtracking (DFS): 1️⃣ Start from each cell that matches the first character. 2️⃣ Explore in all four directions recursively. 3️⃣ Temporarily mark visited cells to avoid reuse. 4️⃣ If the entire word is matched, return true; otherwise, backtrack. ⚙️ Complexity: Time: O(N × 4ᴸ) — where N is the total number of cells, and L is the word length. Space: O(L) — recursion depth. ✨ Key Takeaways: ✅ Strengthened understanding of recursion and backtracking. ✅ Learned to manage visited states effectively in grid problems. ✅ Great exercise in applying DFS to real-world matrix traversal cases. #LeetCode #100DaysOfCode #Java #Backtracking #Recursion #ProblemSolving #DSA #WomenInTech #CodingJourney
To view or add a comment, sign in
-
-
🚀 Problem 2: Reverse Integer 💡 Leetcode Problem No: 7 Today, I solved an interesting Leetcode-style problem that involves reversing an integer — while handling tricky cases like integer overflow 🔄 ✨ Challenge: Given an integer x, reverse its digits and return the reversed number. If reversing x causes the value to go outside the signed 32-bit integer range, return 0. 💻 Key Learnings: 🔹 Used Math.abs(x) to handle negatives elegantly 🔹 Applied overflow check using: if (rev > (Integer.MAX_VALUE - d) / 10) 🔹 Mastered modulus (%) and division (/) logic for digit extraction 🔹 Ensured both positive and negative numbers are correctly reversed 💙 Tip: Always consider edge cases and overflow conditions when working with integer manipulation problems. #Java #Coding #LeetCode #ProblemSolving #JavaDeveloper #ProgrammingChallenge #LeetcodeCoding
To view or add a comment, sign in
-
-
✨ Day 103 of My DSA Challenge – Permutations 🔷 Problem : 46. Permutations 🔷 Goal : Generate all possible orderings (permutations) of a given array of distinct integers. Example → Input: [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 🔷 Key Insight : This problem is a classic recursion and backtracking pattern — exploring all possible arrangements by making choices and undoing them. Here’s how I approached it : 1️⃣ Recursion (Depth-First Search): Build each permutation step by step. 2️⃣ Visited Array: Track which elements have been used so far. 3️⃣ Backtracking: After exploring a path, undo the choice (remove the last element and mark it unvisited). Every recursive call expands the decision tree until all positions are filled, ensuring every unique ordering is generated. 🔷 My Java Approach : Recursive helper() function generates all permutations. Base case → when current list size equals array length. Used a boolean[] vis to manage state efficiently 🔷 Complexity : Time → O(n × n!) (since there are n! permutations and copying each list takes O(n)) Space → O(n) (for recursion and visited tracking) This problem beautifully tests recursion fundamentals, state management, and the art of backtracking — essential tools for mastering combinatorial problems. Each problem reminds me that problem-solving is less about memorizing patterns and more about learning how to think. #Day103 #100DaysOfCode #LeetCode #DSA #Java #ProblemSolving #Recursion #Backtracking #CodingChallenge #Programming #SoftwareEngineering #Algorithms #DataStructures #TechJourney #CodeEveryday #EngineerMindset #DeveloperJourney #GrowthMindset #KeepLearning #ApnaCollege #AlphaBatch #ShraddhaKhapra
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
-
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