Problem statement
Write function solution(nodes, edges). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. nodes is an array of distinct strings; edges is an array of [from,to]. from must finish before to runs. Ignore edges containing unknown nodes and count duplicate edges only once. At each step choose the smallest ready node using JavaScript string comparison. Without cycles return {order:complete execution order,cycle:false}; with any cycle return {order:[],cycle:true}, not a partial order. Self-loops are cycles. An empty graph returns {order:[],cycle:false}. 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"
],
[
[
"a",
"b"
],
[
"b",
"c"
]
]
]Return value
{
"order": [
"a",
"b",
"c"
],
"cycle": false
}Example 2
Function arguments
[
[
"c",
"b",
"a"
],
[]
]Return value
{
"order": [
"a",
"b",
"c"
],
"cycle": false
}Example 3
Function arguments
[
[
"中文",
"日本",
"a"
],
[]
]Return value
{
"order": [
"a",
"中文",
"日本"
],
"cycle": false
}