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

Your time is important!

Yocto Project: more than a build system

Next ’20 OnAir is back!

CS373 Spring 2022: Luca Santos

ICM Week5 Ball

Rust’s String vs str

Setup LDAP with AutoFS on a Synology NAS.

Active Directory Backup Best Practices

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

Interview Preparation —DSA day 5

Leetcode Solutions — 2Sums

Maximum Points You Can Obtain from Cards — LeetCode

Dynamic Programming