Problem Description
Given a string s representing a sentence, check if all the numbers in s are strictly increasing from left to right.
Key Insights
- A sentence consists of tokens that can be either positive numbers or words.
- The numbers must be strictly increasing, meaning each number must be smaller than the subsequent number.
- The problem can be solved by extracting numbers from the string and verifying their order.
Space and Time Complexity
Time Complexity: O(n), where n is the length of the string s, since we need to traverse the string to extract tokens. Space Complexity: O(m), where m is the number of numbers in the string, to store the extracted numbers.
Solution
The solution involves the following steps:
- Split the input string into tokens based on spaces.
- Extract numbers from the tokens and convert them to integers.
- Iterate through the list of numbers and check if each number is less than the next one.
- Return true if all numbers are in strictly increasing order; otherwise, return false.
This approach uses a list to store the extracted numbers and a simple loop to verify the order, making it efficient and straightforward.