🚀 Day 68 -#100DaysOfCode Solving String Problems in Java Today I worked on a problem to find the maximum number of words in a sentence from an array of strings. 🔍 Key Learning: Number of words in a sentence = number of spaces + 1 Importance of placing counters correctly in loops Avoid resetting variables inside inner loops Improved understanding of string traversal using charAt() ✅ Approach I Used: Traverse each sentence Count spaces to determine word count Track the maximum words across all sentences 💡 What I Improved Today: ✔ Loop logic and debugging skills ✔ String manipulation techniques in Java ✔ Problem-solving accuracy #Day68 #CodingJourney #Java #ProblemSolving #100DaysOfCode #LearningInPublic
Java String Problem Solving: Max Words in Sentence
More Relevant Posts
-
Day 44 of #100DaysOfLeetCode 💻✅ Solved Very Simple #169. Majority Element problem in Java. Approach: • Sorted the given array using Arrays.sort() • Observed that the majority element appears more than n/2 times • After sorting, the majority element will always be present at index n/2 • Returned the element at nums[n/2] Performance: ✓ Runtime: 7 ms (Beats 42.86% submissions) ✓ Memory: 55.96 MB (Beats 16.21% submissions) Key Learning: ✓ Understood how sorting can help identify the majority element ✓ Learned the property that the majority element always occupies the middle position after sorting ✓ Practiced array manipulation and problem solving in Java Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 72 ✅ LeetCode Problem Solved: Subsets II 🔁 Concept Used: Backtracking + Recursion 🧠 Key Focus: Handling duplicate elements correctly Today I solved Subsets II, where the main challenge was generating all unique subsets from an array that may contain duplicates. 🔑 What I learned: Why sorting the array is important before recursion How to skip duplicates using this condition: if (idx > i && nums[idx] == nums[idx - 1]) continue; Proper backtracking steps (add → recurse → remove) How recursion builds subsets step by step Learning something new every day and getting better at problem-solving 💪 #DSA #Java #LeetCode #Backtracking #Recursion #ProblemSolving #CodingJourney #DailyLearning #Consistency
To view or add a comment, sign in
-
-
🚀 Day 30 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Sorting Technique 🧩 Problem Solved: Longest Common Prefix Problem: Given an array of strings, find the longest common prefix shared among all the strings. Approach: Sorted the array of strings and compared only the first and last strings. Since sorting groups similar prefixes together, the common prefix between these two strings represents the common prefix for the entire array. Key Learning: ✔️ Using sorting to simplify string comparison problems ✔️ Observing patterns to reduce unnecessary checks ✔️ Efficient prefix detection in string arrays If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 29 of #100DaysOfLeetCode 💻✅ Solved #22. Generate Parentheses on LeetCode using Java. Approach: • Used Backtracking to generate all valid combinations • Added "(" only if open brackets were available • Added ")" only when close brackets were greater than open • Ensured at every step that the parentheses remain balanced • Stopped recursion when both open and close counts reached zero Performance: ✓ Runtime: 3 ms (Beats 16.29% submissions) ✓ Memory: 45.18 MB (Beats 13.87% submissions) Key Learning: ✓ Strengthened understanding of Backtracking technique ✓ Learned how to maintain constraints during recursion ✓ Improved ability to build combinations using decision trees Learning one problem every single day 🚀 #Java #LeetCode #DSA #Backtracking #Recursion #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 34 of #100DaysOfLeetCode 💻✅ Solved #110. Balanced Binary Tree on LeetCode using Java. Approach: • Used a bottom-up recursive approach to calculate height • Returned -1 immediately if any subtree is unbalanced • Compared left and right subtree heights at each node • Checked if the height difference is greater than 1 • Stopped early to optimize unnecessary computations Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.33 MB (Beats 95.41% submissions) Key Learning: ✓ Understood how to combine height calculation with balance checking ✓ Learned early termination technique in recursion ✓ Improved problem-solving for tree-based recursive problems Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinaryTree #Recursion #TreeProblems #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 27 / 180 – DSA with Java 🚀 📘 Topic Covered: Strings & Reverse Traversal 🧩 Problem Solved: Length of Last Word Problem: Given a string containing words separated by spaces, find the length of the last word. Approach: Started traversing the string from the end, skipped trailing spaces first, and then counted characters until encountering another space or reaching the beginning of the string. Key Learning: ✔️ Efficient reverse traversal in strings ✔️ Handling edge cases like trailing spaces ✔️ Writing simple yet optimized string logic If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Strings #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 49 of #100DaysOfLeetCode 💻✅ Solved #387. First Unique Character in a String problem in Java. Approach: • Created an array of size 26 to store the frequency of each character • Traversed the string and counted how many times each character appears • Traversed the string again to find first character with frequency equal to 1 • Returned the index of that character • If no unique character is found, returned -1 Performance: ✓ Runtime: 6 ms (Beats 84.58% submissions) ✓ Memory: 47.16 MB (Beats 36.29% submissions) Key Learning: ✓ Practiced using frequency arrays for string problems ✓ Learned how counting characters helps find unique elements efficiently ✓ Strengthened understanding of string traversal and indexing Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 76 ✅ Today I solved the “Check if Binary String Has at Most One Segment of Ones” problem on LeetCode. 💡 Problem Idea: Given a binary string, we need to check whether there is at most one continuous segment of '1's in the string. 🧠 Approach: Traverse the string using a loop. Count how many segments of '1' appear. If the count becomes greater than 1, return false. Otherwise return true. ⚡ Key Concepts Practiced: String traversal While loop Character comparison Logical conditions Consistency in solving problems every day is helping me strengthen my problem-solving and logical thinking skills in Java. #DSA #Java #LeetCode #ProblemSolving #CodingJourney #WomenInTech #100DaysOfCode
To view or add a comment, sign in
-
-
Learning 2D Arrays & Jagged Arrays in Java Recently explored the concepts of 2D arrays and jagged arrays in Java and focused on understanding how they actually work in memory. Key takeaways: • Each row is stored separately in memory • Jagged arrays allow different row sizes • Better understanding of references and dynamic allocation Visualizing the internal structure helped me strengthen my logical thinking and clarity in handling multidimensional data. Building strong fundamentals step by step with Harshit T at TAP Academy #Java #DataStructures #Arrays #JaggedArrays #ProgrammingFundamentals #LearningJourney #DeveloperGrowth
To view or add a comment, sign in
-
-
While solving a DSA problem on LeetCode, I noticed the solution used StringBuilder instead of a normal String in Java. At first I thought — why not just use String? 🤔 While exploring this, I learned that every time we modify a String, Java creates a new object in memory. The old objects become unused, which are called garbage values and later cleaned by the garbage collector. A small doubt while solving one question helped me understand how memory actually works in Java 💡 #Java #DSA #LearningInPublic #Programming #LeetCode
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