Fetching latest headlines…
Kth Smallest
NORTH AMERICA
πŸ‡ΊπŸ‡Έ United Statesβ€’March 22, 2026

Kth Smallest

0 views0 likes0 comments
Originally published byDev.to

Introduction

Finding the Kth smallest element in an array is a common problem in data structures. It is useful in many real-world applications like ranking and statistics.

Problem Statement

Given an array of integers and a number k, find the Kth smallest element in the array.

Approach 1: Sorting

  1. Sort the array in ascending order
  2. Return the element at index k-1

Python Code (Sorting)


python
def kth_smallest(arr, k):
    arr.sort()
    return arr[k - 1]

# Example
arr = [7, 10, 4, 3, 20, 15]
k = 3
print("Kth Smallest:", kth_smallest(arr, k))


## Input
arr = [7, 10, 4, 3, 20, 15]
k = 3

## output
   7

Comments (0)

Sign in to join the discussion

Be the first to comment!