Day 22/100: Longest Common Prefix 📏 Today's challenge was about finding the common starting thread in an array of strings. The Logic: Vertical Scanning Instead of comparing whole words, I looked at them character by character across the entire list. If "flower", "flow", and "flight" all have 'f' and 'l' at the start, that's our prefix. As soon as a mismatch happens, we cut the string and return the result. Complexity: O(S) where S is the sum of all characters in all strings. #100DaysOfCode #Java #DSA #Strings #CodingJourney #Day22 #LearnInPublic
Day 22: Finding Common Prefix in Strings with Java
More Relevant Posts
-
Solved the Flatten a Multilevel Doubly Linked List problem using iterative pointer manipulation. The idea is to traverse the list, and whenever a node has a child, we attach the child list in between the current node and its next node. Then we find the tail of the child list and connect it back to the original next node. This way, we flatten the list in-place without using extra space. Time Complexity: O(n) Space Complexity: O(1) #Java #DSA #LinkedList #LeetCode #Coding
To view or add a comment, sign in
-
-
Day 33/50 🚀 — Valid Palindrome (Two Pointer Approach) Today’s problem was a great mix of string manipulation + two pointers. 🔹 Ignored non-alphanumeric characters 🔹 Handled case-insensitivity 🔹 Compared characters from both ends efficiently Key insight: Instead of preprocessing the string, we can optimize in-place using two pointers, skipping unwanted characters on the go. 💡 This improves both readability and performance. Performance: ⚡ Runtime: 2 ms (99%+) 📦 Memory: Efficient #Day33 #LeetCode #TwoPointers #DSA #Java #CodingJourney #50DaysOfCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 56/100 Today’s problem: String Compression (In-place) 💡 Key Learnings: - Learned how to use Two Pointers (Read & Write) efficiently - Understood in-place modification without extra space - Handled edge cases like counts greater than 9 (e.g., 12 → '1','2') - Improved thinking around grouping consecutive characters 🧠 Approach: Used a read pointer to traverse the array and a write pointer to update the compressed result directly in the same array. ⚡ Time Complexity: O(n) 📦 Space Complexity: O(1) Consistency is the real game 💯 #Day56 #Java #DSA #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 22/100 – #100DaysOfCode Today I worked on the Longest Common Prefix problem and focused on improving both efficiency and clarity in my approach. Key Takeaways: Start with the first string as the initial prefix Gradually shrink the prefix until it matches all strings Always handle edge cases (empty array / no common prefix) Small optimizations like avoiding unnecessary string creation can improve performance ⚡ Result: Achieved optimal time complexity: O(N * M) Clean and readable solution 100% test cases passed Example: Input: ["flower", "flow", "flight"] Output: "fl" This problem reinforced an important lesson: Sometimes the best solution is not adding complexity, but simplifying step by step. On to Day 23 #CodingJourney #Java #DSA #LeetCode #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Solved the Binary Tree Right Side View problem using a DFS approach. The idea is to traverse the tree level-wise but visit the right child first. For each level, the first node we encounter is the visible node from the right side, so we add it to the result. By prioritizing right before left, we ensure only the rightmost nodes are captured. Time Complexity: O(n) Space Complexity: O(h) (recursion stack) #Java #DSA #Tree #DFS #LeetCode #Coding
To view or add a comment, sign in
-
-
Day 82 - Kth Smallest Element in a BST Used inorder traversal to find the kth smallest element in a binary search tree. Approach: • Inorder traversal of BST gives sorted order • Maintain a counter while traversing • When count == k, capture the value Time Complexity: O(n) Space Complexity: O(h) #Day82 #LeetCode #BST #BinaryTree #DSA #Java #CodingJourney
To view or add a comment, sign in
-
-
Just cracked LeetCode #9 – Palindrome Number. Sounds simple, but the follow-up challenge of solving it without converting to a string makes you really think about the math behind it. 🚀 The approach was straightforward — reverse the number mathematically (no string conversion!) and compare it with the original. Negative numbers and trailing zeros are the edge cases that catch you off guard if you're not careful. 🧑💻 Beats 79.66% in runtime and 95.20% in memory. Not perfect, but I'll take it. One problem at a time. That's the game. 💪 #LeetCode #Java #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
Solved the Copy List with Random Pointer problem using an in-place approach. Instead of using extra space like HashMap, the solution inserts copied nodes in between original nodes, sets random pointers, and then separates both lists. This keeps the solution efficient in both time and space. Time Complexity: O(n) Space Complexity: O(1) #Java #DSA #LinkedList #LeetCode #Coding
To view or add a comment, sign in
-
-
🚀 Day 23 of #128DaysOfCode Today I solved an interesting string problem where one string is shuffled and an extra character is added. 🔍 What I learned: - How to use character ASCII values to simplify problems - Instead of comparing strings directly, we can use sum difference logic - Converting between char and int makes calculations easier and efficient 💡 Key idea: If we add all characters of both strings and subtract, the remaining value gives the extra character. ⚡ This approach is simple, clean, and runs in O(n) time with O(1) space. Consistency is building momentum 🔥 #Java #DSA #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 7 of #LeetCode Challenge 🔍 Problem: Sqrt(x) 💡 Approach: Used the built-in Math.sqrt() function to compute the square root and then typecasted it to an integer to get the floor value. 🧠 Key Concept: Understanding how to convert a floating-point result into an integer using typecasting. 🔥 #Day7 #LeetCode #Java #DSA #CodingJourney #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