Continuing my DSA practice on LeetCode, today I worked on another hard problem. * Problem: Valid Number (65) * Approach: This problem is about validating whether a string represents a valid number, including integers, decimals, and scientific notation. I solved it by scanning the string once and keeping track of certain conditions using flags: seenDigit to check if we have encountered any digit. seenDot to ensure only one decimal point appears. seenE to track if an exponent (e or E) appears. digitAfterE to make sure digits exist after the exponent. While iterating through the string, I handled different cases such as digits, signs (+/-), decimal points, and exponent characters and updated the flags accordingly. * Key Learning: This problem helped me practice carefully handling multiple conditions while parsing strings, which is common in many real-world validation and parsing tasks. #LeetCode #DSA #Java #ProblemSolving #CodingJourney
Valid Number Problem Solution on LeetCode
More Relevant Posts
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 #60DaysOfLeetCode – Day 32 Today’s problem was about removing all adjacent duplicates in a string. 🔹 Approach Used: Stack To efficiently handle consecutive duplicates, I used a stack-based approach: Traverse the string character by character. If the stack is not empty and the top element matches the current character, pop it (this removes the duplicate pair). Otherwise, push the current character onto the stack. Finally, build the result string from the stack and reverse it to maintain the correct order. 🔹 Key Learning: Using a stack helps simulate the process of removing adjacent duplicates in a single pass, achieving O(n) time complexity and avoiding unnecessary reprocessing. This problem highlights how stacks are powerful for handling sequential patterns and cancellations, especially in string manipulation problems. On to Day 33! 💻🔥 #LeetCode #DSA #Java #CodingChallenge #ProblemSolving #LearningInPublic #60DaysOfCode
To view or add a comment, sign in
-
-
Day 55 of #100DaysOfLeetCode 💻✅ Solved #434. Number of Segments in a String problem in Java. Approach: • Initialized a counter to track number of words (segments) • Traversed the string character by character • Checked for non-space characters • If the current character is not a space and either it is the first character or the previous character is a space, incremented the count • This ensures counting only the starting of each word Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 41.83 MB (Beats 99.81% submissions) Key Learning: ✓ Practiced string traversal without using extra space ✓ Learned how to identify word boundaries efficiently ✓ Improved logic building for handling spaces and edge cases Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 1 of my DSA Journey with CodeOjas! Today, I solved a “Array Reversal in Blocks” problem using Java. Problem: Given an array of integers and a block size, reverse the array in blocks of the given size, but keep the middle block unchanged. Example: Input: arr = [1, 2, 3, 4, 5, 6, 7], blockSize = 3 Output: [3, 2, 1, 4, 5, 6, 7] Approach: Divided the array into blocks of the given size Reversed all blocks except the middle block Constructed a new array to store the modified result (brute-force approach) Complexity: Time Complexity: O(n) Space Complexity: O(n) This is a brute-force approach — simple, clear, and easy to understand for beginners. 💡 Takeaway: Breaking down a problem into blocks can help solve complex array manipulation problems easily. 📂 Code is available on my GitHub: [https://lnkd.in/g4yxAJs3] #DSA #Java #CodingJourney #CodeOjas #ProblemSolving #LinkedInLearning
To view or add a comment, sign in
-
LeetCode Challenge – Day 49 Today I solved the Linked List Cycle problem. Problem Insight: Given a linked list, determine whether it contains a cycle (loop). A cycle occurs when a node points back to a previous node instead of reaching null. Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise and Hare) Maintained two pointers: Slow pointer moves one step at a time Fast pointer moves two steps at a time If a cycle exists, both pointers will eventually meet If not, the fast pointer will reach the end of the list Key Learning: Using two pointers with different speeds helps efficiently detect cycles without extra space. Complexity: Time: O(n) Space: O(1) Understanding pointer movement made this problem much easier to solve. #LeetCode #Java #DSA #CodingJourney
To view or add a comment, sign in
-
🚀 Day 94 -#100DaysOfCode Today I worked on a problem that looks simple at first but really tests your understanding of indexing and conditions. 💡 Problem Insight: Given an array, we need to calculate the sum of squares of elements whose indices (1-based) divide the length of the array. 🧠 Key Learning: Always be careful with 1-based vs 0-based indexing The condition n % i == 0 ensures we only pick valid positions Accessing elements correctly using nums[i-1] is crucial ⚡ What I Improved Today: Better understanding of index manipulation Writing cleaner loops with proper conditions Avoiding off-by-one errors #Day94 #CodingJourney #Java #DSA #LeetCode #Consistency #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 7 / 100 – LeetCode Challenge Today I solved Length of Last Word (LeetCode #58) using Java. 🔹 Problem: Given a string "s" containing words and spaces, return the length of the last word in the string. 📌 Approach: - Traverse the string from the end. - Ignore trailing spaces. - Start counting characters of the last word. - Stop when a space appears after counting begins. 💡 Key Concepts Practiced: - String traversal - "charAt()" usage - Reverse iteration - Conditional logic ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) ✅ Key Takeaway: Sometimes solving a problem becomes easier when we traverse the data from the end instead of the beginning. #100DaysOfCode #LeetCode #Java #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 69 — LeetCode Practice 🚀 Today’s focus was on string manipulation and careful indexing. ✅ Problem solved today: 🔹 Find Common Characters 💡 Key learnings from today: • Understood how to find common characters across multiple strings • Learned the importance of character frequency counting • Practiced handling nested loops efficiently • Realized how small mistakes in indexing can affect the entire logic • Improved attention to detail while working with strings Initially, I made a mistake by using the wrong variable inside charAt(). This caused incorrect indexing, which can either lead to wrong output or even StringIndexOutOfBoundsException. After fixing it, the logic worked perfectly by correctly comparing characters and tracking their minimum frequency across all words. This problem reinforced an important lesson: Sometimes errors are not in logic — but in small details like indexing and variable usage. Accuracy matters as much as logic. Step by step, getting better 💪 On to Day 70 🚀 #Day69 #DSA #LeetCode #ProblemSolving #Java #CodingJourney #Consistency #FutureEngineer
To view or add a comment, sign in
-
-
🚀 Day 63 of #LeetCode Practice Solved: Count Equal and Divisible Pairs in an Array (Easy) 🔹 Problem Summary: Given an array and an integer k, find the number of pairs (i, j) such that: • nums[i] == nums[j] • (i * j) is divisible by k 🔹 Approach: • Used two nested loops to check all pairs • Compared elements to find equal values • Checked if (i * j) % k == 0 • Counted valid pairs 🔹 Key Learning: Brute-force helps build a strong foundation and improves problem understanding before optimization. 💡 Consistency, patience, and small daily improvements lead to big results over time. #LeetCode #DSA #Java #CodingJourney #Consistency #KeepLearning
To view or add a comment, sign in
-
-
Day 22 of #50DaysLeetCode Challenge 🚀 Today I solved the “Remove Element” problem using Java. 🔹 Problem: Given an array and a value, remove all occurrences of that value in-place and return the number of remaining elements. 🔹 Approach: Used the two-pointer technique. One pointer iterates through the array, while the other keeps track of where to place elements that are not equal to the given value. 🔹 Key Learning: In-place array problems often rely on pointer manipulation instead of extra space. 🔹 Time Complexity: O(n) 🔹 Example: Input: nums = [3,2,2,3], val = 3 Output: 2 (array becomes [2,2,...]) Simple problem, but important for mastering array manipulation techniques. #Day22 #LeetCode #Java #DSA #Arrays #TwoPointers #CodingJourney #ProblemSolving
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