FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
CA 07 - Kth Smallest
NewsProgramming Languages

CA 07 - Kth Smallest

via Dev.to PythonJonah Blessy3h ago

Problem Statement: click here Problem Understanding: We are given an integer array arr[] and an integer k . The task is to return the kth smallest element in the array when arr[] is sorted. Initial Approach: My initial approach was to use the sort() function in Python so sort the array. Then by indexing arr[k-1] we can get the kth smallest element. Example: arr= [10, 5, 4, 3, 48, 6, 2, 33, 53, 10] k = 4 arr.sort() print(arr[k-1]) Sorted array: arr= [2, 3, 4, 5, 6, 10, 10, 33, 48, 53] Output: 5 Brute force approach: Without using the in-built sort() function, we can achieve the same solution by: arr = [ 7 , 10 , 4 , 3 , 20 , 15 ] k = 3 for i in range ( k ): # for looping until smallest element k-1 min_val = arr [ 0 ] # assume first element is smallest min_index = 0 # since we assumed the first element for j in range ( len ( arr )): if arr [ j ] < min_val : min_val = arr [ j ] min_index = j arr . pop ( min_index ) # remove the smallest element print ( min_val ) In this approach, we first

Continue reading on Dev.to Python

Opens in a new tab

Read Full Article
2 views

Related Articles

Mexico City's 'Xoli' Chatbot Will Help World Cup Tourists Navigate the City
News

Mexico City's 'Xoli' Chatbot Will Help World Cup Tourists Navigate the City

Wired • 3h ago

News

Mechanics vs Understanding

Medium Programming • 5h ago

Flames of Desire
News

Flames of Desire

Medium Programming • 7h ago

The Night I Ran Out of Tokens
News

The Night I Ran Out of Tokens

Medium Programming • 7h ago

News

Why Judge Calibration Matters: Sonnet vs Opus — a Case Study

Medium Programming • 8h ago

Discover More Articles