K-th Smallest Prime Fraction Problem

Problem You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k. For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i] / arr[j]. Return the kth smallest fraction considered. Return your answer as an array of integers of size 2, where answer[0] == arr[i] and answer[1] == arr[j]. ...

Kth Largest Element in an Array

Problem Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 1: Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Example 2: Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 ...

Kth Smallest Element Using Randomized Selection

Problem Input - array A with n distinct numbers and a number i ∈ {1, 2, …, n} Output : ith order statistic i.e. ith smallest element of the input array Solution We have already seen multiple solutions here - Kth OR Nth Smallest Element in an Array. Here will focus on Linear time or O(n) solution. Finding the ith smallest element may seem difficult at first, but is it possible to find some O(n) or linear time solution. ...

Kth largest element in Binary Search Tree

Problem Given a Binary Search Tree (BST) and a positive integer k, find the k’th largest element in the Binary Search Tree. Examples Example 1: Input: 2 / \ 1 3 and k = 2 Return : 2 As 2 is the second smallest element in the tree. ...

Top K Frequent Words Problem

Problem Given a document (or stream) of words. Find the top k most frequent words in the document (or stream). OR Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order. Examples Example 1: Input: words = ["i","love","leetcode","i","love","coding"], k = 2 Output: ["i","love"] Explanation: "i" and "love" are the two most frequent words. Note that "i" comes before "love" due to a lower alphabetical order. ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy