------Continuing my DSA practice using Java. Today I worked on the “Shortest Completing Word” problem. The task was to find the shortest word that contains all the letters present in a given license plate. I first extracted and counted only the alphabetical characters from the license plate, ignoring digits and case. For each word, I compared its character frequency with the required frequency. If a word satisfied all the conditions, I checked whether it was shorter than the current answer and updated accordingly. Time Complexity: O(n × m) Space Complexity: O(1) Key takeaway: Breaking string problems into frequency comparison steps helps keep the logic clear and manageable. #DSA #Java #Strings #Hashing #ProblemSolving #LearningJourney
Java DSA Practice: Shortest Completing Word Problem
More Relevant Posts
-
Worked on another DSA problem in Java **Check if an Array is Sorted and Rotated - First tried a brute force approach by rotating the array multiple times and checking if it becomes sorted - Then used a better approach by comparing it with a sorted version of the array - Finally understood the optimal idea — if there is only one “dip” in the array, it can be sorted and rotated This problem helped me understand array rotation logic and optimization better. Trying to stay consistent and improve my problem-solving skills step by step 🙂 Code available on my GitHub https://lnkd.in/gBmMmSZQ If anyone has suggestions or knows a better approach, please feel free to share 🙌 #DSA #Java #ArrayProblems #ProblemSolving #CodingJourney #LearningInPublic #Consistency
To view or add a comment, sign in
-
Day 5 of revisiting Java + DSA. Today I practiced multiple applications of Linear Search in Java: ✔️ Searching in a String ✔️ Searching within a range in an array ✔️ Finding minimum number ✔️ Searching in 2D arrays ✔️ Counting numbers with even digits (logarithm approach) ✔️ Maximum wealth calculation in a 2D array Implemented each problem from scratch after learning the concept from Kunal Kushwaha Java + DSA playlist. Really appreciate how clearly he explains one concept and shows how it applies to many problem patterns. It makes practice much more meaningful. One concept. Multiple problem patterns. #Java #DSA #LinearSearch #ProblemSolving #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 2 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Move Zeroes Problem: Move all 0s to the end of the array while maintaining the relative order of non-zero elements, without using extra space. Approach: Identified the first zero and used a two-pointer method to swap non-zero elements forward, ensuring an in-place and efficient solution. Key Learning: ✔️ Better understanding of in-place array manipulation ✔️ Practical use of two-pointer logic ✔️ Writing optimized solutions with O(n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 21.... 💡 Today I learned about Prime Factorization in Java! Prime Factorization means breaking a number into its prime factors — the building blocks of the number. 🧩 Basic Approach: int i = 2; while (n > 1) { while (n % i == 0) { System.out.println(i); n = n / i; } i++; } ⏱️ Time Complexity: O(n) ⚙️ Optimized Approach: int i = 2; while (i * i <= n) { while (n % i == 0) { System.out.println(i); n = n / i; } i++; } if (n > 1) System.out.println(n); ⏱️ Time Complexity: O(√n) ✅ Key Takeaway: Checking factors only up to √n makes the algorithm much faster — no need to go till n. Small change, big improvement in performance! #Java #DSA #LearningJourney #Coding #Algorithms #Optimization
To view or add a comment, sign in
-
🚀 DSA Day 5 / 100 Solved the Two Sum problem on LeetCode using Java. Logic : • Go through the array one number at a time • For each number, check what value is needed to reach the target • Store each number with its index in a HashMap • If the needed value is already stored, we’ve found the answer #DSA #100DaysOfCode #Java #LeetCode #BeginnerDSA #LearningStepByStep #Consistency
To view or add a comment, sign in
-
-
🚀 Day 16 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Carry Handling 🧩 Problem Solved: Plus One Problem: Given a number represented as an array of digits, increment the number by one and return the updated array. Approach: Started from the last digit and handled the carry carefully. If the digit was less than 9, incremented it directly. If it was 9, set it to 0 and continued moving left to handle the carry. If all digits were 9, created a new array with an extra leading 1. Key Learning: ✔️ Handling carry propagation in arrays ✔️ Managing edge cases like all 9s ✔️ Thinking about number representation logically If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Day 5/30 – Java DSA Challenge 🔎 Problem 37: 2024. Maximize the Confusion of an Exam (LeetCode – Medium) Today’s problem is a powerful extension of the Sliding Window – At Most K Pattern 🔥 🧠 Problem Summary You are given: A string answerKey containing only 'T' and 'F' An integer k (maximum flips allowed) 🎯 Goal: After performing at most k flips, return the maximum number of consecutive identical answers. 💡 Core Idea To maximize consecutive characters: 👉 We maintain a sliding window 👉 Count number of 'F' and 'T' inside the window 👉 If the minimum of the two counts exceeds k, shrink the window Why min(c0, c1)? Because we can flip the smaller group into the larger one within k changes. This guarantees the longest valid window. ⏱ Time Complexity O(n) – Each character is added and removed from window at most once 📦 Space Complexity O(1) – Only counters used 📌 Key Takeaway “Flip at most K characters” → Think sliding window Always track frequency inside window Shrink when constraint breaks 🔥 37 Problems Completed Day 5 Consistency Continues 💪🚀 #Day5 #30DaysOfCode #Java #DSA #LeetCode #SlidingWindow #TwoPointers #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 1/30 – Java DSA Challenge 🔎 Problem 2: 3110. Score of a String (LeetCode – Easy) Solved my second problem for Day 1 of the 30 Days DSA challenge. 🧠 Problem Statement The score of a string is defined as the sum of the absolute difference between ASCII values of adjacent characters. We need to return the total score. 💡 Example Input: "hello" ASCII values: h = 104 e = 101 l = 108 l = 108 o = 111 Score calculation: |104 − 101| + |101 − 108| + |108 − 108| + |108 − 111| = 3 + 7 + 0 + 3 = 13 👨💻 Approach ✔ Start from index 1 ✔ Compare each character with its previous character ✔ Add the absolute difference to a running sum Since characters in Java are stored using ASCII values internally, we can directly subtract them. ⏱ Time Complexity: O(n) – We traverse the string once. 📦 Space Complexity: O(1) – Only a single variable is used. 📌 Key Learning: Understanding how characters are stored internally (ASCII values) helps simplify string problems. Excited to continue this journey 🚀 #Day1 #30DaysOfCode #Java #DSA #LeetCode #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 6 of My 90 Days Java Full Stack Challenge Today, I focused on understanding the theory of String in Java and solved a few basic String problems to build a strong foundation. 📘 What I learned today: What is String in Java Why String is immutable String Constant Pool (SCP) == vs equals() Difference between String, StringBuilder, and StringBuffer How String works internally (memory & performance basics) 🧩 Practice (Basic Level): ✔ Reverse a String ✔ Check Palindrome ✔ Count vowels & consonants ✔ Remove whitespaces 💡 Key takeaway: Before jumping into advanced DSA problems, clarity of concepts matters more than speed. 📅 Plan for tomorrow: 👉 Solve more String DSA problems (intermediate level) and go deeper with hands-on practice. Learning step by step, one day at a time 💪 #Java #StringInJava #90DaysJavaFullStack #DSA #LearningInPublic #Consistency #DeveloperJourney
To view or add a comment, sign in
-
🚀 Day 14 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Sorted-Rotation Logic 🧩 Problem Solved: Check if Array is Sorted and Rotated Problem: Determine whether a given array is sorted in non-decreasing order and then possibly rotated. Approach: Traversed the array and counted how many times the order decreases (where the current element is smaller than the previous one). If the count of such “break points” is at most one (including the circular check between last and first elements), the array satisfies the condition. Key Learning: ✔️ Understanding sorted array properties ✔️ Handling circular array comparisons ✔️ Solving rotation-based problems efficiently in O(n) time If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
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