Pearl No. 4 – Kth Smallest in the Union of Two Sorted Collections
typeocaml.com
typeocaml.com
I am very keen to OCaml and so using OCaml to solve various algorithm problems to have some fun.
But yeah, if they are arrays, you use binary search. Not obvious, but also straightforward if you are looking to beat O(k).
https://leetcode.com/problems/median-of-two-sorted-arrays/de...
Ordered collection != sorted collection, btw. Sorted collections are actually more like sets than like arrays. A data structure that stores the elements in a sorted fashion is actually able to store an unordered collection with naturally defined insertion / deletion operations. (In OCaml, Set data structure is represented as a balanced binary tree, for instance, and it requires an order relation defined for its elements.)
Will change
The title is so close to presenting the problem on a way that people could fully consider how they'd handle the problem before following the link. Just add "disjoint" to the title.