LeetCode 434 | Number of Segments in a String | O(n) Time | O(n) Space | Easy Solution

Description: Number of Segments in a String is a beginner-friendly LeetCode problem that helps improve your understanding of strings, splitting operations, and text processing. A segment is defined as a contiguous sequence of non-space characters. Given a string s, return the number of segments present in the string. ✅ Approach The idea is simple and efficient: Split the string using spaces as separators Traverse the resulting array of strings Ignore empty strings created by multiple spaces Count only valid non-empty segments Return the final count This approach is straightforward and perfect for learning string manipulation and parsing techniques. ✅ Time Complexity O(n) → We traverse the entire string once while splitting and counting ✅ Space Complexity O(n) → Additional space is used to store the split segments 🔗 LeetCode https://leetcode.com/u/TR0kHGhQN9/ 🔗 LinkedIn   / dhruvi-patel-bb2b9239a   📝 Notes A segment is a sequence of characters separated by spaces Multiple consecutive spaces should not be counted as segments Great problem for practicing string parsing Helps strengthen understanding of string splitting operations Frequently asked in beginner coding assessments Demonstrates how text can be processed efficiently using built-in string functions #leetcode #dsa #coding #programming #java #python #cplusplus #strings #numberofsegmentsinastring #leetcodeeasy #codinginterview #algorithms #softwareengineer #computerscience #datastructures #stringmanipulation #textprocessing #logicbuilding #parsing