← Back to all problems
Medium

Find K Closest Elements

Updated Feb 24, 2026

Problem

Return k closest elements to x in ascending order.

Constraints

1 <= k <= arr.length <= 10^4

Examples

Example 1

Input: {"arr": [1, 2, 3, 4, 5], "k": 4, "x": 3}
Output: [1, 2, 3, 4]

Function Signature

def findClosestElements(self, arr: list[int], k: int, x: int) -> list[int]

How to Submit

Implement a Solution class with a findClosestElements method.

Your method will be called with the input parameters and should return the answer.