Problem statement
Write function solution(tokens, size, overlap). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. tokens:JSON[], size:integer 1–1024, overlap:integer 0<=overlap<size. Start at 0 and advance by size-overlap. Each chunk is {start,end,tokens}, with end=min(length,start+size) exclusive. Stop immediately after a chunk reaches the input end. Empty input yields []. Preserve JSON tokens without joining or string conversion. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
"a",
"b",
"c",
"d",
"e"
],
3,
1
]Return value
[
{
"start": 0,
"end": 3,
"tokens": [
"a",
"b",
"c"
]
},
{
"start": 2,
"end": 5,
"tokens": [
"c",
"d",
"e"
]
}
]Example 2
Function arguments
[
[
"a",
"b",
"c",
"d"
],
2,
0
]Return value
[
{
"start": 0,
"end": 2,
"tokens": [
"a",
"b"
]
},
{
"start": 2,
"end": 4,
"tokens": [
"c",
"d"
]
}
]Example 3
Function arguments
[
[
null,
true
],
3,
0
]Return value
[
{
"start": 0,
"end": 2,
"tokens": [
null,
true
]
}
]