One problem a day logo One problem a day
Browse problems
All problems 944 About this project

Categories

  • Array & Hashmap 217
  • Backtracking 33
  • Binary Search 27
  • Bit Manipulataion 25
  • Design 46
  • Dynamic Programming 85
  • Graph 74
  • Greedy 59
  • Heap 44
  • Intervals 16
  • Linked List 50
  • Math & Germetry 85
  • Queue 15
  • Sliding Window 29
  • Stack 48
  • Tree 122
  • Trie 14
  • Two Pointers 31

© 2026 One problem a day

Problems Number of segments in a string
array and hashmap January 5, 2023

Number of segments in a string

Time O(n) Space O(n) Open original problem

We will split the string by space, then count the number of non-empty string.

class Solution:
    def countSegments(self, s: str) -> int:
        return len(s.split())

Time complexity: O(n)
Space complexity: O(n)

Previous problem ← Steps to make array non decreasing
Next problem Most profit assigning work →

On this page

Start typing to search all 944 problems.
↑↓ Navigate ↵ Open Powered by Fuse.js