{"ScriptPreparationCode":"var data = Array.from({length: 10000}).map(() =\u003E Math.random() * 100);","TestCases":[{"Name":"1","Code":"const sort = (arr) =\u003E {\r\n return [...arr].sort((a, b) =\u003E a - b);\r\n};\r\nconst median = (arr) =\u003E {\r\n const sorted = sort(arr);\r\n const mid = (arr.length / 2) | 0;\r\n return sorted.length % 2 === 0\r\n ? (sorted[mid - 1] \u002B sorted[mid]) / 2\r\n : sorted[mid];\r\n};\r\n\r\nconst res = median(data);\r\n","IsDeferred":false},{"Name":"2","Code":"function swap(arr, i, j) {\r\n const temp = arr[i];\r\n arr[i] = arr[j];\r\n arr[j] = temp;\r\n}\r\n\r\nfunction median(arr) {\r\n const n = arr.length;\r\n function quickSelectInternal(arr, low, high, k) {\r\n while (true) {\r\n if (high \u003C= low) {\r\n return arr[k];\r\n }\r\n\r\n if (high === low \u002B 1) {\r\n if (arr[low] \u003E arr[high]) {\r\n swap(arr, low, high);\r\n }\r\n return arr[k];\r\n }\r\n\r\n let middle = Math.floor((low \u002B high) / 2);\r\n\r\n if (arr[middle] \u003E arr[high]) swap(arr, middle, high);\r\n if (arr[low] \u003E arr[high]) swap(arr, low, high);\r\n if (arr[middle] \u003E arr[low]) swap(arr, middle, low);\r\n\r\n swap(arr, middle, low \u002B 1);\r\n\r\n let ll = low \u002B 1;\r\n let hh = high;\r\n\r\n while (true) {\r\n do ll\u002B\u002B;\r\n while (arr[ll] \u003C arr[low]);\r\n do hh--;\r\n while (arr[hh] \u003E arr[low]);\r\n\r\n if (hh \u003C ll) break;\r\n\r\n swap(arr, ll, hh);\r\n }\r\n\r\n swap(arr, low, hh);\r\n\r\n if (hh \u003C= k) low = ll;\r\n if (hh \u003E= k) high = hh - 1;\r\n }\r\n }\r\n\r\n const mid = Math.floor((n - 1) / 2);\r\n\r\n if (n % 2 === 1) {\r\n return quickSelectInternal(arr, 0, n - 1, mid);\r\n } else {\r\n const leftMid = quickSelectInternal(arr, 0, n - 1, mid);\r\n const rightMid = quickSelectInternal(arr, 0, n - 1, mid \u002B 1);\r\n return (leftMid \u002B rightMid) / 2;\r\n }\r\n}\r\n\r\nconst res = median(data);\r\n","IsDeferred":false}]}