Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-324

Token Offsets from Whitespace

Problem

Given text, return the [start, end) character offsets of each whitespace-separated token.

Given the text, return a list of [start, end] pairs in order.

Hint

Track the start of each non-space run and close it at whitespace or the end.

Test cases

case 1
in: ["ab cd"]
expected: [[0,2],[3,5]]
case 2
in: ["a b"]
expected: [[0,1],[3,4]]
case 3
in: [""]
expected: []
Starter codePython
def token_offsets_from_whitespace(text):
    # Your code here
    pass

3 test cases · run your code against them in the editor