<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zip Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/zip/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/zip/</link>
	<description></description>
	<lastBuildDate>Mon, 26 Sep 2022 16:57:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>zip Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/zip/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2418. Sort the People</title>
		<link>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2418-sort-the-people/</link>
					<comments>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2418-sort-the-people/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 26 Sep 2022 16:57:17 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[zip]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=9842</guid>

					<description><![CDATA[<p>You are given an array of strings&#160;names, and an array&#160;heights&#160;that consists of&#160;distinct&#160;positive integers. Both arrays are of length&#160;n. For each index&#160;i,&#160;names[i]&#160;and&#160;heights[i]&#160;denote the name and height&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2418-sort-the-people/">花花酱 LeetCode 2418. Sort the People</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You are given an array of strings&nbsp;<code>names</code>, and an array&nbsp;<code>heights</code>&nbsp;that consists of&nbsp;<strong>distinct</strong>&nbsp;positive integers. Both arrays are of length&nbsp;<code>n</code>.</p>



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



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



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> names = ["Mary","John","Emma"], heights = [180,165,170]
<strong>Output:</strong> ["Mary","Emma","John"]
<strong>Explanation:</strong> Mary is the tallest, followed by Emma and John.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> names = ["Alice","Bob","Bob"], heights = [155,185,150]
<strong>Output:</strong> ["Bob","Alice","Bob"]
<strong>Explanation:</strong> The first Bob is the tallest, followed by Alice and the second Bob.
</pre>



<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>&nbsp;consists of lower and upper case English letters.</li><li>All the values of&nbsp;<code>heights</code>&nbsp;are distinct.</li></ul>



<p>Solution: Zip and sort</p>



<p>Time complexity: O(nlogn)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;string&gt; sortPeople(vector&lt;string&gt;&amp; names, vector&lt;int&gt;&amp; heights) {
    vector&lt;pair&lt;int, string*&gt;&gt; data;
    for (int i = 0; i &lt; names.size(); ++i)
      data.emplace_back(heights[i], &amp;names[i]);    
    sort(rbegin(data), rend(data));
    vector&lt;string&gt; ans(names.size());
    for (int i = 0; i &lt; names.size(); ++i)
      ans[i].swap(*data[i].second);
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2418-sort-the-people/">花花酱 LeetCode 2418. Sort the People</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/algorithms/array/leetcode-2418-sort-the-people/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
