Introduction
The problem we will be heading towards is based on a Sorting algorithm that will be solved using some Data Structure. A set of elements can be arranged in increasing and decreasing order using either the inbuilt functions or the various sorting techniques depending on the question need and the constraints.
Let’s move to our problem statement to get an idea and approach it.
Also see, Array Implementation of Queue and Rabin Karp Algorithm
Problem Statement
In this problem, we will be given two integer arrays along with an integer. Each array will contain the range, and our task is to calculate the Nth number When numbers from given ranges are sorted.
Example:
Input: Left{1,4} , Right{3,5}, N=4
Output: 5
Explanation:
The numbers present in the range of both the arrays and in the sorted array will be {1,2,3,4,5} and therefore, the 4th element is ‘5’.
Basically here in the left array, Left[0] is the starting number and Right[0] is the ending number for the sorted array along with Left[1] is the starting number and Right[1] is the ending number. I.e. the merged sorted array will be [Left[0]---Left[1],Right[0]---Right[1]]
Example:
Input: Left{1,4} , Right{4,5}, N=3
Output: 4
Explanation:
The numbers present in the range of both the arrays and in the sorted array will be {1,2,3,4,4,5} and therefore, the 3rd element is ‘4’.




