Day: 97/365 📌 LeetCode POTD: Minimum Distance to the Target Element Easy Key takeaways/Learnings from this problem: 1. This one shows that sometimes the simplest approach—just scanning the array—is more than enough. 2. Key learning: track the minimum absolute distance on the go instead of storing unnecessary data. 3. Good reminder that not every problem needs fancy algorithms, clarity beats complexity. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
Minimum Distance to Target Element LeetCode Solution
More Relevant Posts
-
🚀 Day 88 / 100 — LeetCode Challenge Solved: Find Minimum in Rotated Sorted Array 💡 Approach: Used Binary Search (O(log n)) to efficiently locate the minimum element in a rotated sorted array. Instead of scanning linearly, compared mid with high to decide the search direction. 🔍 Key Insight: If nums[mid] > nums[high] → minimum is in the right half Else → minimum is in the left half (including mid) ⚡ Performance: Runtime: 0 ms (Beats 100%) Memory: 43.92 MB 🧠 Learning: Understanding how sorted + rotated arrays behave helps reduce time complexity drastically from O(n) → O(log n) Consistency is key. 12 days to go 💯🔥 #Day88 #LeetCode #BinarySearch #Java #DSA #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 Day 85 of my LeetCode Journey 🔥 📘 Problem: 257. Binary Tree Paths 🎯 Difficulty: Easy 🔹 Problem Statement: Given the root of a binary tree, return all root-to-leaf paths in any order. A leaf is a node with no children. 🔹 Approach Used: Use recursion to traverse the tree If a node is a leaf → add its value as a path For non-leaf nodes: Recursively get paths from left subtree Recursively get paths from right subtree Append current node value with "->" to each child path Collect and return all paths 🔹 Key Concepts: Recursion Depth-First Search (DFS) Tree traversal String manipulation 🔹 Learning: This problem strengthens understanding of DFS traversal and how to build paths dynamically during recursion. It also shows how to combine results from subtrees efficiently. ✅ Status: Accepted (Runtime: 5 ms) 📌 Break problems into smaller subproblems — recursion does the rest 🚀 #LeetCode #Day82 #Java #BinaryTree #DFS #Recursion #DSA #ProblemSolving
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 30 Today’s focus: HashMap for frequency counting. Problem solved: • Number of Good Pairs (LeetCode 1512) Concepts used: • HashMap • Frequency counting • Incremental counting technique Key takeaway: The goal is to count pairs (i, j) such that nums[i] == nums[j] and i < j. Instead of checking all pairs (which would take O(n²)), we use a HashMap to track frequencies. As we iterate through the array: • For each number, we check how many times it has already appeared • That count directly contributes to the number of valid pairs • Then we update its frequency in the map This allows counting pairs in a single pass with O(n) time complexity. Continuing to strengthen fundamentals and consistency in problem solving. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
--------LeetCode Progress Update Solved: Convert a Number to Hexadecimal (405) * Problem Insight: Convert a 32-bit integer into its hexadecimal representation without using built-in conversion methods. * Approach: • Used bit manipulation (num & 15) to extract last 4 bits • Mapped values to hexadecimal characters (0-9, a-f) • Right shift (>>> 4) to process next chunk • Handled negative numbers using 2’s complement logic automatically * Key Learning: Bit manipulation makes low-level operations both efficient and elegant—especially when dealing with number systems. #LeetCode #DSA #Java #BitManipulation #ProblemSolving
To view or add a comment, sign in
-
-
Day 37 of showing up consistently 💻🔥 Solved Arithmetic Subarrays — a problem that really sharpened my understanding of subarrays and sequence patterns. 💡 Insight: Instead of checking order directly, sorting the subarray and verifying a constant difference makes the solution clean and efficient. ⚡ Runtime: 4 ms (100% 💯) 📊 Small optimizations → Big impact Every day = 1 step closer to mastery. #Day37 #LeetCode #DSA #Java #CodingJourney #Consistency #KeepGrinding
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟔𝟑 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on rotating an array to the right by k steps efficiently. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Rotate Array 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐑𝐞𝐯𝐞𝐫𝐬𝐚𝐥 𝐓𝐞𝐜𝐡𝐧𝐢𝐪𝐮𝐞 • First normalized k using k % n • Reversed the entire array • Reversed the first k elements • Reversed the remaining elements This results in the desired rotation. 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • Reversal technique is a powerful in-place trick • Breaking a problem into steps simplifies logic • Modulo helps handle large values of k • In-place operations reduce space complexity 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 Sometimes the best solution is not shifting elements — but rearranging them smartly. 63 days consistent 🚀 On to Day 64. #DSA #Arrays #TwoPointers #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
LeetCode Challenge – Day 51 Today I solved the Diameter of Binary Tree problem. Problem Insight: The task is to find the length of the longest path between any two nodes in a binary tree. The path does not necessarily pass through the root. Approach: Used Depth First Search (DFS) to calculate the height of each subtree For every node: Calculated left subtree height Calculated right subtree height Updated the maximum diameter as the sum of left and right heights Returned the maximum diameter found during traversal Key Learning: Tree problems often combine multiple concepts. Here, calculating height and updating diameter together in a single traversal makes the solution efficient. Complexity: Time: O(n) Space: O(h) This problem helped me understand how recursion can be used to compute multiple values in a single traversal. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
🚀 Day 43 of my #100DaysOfCode Journey Today, I solved the LeetCode problem: Sum of Unique Elements Problem Insight: Find elements in an array that appear exactly once and calculate their total sum. Approach: • Used a frequency array to count occurrences of each number • Traversed the array to build frequency • Added only those elements to sum whose frequency is exactly 1 Time Complexity: • O(n) Space Complexity: • O(1) (fixed size array used for constraints) Key Learnings: • Frequency array is faster than HashMap when range is fixed • Two-pass approach makes logic clear and simple • Always check constraints before choosing data structure Takeaway: Right data structure makes the solution simple and efficient 🚀 #DSA #Java #LeetCode #100DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 4 of My LeetCode Journey Solved today’s POTD (Problem of The Day): Closest Equal Element Queries (Medium) 📝 Problem Summary Given a circular array, for each query index, find the minimum distance to another index having the same value. If no such index exists, return -1. 🧠 Intuition Instead of checking every index for each query (brute force), I realized we only need to focus on positions where the same value occurs. 💡 Approach ✔️ Used a HashMap to store: value → list of indices ✔️ For each query: Found the index position using binary search Checked only left and right neighbors (closest possible matches) ✔️ Calculated distance using circular logic: min(|i - j|, n - |i - j|) 📚 Key Learning Smart preprocessing can reduce time complexity significantly In circular arrays, always consider wrap-around distance Nearest element problems often reduce to adjacent comparisons #LeetCode #Day4 #DSA #ProblemOfTheDay #Java #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 Day 16 of LeetCode Problem Solving Solved today’s problem — LeetCode #26: Remove Duplicates from Sorted Array 💻🔥 ✅ Approach: Two Pointers ⚡ Time Complexity: O(n) 📊 Space Complexity: O(1) The task was to remove duplicates in-place from a sorted array and return the count of unique elements. 👉 I used the Two Pointer technique: One pointer to track unique elements Another to traverse the array 💡 Key Idea: Since the array is sorted, duplicates will be adjacent — making it easier to skip them. 👉 Core Logic: Compare nums[i] with nums[j] If different → move pointer and update value Maintain unique elements at the beginning 💡 Key Learning: Two Pointer is a very powerful technique for array problems — especially when data is sorted. Consistency is the key — getting better every day 🚀 #Day16 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
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