💡 One Small Problem, Big Lesson I recently solved a classic DSA problem: finding the *first non-repeating character* in a string, and it taught me more than I expected. At first glance, it looks simple. But solving it efficiently pushed me to think deeper about: 🔹 Time complexity (avoiding O(n²) solutions) 🔹 Using the right data structures (HashMap for frequency counting) 🔹 Writing clean, readable logic I implemented a solution in Java using a two-pass approach: 1. Count character frequencies 2. Identify the first character with a count of 1 This brought the solution down to *O(n)* time complexity, a big win compared to brute force. Moments like this remind me that mastering Data Structures & Algorithms isn’t about memorizing solutions, but about learning how to think. I’m continuously improving my problem-solving skills and applying them to real-world backend engineering challenges. If you're also on the DSA journey, what problem challenged your thinking recently? #Java #DSA #ProblemSolving #BackendDevelopment #SoftwareEngineering
Java DSA: First Non-Repeating Character Solution
More Relevant Posts
-
🚀 Day 6 of My DSA Journey – Mastering Patterns, Not Just Problems! Today I solved Two Sum II – Input Array is Sorted 🔢 💡 Key Insight: Two Pointer Pattern Instead of using a HashMap (O(n) space), I used the Two Pointer approach because the array is already sorted. 👉 Approach: Start with two pointers: left = 0 right = n - 1 Calculate sum: If sum == target → ✅ Found answer If sum < target → Move left++ If sum > target → Move right-- ⚡ Why this works? Because the array is sorted, we can intelligently move pointers to reduce time complexity. 📈 Complexity: Time: O(n) Space: O(1) 🧠 Pattern Learned: The Two Pointer Pattern is extremely powerful for: ✔ Sorted arrays ✔ Pair problems ✔ Optimization from brute force 💻 Tech Stack: Java | DSA | Problem Solving 🔥 Takeaway: Don’t just solve problems — identify patterns. That’s what turns practice into interview success. #DSA #Java #CodingJourney #LeetCode #SoftwareEngineer #ProblemSolving #TechCareers #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Mastering the DSA Pattern Universe Instead of solving problems randomly, I’ve started focusing on patterns — and it completely changed how I approach Data Structures & Algorithms. Here’s the structured roadmap I’m following: 🔹 Array & Interval Patterns 🔹 String & Hashing 🔹 Binary Search & Variants 🔹 Linked List Patterns 🔹 Stack & Queue Patterns 🔹 Tree & Graph Patterns 🔹 Heap, Greedy & Dynamic Programming 💡 The key insight: Most problems are just variations of a core pattern. Once you identify the pattern, solving becomes faster and more intuitive. 🛠️ What I’m doing: Practicing pattern-wise problems in Java Building structured DSA notes Maintaining clean GitHub repositories for consistency Focusing on problem-solving thinking, not just code 📈 Goal: To strengthen problem-solving skills and become industry-ready for backend/full-stack roles. If you're learning DSA, stop jumping randomly between questions — follow patterns, and everything starts connecting. #DSA #Java #ProblemSolving #CodingJourney #SoftwareDevelopment #FullStackDeveloper
To view or add a comment, sign in
-
-
🚀 Day 22 of My DSA Journey Today I solved an important Binary Search problem: 👉 Find First and Last Position of Element in Sorted Array 🧩 Problem Understanding Given a sorted array and a target value, we need to find the starting and ending position of the target element. If the target is not present, return [-1, -1]. 🔍 Approach I Used (Binary Search x2) Instead of linear search, I used Binary Search twice: ✔️ First Binary Search → to find the first occurrence ✔️ Second Binary Search → to find the last occurrence 💡 Trick: Even after finding the target, we don’t stop — we continue searching on left/right side to get the boundary indices. ⚡ Why this approach? Because the array is sorted → Binary Search reduces time complexity drastically. ⏱ Time Complexity: O(log n) 📦 Space Complexity: O(1) 🔥 Key Learning Binary Search is not just for finding elements — it can also be used to find boundaries, ranges, and conditions. Consistency is the real game changer 💪 One problem at a time! #DSA #BinarySearch #LeetCode #Java #ProblemSolving #100DaysOfCode #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚀 DSA Preparation 💪 Solved a fundamental Binary Search problem, a key concept for efficient searching. Focused on reducing search space by half in each step to achieve optimal performance 🔥 🧠 Problem 🔎 Binary Search Given a sorted array nums and a target value, return its index if found. If the target does not exist, return -1. 👉 The solution must run in O(log n) time complexity. Example Input: nums = [-1,0,3,5,9,12], target = 9 Output: 4 Input: nums = [-1,0,3,5,9,12], target = 2 Output: -1 ⚡ Key Learning 📌 Binary Search works only on sorted arrays 📌 Each step halves the search space → highly efficient 📌 Time Complexity: O(log n) 📌 Space Complexity: O(1) Improving DSA with strong fundamentals 🚀 #DSA #LeetCode #BinarySearch #Algorithms #Java #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 61 of My DSA Journey Today I solved the Subsets problem using the Backtracking technique. 🔹 Problem: Given an integer array nums, return all possible subsets (the power set). 🔹 Key Idea: Instead of trying to generate subsets directly, I used backtracking to explore every possible combination. 💡 Approach: Start with an empty subset. At each step, add the current subset to the result. Try including each element one by one. Recursively explore further subsets. Backtrack by removing the last element to explore other possibilities. 🔁 This approach systematically explores every possible subset using a decision tree. 📊 Time Complexity: O(n × 2ⁿ) — because each element can either be included or excluded. ✨ What I Learned: Backtracking is powerful for solving combinatorial problems. The pattern of choose → explore → unchoose is very important. 💻 Practicing problems like this helps strengthen recursion and problem-solving skills. #Day61 #DSA #Backtracking #Java #CodingJourney #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 86 of DSA Problem Solving 💡 Problem Solved: Next Greater Element I 🔍 Problem Idea: Given two arrays where nums1 is a subset of nums2, the task is to find the next greater element for each value in nums1 based on its position in nums2. 👉 The next greater element is the first element to the right that is larger than the current number. 🧠 Key Learning: Instead of using a brute-force approach (O(n²)), we optimize using a Monotonic Stack. ✔ Traverse nums2 from right to left ✔ Maintain a decreasing stack ✔ Pop all smaller elements → the top becomes the next greater ⚙️ Concepts Practiced: Monotonic Stack Stack + HashMap combination Efficient lookup strategy Right-to-left traversal ⏱️ Time Complexity: O(n + m) → Linear time using stack O(n) space for stack + hashmap 💭 Real Journey Behind the Solution: At first glance, it feels like a simple comparison problem 🤔 But brute force quickly becomes inefficient. The real breakthrough came when I realized: 👉 “We don’t need to check repeatedly — we can store useful answers while traversing once.” That’s where the monotonic stack pattern clicked 💡 A powerful technique I’m seeing again and again in DSA! 🔥 This problem strengthened my understanding of: Pattern recognition in stacks Writing optimal solutions under constraints 📌 Consistency is the real game. Small daily wins → Big long-term growth. #Day86 #DSA #LeetCode #CodingJourney #Java #Stack #MonotonicStack #ProblemSolving #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🔥 DSA Challenge – Day 127/360 🚀 📌 Topic: Backtracking 🧩 Problem: Subsets II Problem Statement: Given an integer array that may contain duplicates, return all possible subsets such that the solution set does not contain duplicate subsets. 🔍 Example: Input: nums = [1,2,2] Output: [[], [1], [1,2], [1,2,2], [2], [2,2]] 💡 Approach: Backtracking + Sorting 1️⃣ Step 1 – Sort the array to group duplicate elements together 2️⃣ Step 2 – Use recursion to generate all subsets 3️⃣ Step 3 – Skip duplicate elements using condition (i != ind && nums[i] == nums[i-1]) ⏱ Complexity: Time: O(2^n) Space: O(n) (recursion stack + subset storage) 📚 Key Learning: Sorting + smart skipping of duplicates helps avoid repeated subsets in backtracking problems. #DSA #Java #Coding #InterviewPrep #ProblemSolving #TechJourney #360DaysOfCode #LeetCode #Backtracking
To view or add a comment, sign in
-
-
🚀 Day 15 of My DSA Journey Today’s problem: Array Rank Transform 💡 Problem Insight: Given an array, replace each element with its rank when the array is sorted. Rank starts from 1 Equal elements → same rank Ranks must be continuous (no gaps) 🧠 Approach: 🔹 Clone and sort the array 🔹 Use a HashMap to assign ranks to unique elements 🔹 Traverse original array and replace values using the map ⚡ Key Learning: 👉 This is a classic example of Coordinate Compression 👉 Helps reduce large values into a smaller ranked range 💻 Code Logic: Sort copy of array Assign rank only if element not already mapped Replace original values using the map 📊 Result: ✅ 43 / 43 test cases passed ⏱ Runtime: 31 ms 📈 Beat: 58.58% 💾 Memory: 74.74 MB (85.14% better than others) 💭 Takeaway: Simple problems can test clean thinking + handling duplicates properly. Hashing + sorting is a powerful combo 🔥 🔥 Consistency Check: Day 15 Complete Building discipline one problem at a time. #DSA #CodingJourney #LeetCode #Java #ProblemSolving #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 1 of becoming DSA consistent (no excuses) Problem name : Minimum Distance Between Three Equal Elements II Difficulty : Medium Topic : Hash Table Most people would brute-force this problem… but there’s a smarter way using grouping. 🧠 Approach : 👉 Instead of comparing all triplets (which is slow), we optimize using a HashMap. Step 1: Store indices Traverse the array For each number, store all its indices in a map number → list of positions Step 2: Filter useful candidates Only consider numbers that appear at least 3 times Others cannot form a valid triplet Step 3: Check consecutive triplets For each list of indices: Pick 3 consecutive indices → (i, i+1, i+2) Since indices are sorted, this ensures minimum distance. Step 4: Compute distance, Distance is calculated between the 3 positions. Simplifies to: 2 × (last index − first index); Step 5: Track minimum. Keep updating the smallest distance found. If no valid triplet → return -1; Key Learning : When dealing with repeated elements: Use HashMap for grouping, Work on indices instead of values, Look for patterns (like consecutive grouping) to reduce complexity. IF YOU GUYS USED DIFFERENT LOGIC , Drop your logic below 👇... #leetcode #dsa #coding #softwareengineering #programming #interviewprep #java #grow #innovation #LetsConnect
To view or add a comment, sign in
-
-
Day 2/30 — DSA Challenge Today’s problem: Remove Duplicates from a Sorted Array I started with my own intuition — thought I could simply count the duplicates and subtract them from the array length. Sounded logical at first, but it didn’t hold up. Several test cases failed, and that’s when I knew something was off. After rethinking the approach, I realized this problem isn’t about counting duplicates — it’s about maintaining the structure of the array while removing them in-place. That’s when the key insight clicked: Since the array is already sorted, duplicates are always adjacent. This makes it a perfect use case for the two-pointer technique. Instead of counting, the idea is to: • Identify unique elements • Shift them forward in the array • Ignore the rest Once I understood that, the problem became surprisingly simple. Lesson from today: Sometimes the first idea feels right but fails in edge cases. The real skill is stepping back, rethinking, and adapting your approach. #Day2 #DSAChallenge #ProblemSolving #CodingJourney #Java #Algorithms
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