K-th Element of 2 Sorted Array — Asked in Flipkart and Microsoft Interview

Problem Statement :

You are given two sorted arrays/list ‘arr1’ and ‘arr2’ and an integer k. You create a new sorted array by merging all the elements from ‘arr1’ and ‘arr2’. Your task is to find the kth smallest element of the merged array.

Sample Input:

arr1 = [2,3,45]arr2 = [4,6,7,8]k = 4

Sample Output:

6

Explanation of Sample Test Case:

The merged array will be : [2,3,4,6,7,8,45]

The fourth element of this array will be 6 hence we return 6.

Approach :

Time Complexity : O(log k)
Space Complexity : O(1)

Code :

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Teachmitra | From google form to a humble start

How To Trade $LUNA

Let’s break some code!

Photo by <a href=”https://unsplash.com/@hvranic?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Ivan Vranić</a> on <a href=”https://unsplash.com/s/photos/broken?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Mutate This! Or Not… A Tale of Python Objects

GitOps and Security

Reducing Memory Footprint and OOM Terminations in iOS.

[Leetcode] Jump Game

3 Beliefs I Abandoned After 3 Years of Professional Coding

Code on a laptop

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Fastest Horses

Linked List — Circular

Interview Preparation Series

LeetCode 146. LRU Cache