🚀 Day 89 - #100DaysOfCode Today I solved a problem on finding the smallest common element between two sorted arrays. 🧩 Problem Given two integer arrays, return the first common element between them. If no common element exists, return -1. 💡 Approach I used a HashSet to efficiently check for common elements. Steps: 1️⃣ Insert all elements of the first array into a HashSet. 2️⃣ Traverse the second array. 3️⃣ Check if the current element exists in the set. 4️⃣ If found, return that element immediately. 5️⃣ If no common element is found, return -1. ⏱ Time & Space Complexity Time Complexity: O(n + m) Space Complexity: O(n) 📌 Key Learning: Using a HashSet helps reduce lookup time to O(1), making the solution efficient #DSA #Java #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode
Finding Smallest Common Element in Two Sorted Arrays with HashSet
More Relevant Posts
-
🧠 Problem Statement: Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays after combining them. ⚙️ Approach: ✔️ Combine both arrays into a single array ✔️ Sort the merged array ✔️ If the length is odd → return the middle element ✔️ If the length is even → return the average of the two middle elements ⏱ Time Complexity: O((m+n) log(m+n)) 📦 Space Complexity: O(m+n) 📌 Learning: This problem helped me understand array merging and median calculation concepts. 🔥 Consistency in solving problems daily helps improve problem-solving skills and algorithmic thinking. #Day9 #DSA #LeetCode #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 27 Today’s focus: Binary Search on modified arrays. Problem solved: • Search in Rotated Sorted Array (LeetCode 33) Concepts used: • Binary Search • Identifying sorted halves • Conditional search space reduction Key takeaway: This problem extends binary search to a rotated sorted array, where the array is not fully sorted but divided into two sorted parts. At each step, we: • Find the mid element • Check which half (left or right) is sorted • Decide whether the target lies in the sorted half • Eliminate the other half This allows us to still achieve O(log n) time complexity. Continuing to strengthen fundamentals and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 Solved an interesting problem today: “Minimum Stickers to Spell Word” At first, I tried a greedy approach… failed ❌ Then I realized this is actually a DP + memoization problem. 💡 Key Insight: Instead of trying all combinations blindly, we reduce the target string step by step. 🧠 Approach: - Convert each sticker into frequency map - Recursively try reducing target - Use memoization to avoid recomputation ⏱️ Time Complexity: Optimized significantly with caching 🔥 This problem improved my thinking about state reduction. #DSA #CodingInterview #Java #LeetCode
To view or add a comment, sign in
-
-
🚀 Day 34/100 Today I solved Search in Rotated Sorted Array II — a tricky variation of binary search with duplicates! 🔍 Problem Insight: Array is sorted but rotated Duplicates make it harder to decide which half is sorted. 🧠 Key Learning: When nums[low] == nums[mid] == nums[high], we shrink the search space Otherwise, identify the sorted half and decide where target lies. ⚡ Approach Used: Modified Binary Search Carefully handled edge cases with duplicates. 💡 Time Complexity: Best/Average: O(log n) Worst (due to duplicates): O(n). 💻 What I Learned: Duplicates can break normal binary search logic. Always handle ambiguous cases by reducing search space Patience is key in edge-case-heavy problems 😄. #DSA #BinarySearch #LeetCode #Java #CodingJourney #ProblemSolving #100Daysofcode #day34
To view or add a comment, sign in
-
-
Today I solved LeetCode 101 – Symmetric Tree. 🧩 Problem Summary: Given the root of a binary tree, check whether it is symmetric (mirror of itself). A tree is symmetric if the left subtree is a mirror reflection of the right subtree. 💡 Key Concepts Used: Binary Trees Recursion Depth First Search (DFS) Tree comparison 🧠 Approach: Define a helper function to compare two nodes. Check if: Both nodes are null → symmetric One is null → not symmetric Values are equal → continue checking Recursively compare: Left subtree of left node with right subtree of right node Right subtree of left node with left subtree of right node If all checks pass, the tree is symmetric. This ensures a mirror comparison of the tree structure. 📚 What I Learned: How to compare two trees using recursion. Understanding mirror symmetry in binary trees. Strengthening DFS and recursive thinking. Breaking problems into smaller subproblems. Improving problem-solving skills one step at a time 🌳 Consistency is the key to growth 🚀 #LeetCode #DSA #BinaryTree #SymmetricTree #DFS #Recursion #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
-
Day 15 – Maximum Depth of Binary Tree 🚀 Continuing my DSA journey with Striver’s A2Z Sheet / LeetCode practice. Today’s problem focused on finding the maximum depth (height) of a binary tree, which is a fundamental concept used in many tree-related problems. Approach We use recursion (DFS) to compute the height of the tree. For every node: Height = 1 + max(height of left subtree, height of right subtree) Base case: If node == null → return 0. Time complexity : O(N) . Space Complexity : O(N). Github Code :- https://lnkd.in/gnDkqcFQ #LeetCode #DSA #StriverA2Z #CodingJourney #Java #BinaryTree #TreeRecursion #ProblemSolving #CodingPractice #SoftwareEngineering #TechInterviewPrep #Day15 #DeveloperJourney
To view or add a comment, sign in
-
-
LeetCode Day 45 Today I solved the Contains Duplicate problem. Problem Insight: Given an integer array, we need to check whether any element appears more than once. Approach: Sorted the array first Compared adjacent elements If two consecutive elements are equal → duplicate found Key Learning: Sorting helps bring duplicates together, making it easy to detect them with a single pass. Complexity: Time: O(n log n) Space: O(1) Consistency builds confidence — Day 45 done! #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
🚀 DSA Journey Update: 7/75 Solved another problem today: Product of Array Except Self 💡 Key Idea: Used prefix (left) and suffix (right) products to build the answer without using division and in O(n) time. 🔍 Example: Input: [1,2,3,4] Output: [24,12,8,6] ⚡ Learning: Optimized approach using two passes Space optimization by reusing the same array Stronger understanding of prefix/suffix patterns Step by step progress… consistency matters more than speed 🔥 #DSA #Java #LeetCode #CodingJourney #100DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 20 of My DSA Journey Solved LeetCode Problem #1394 — Find Lucky Integer in an Array 💡 📌 Problem Summary: Given an array of integers, find the largest number whose frequency in the array is equal to its value. If no such number exists, return -1. 🧠 Approach: Used HashMap to store frequency of each element Traversed the map to check if frequency == value Tracked the maximum lucky number 💻 Key Learning: Importance of frequency counting Efficient use of HashMap Writing clean and optimized code using getOrDefault() ⏱ Time Complexity: O(n) 📦 Space Complexity: O(n) ✅ Consistency is the key — small steps every day lead to big results! #Day20 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 58 of #100DaysOfCode Solved – Check Balanced String 🔍 What I did: Traversed the string and calculated the sum of digits at even and odd indices separately, then compared both sums to determine if the string is balanced. 💡 Key Learning: Practiced string traversal and indexing Improved understanding of even vs odd index logic Learned how to convert char to integer (c - '0') 🎯 Takeaway: Even simple index-based problems can strengthen your fundamentals and attention to detail. #Day58 #LeetCode #Java #ProblemSolving #CodingJourney #100DaysOfCode #DSA
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