def _get_grid_uniongrid_elements(merged_grid, grid):
    """
    Get the mapping between a grid and the merged grid

    Parameters
    ----------
    merged_grid : NumPy Array of size [num_merged_elements x 2]
        Merged pseudo-grid, i.e., as obtained with merge_grids()
    grid : NumPy Array of size [num_grid_elements x 2]
        Pseugo grid, i.e.: high_grid, mortar_grid, or low_grid.

    Returns
    -------
    elements : List of length num_merged_elements
        Containing the local elements of the grids overlapping the merged grid,
        at the a interval.

    Credits
    -------
    The follwing piece of code was modified from:
    www.geeksforgeeks.org/find-intersection-of-intervals-given-by-two-lists/
    Author: Sarthak Shukla (Indian Institute of Information Technology Nagpur)
    
    """
    
    
    # First, convert the FEM-like 1D grids to lists
    arr1 = merged_grid.tolist()
    arr2 = grid.tolist()
    
    # Initialize pointers
    i = j = 0

    # Length of lists
    n = len(arr1) 
    m = len(arr2) 
    
    # Elements list
    elements = []
    
    # Loop through all intervals unless one of the interval gets exhausted 
    while i < n and j < m: 
      
        # Left bound for intersecting segment 
        l = max(arr1[i][0], arr2[j][0]) 
          
        # Right bound for intersecting segment 
        r = min(arr1[i][1], arr2[j][1]) 
        
        # If the segment is valid, append the element to the list
        if l < r:
            elements.append(j)
            
        # If i-th interval's right bound is  
        # smaller increment i else increment j 
        if arr1[i][1] < arr2[j][1]: 
            i += 1
        else: 
            j += 1
 
    return elements