Find K Closest Elements

Medium

📝 Description

Find k closest elements to target in sorted array

Input Format

First line: space-separated sorted array Second line: k and x (target)

Output Format

k closest elements

Constraints

1 ≤ k ≤ arr.length ≤ 10^4

🔍 Sample Input

1 2 3 4 5
4 3
            

✅ Sample Output

1 2 3 4
            

Code Editor

Please login to run and submit code.

Shortcuts: Ctrl+Enter to submit, Ctrl+Shift+R to run