HardPro challengeJavaScriptTypeScript

useTransition Simulation

ReactConcurrentScheduling

Simulate useTransition priority queue. Updates marked isUrgent: true
preempt non-urgent ones.

solve(updates) processes updates in priority order:
1. All urgent updates first (in arrival order).
2. Then non-urgent ones (in arrival order).

Returns the commit order.

Sample tests

Test #1Urgent first
Input: [[{"id":"a","isUrgent":false},{"id":"b","isUrgent":true}]]
Output: ["b","a"]
Test #2All urgent in order
Input: [[{"id":"x","isUrgent":true},{"id":"y","isUrgent":true}]]
Output: ["x","y"]
Test #3No urgent
Input: [[{"id":"p","isUrgent":false},{"id":"q","isUrgent":false}]]
Output: ["p","q"]
Test #4Empty
Input: [[]]
Output: []
Test #5Interleaved priorities
Input: [[{"id":"a","isUrgent":false},{"id":"b","isUrgent":true},{"id":"c","isUrgent":false},{"id":"d","isUrgent":true}]]
Output: ["b","d","a","c"]