Posts

Showing posts from March 17, 2019

K’th SmallestElement in Unsorted Array in python

Image
4 $begingroup$ I was solving this sorting problem, and I was wondering if I can get any code review and feedback. You can find this problem online. # Find Kth Smallest Element in a Range # # Prompt: Given an unsorted array of whole integers in the range # 1000 to 9000, find the Kth smallest element in linear time # The array can have duplicates. # # Input: Unsorted array of whole integers in range of 1000 to 9000 # Kth smallest element you want to find # # Output: Kth smalest element in the range # # Example: array = [1984, 1337, 9000, 8304, 5150, 9000, 8304], k=5 # output = 8304 # # Notes: What are the time and auxilliary space complexity? # Time Complexity: O(N) # Auxiliary Space Complexity: O(N) def kthSmallest(lst, k):...