<p>You are given an array of strings <code>names</code>, and an array <code>heights</code> that consists of <strong>distinct</strong> positive integers. Both arrays are of length <code>n</code>.</p>

<p>For each index <code>i</code>, <code>names[i]</code> and <code>heights[i]</code> denote the name and height of the <code>i<sup>th</sup></code> person.</p>

<p>Return <code>names</code><em> sorted in <strong>descending</strong> order by the people&#39;s heights</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> names = [&quot;Mary&quot;,&quot;John&quot;,&quot;Emma&quot;], heights = [180,165,170]
<strong>Output:</strong> [&quot;Mary&quot;,&quot;Emma&quot;,&quot;John&quot;]
<strong>Explanation:</strong> Mary is the tallest, followed by Emma and John.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> names = [&quot;Alice&quot;,&quot;Bob&quot;,&quot;Bob&quot;], heights = [155,185,150]
<strong>Output:</strong> [&quot;Bob&quot;,&quot;Alice&quot;,&quot;Bob&quot;]
<strong>Explanation:</strong> The first Bob is the tallest, followed by Alice and the second Bob.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == names.length == heights.length</code></li>
	<li><code>1 &lt;= n &lt;= 10<sup>3</sup></code></li>
	<li><code>1 &lt;= names[i].length &lt;= 20</code></li>
	<li><code>1 &lt;= heights[i] &lt;= 10<sup>5</sup></code></li>
	<li><code>names[i]</code> consists of lower and upper case English letters.</li>
	<li>All the values of <code>heights</code> are distinct.</li>
</ul>

class Solution:

    def mergeSort(self, array, dependent, p, r):
        # assumes a list of typles of (height, name)
        if (r > p):
            q = (p + r) // 2
            self.mergeSort(array, dependent, p, q)
            self.mergeSort(array, dependent, q + 1, r)
            self.merge(array, dependent, p, q, r)

    def merge(self, array, dependent, p, q, r):

        low_half = array[p:q + 1]
        high_half = array[q + 1:r + 1]

        low_half_dep = dependent[p:q + 1]
        high_half_dep = dependent[q + 1:r + 1]
        
        i = j = 0
        k = p
                
        # print(high_half)
        while (i < len(low_half)) and (j < len(high_half)):
            if low_half[i] > high_half[j]:
                array[k] = low_half[i]
                dependent[k] = low_half_dep[i]
                i += 1
            else:
                array[k] = high_half[j]
                dependent[k] = high_half_dep[j]
                j += 1
            k += 1

        while (i < len(low_half)):
            # print("here")
            array[k] = low_half[i]
            dependent[k] = low_half_dep[i]
            i += 1
            k += 1

        while (j < len(high_half)):
            # print("there")
            array[k] = high_half[j]
            dependent[k] = high_half_dep[j]
            j += 1
            k += 1
        # print(dependent, array)

    def sortPeople(self, names: List[str], heights: List[int]) -> List[str]:

        self.mergeSort(heights, names, 0, len(heights) - 1)
       
        return names

135