Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Tutorial: Find k_th element in an array

Правка en1, от TheBhediyaOfDalalStreet, 2022-08-19 22:11:32

Hello frends, in this blog I teach you how to find k_th element in an array of size n. This blog is going be very advanced so please if you are new to progrmaming stay away.

eg. arr = {1, 3, 2, 9, 5, 6, 11} and k = 2 then programs must return 3

Approach:

Define dp(i, j, k) = number of inversions in the array formed by concatenating prefix arr[0 .. i] and arr[j .. n-1] such that the smaller number in the inversion pair is >= k (0 <= i < j < n)

The transitions is trivial, so I am skipping those.

then the answer can be found by returning the value of arr[k — 1]

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский TheBhediyaOfDalalStreet 2022-09-04 14:17:37 0 (published)
en1 Английский TheBhediyaOfDalalStreet 2022-08-19 22:11:32 634 Initial revision (saved to drafts)