AI Native 分级编程挑战

第3级 · 进阶 · 结构与效率

计算滑动窗口中位数

维护奇数和偶数窗口的中位数。

题目说明

编写 function solution(values, windowSize)。输入输出均为 JSON 值,不要修改输入数组或对象。不支持外部库、网络访问及异步函数。 values:integer[] (-10^6…10^6), windowSize:integer 1–1024. Return the median of every consecutive full window in input order. For odd windows use the middle sorted value; for even windows average the two middle values. If fewer values than the window size, return []. Do not mutate input. 输入范围:每个输入数组最多50,000项,每个字符串最多1,000个字符。数字必须有限,整数及整数累计结果在JavaScript安全整数范围内。其他类型和有效性遵循上述规则。

输入输出示例

示例 1

函数参数

[
  [
    1,
    3,
    2,
    5,
    4
  ],
  3
]

返回值

[
  2,
  3,
  4
]
示例 2

函数参数

[
  [
    1,
    2,
    3,
    4
  ],
  2
]

返回值

[
  1.5,
  2.5,
  3.5
]
示例 3

函数参数

[
  [
    0,
    0,
    -1,
    1
  ],
  2
]

返回值

[
  0,
  -0.5,
  0
]
Practice has no points, deadline or submission cap. Use AI and search freely. Sign in to run public examples, or verify locally.

69 / 20,000字符

Add your test · optional

Enter a JSON argument array in values, windowSize order. Your test runs alongside the three examples.

Save both files in one folder and run this command with Node.js. Read the checks field for individual example results.

node verify-rolling-median.mjs
문의하기

서비스명: 포트포올
문의는 운영자에게 이메일로 전송됩니다.

이메일과 문의 내용은 답변을 위해 운영자 및 메일 발송 서비스로 전송됩니다. 비밀번호·결제정보·민감한 개인정보는 입력하지 마세요.