<?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>rank Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/rank/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/rank/</link>
	<description></description>
	<lastBuildDate>Mon, 02 Mar 2020 08:36:51 +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>rank Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/rank/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1366. Rank Teams by Votes</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-1366-rank-teams-by-votes/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-1366-rank-teams-by-votes/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 02 Mar 2020 08:31:51 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[rank]]></category>
		<category><![CDATA[simulation]]></category>
		<category><![CDATA[sorting]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6392</guid>

					<description><![CDATA[<p>In a special ranking system,&#160;each voter gives a rank from highest to lowest to all teams participated in the competition. The ordering of teams is&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1366-rank-teams-by-votes/">花花酱 LeetCode 1366. Rank Teams by Votes</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>In a special ranking system,&nbsp;each voter gives a rank from highest to lowest to all teams participated in the competition.</p>



<p>The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we consider the second position to resolve the conflict, if they tie again, we continue this process until the ties are resolved. If two or more teams are still tied after considering all positions, we rank them alphabetically based on their team letter.</p>



<p>Given an array of strings&nbsp;<code>votes</code>&nbsp;which is the votes of all voters in the ranking systems. Sort all teams according to the ranking system described above.</p>



<p>Return&nbsp;<em>a string of all teams</em>&nbsp;<strong>sorted</strong>&nbsp;by the ranking system.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> votes = ["ABC","ACB","ABC","ACB","ACB"]
<strong>Output:</strong> "ACB"
<strong>Explanation:</strong> Team A was ranked first place by 5 voters. No other team was voted as first place so team A is the first team.
Team B was ranked second by 2 voters and was ranked third by 3 voters.
Team C was ranked second by 3 voters and was ranked third by 2 voters.
As most of the voters ranked C second, team C is the second team and team B is the third.
</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> votes = ["WXYZ","XYZW"]
<strong>Output:</strong> "XWYZ"
<strong>Explanation:</strong> X is the winner due to tie-breaking rule. X has same votes as W for the first position but X has one vote as second position while W doesn't have any votes as second position. 
</pre>



<p><strong>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> votes = ["ZMNAGUEDSJYLBOPHRQICWFXTVK"]
<strong>Output:</strong> "ZMNAGUEDSJYLBOPHRQICWFXTVK"
<strong>Explanation:</strong> Only one voter so his votes are used for the ranking.
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> votes = ["BCA","CAB","CBA","ABC","ACB","BAC"]
<strong>Output:</strong> "ABC"
<strong>Explanation:</strong> 
Team A was ranked first by 2 voters, second by 2 voters and third by 2 voters.
Team B was ranked first by 2 voters, second by 2 voters and third by 2 voters.
Team C was ranked first by 2 voters, second by 2 voters and third by 2 voters.
There is a tie and we rank teams ascending by their IDs.
</pre>



<p><strong>Example 5:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> votes = ["M","M","M","M"]
<strong>Output:</strong> "M"
<strong>Explanation:</strong> Only team M in the competition so it has the first rank.
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= votes.length &lt;= 1000</code></li><li><code>1 &lt;= votes[i].length &lt;= 26</code></li><li><code>votes[i].length ==&nbsp;votes[j].length</code>&nbsp;for&nbsp;<code>0 &lt;= i, j &lt; votes.length</code>.</li><li><code>votes[i][j]</code>&nbsp;is an English&nbsp;<strong>upper-case</strong>&nbsp;letter.</li><li>All characters of&nbsp;<code>votes[i]</code>&nbsp;are unique.</li><li>All the characters&nbsp;that occur&nbsp;in&nbsp;<code>votes[0]</code>&nbsp;<strong>also&nbsp;occur</strong>&nbsp;in&nbsp;<code>votes[j]</code>&nbsp;where&nbsp;<code>1 &lt;= j &lt; votes.length</code>.</li></ul>



<h2><strong>Solution: Sort by rank</strong></h2>



<p>Time complexity: O(v*n + n^2*logn)<br>Space complexity: O(n*n)</p>



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  string rankTeams(vector&lt;string&gt;&amp; votes) {
    const int n = votes[0].length();
    string ans(votes[0]);
    vector&lt;vector&lt;int&gt;&gt; rank(26, vector&lt;int&gt;(n));
    
    for (const auto&amp; vote : votes)
      for (int i = 0; i &lt; n; ++i)
        ++rank[vote[i] - 'A'][i];
    
    sort(begin(ans), end(ans), [&amp;](const char i, const char j) {
      if (rank[i - 'A'] != rank[j - 'A']) return rank[i - 'A'] &gt; rank[j - 'A'];
      return i &lt; j;
    });    
    return ans;
  }
};</pre>
</div></div>



<p></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-1366-rank-teams-by-votes/">花花酱 LeetCode 1366. Rank Teams by Votes</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/simulation/leetcode-1366-rank-teams-by-votes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>LeetCode Weekly Contest 113</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 02 Dec 2018 03:47:20 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[rank]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4389</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/">LeetCode Weekly Contest 113</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><img class="alignnone size-large wp-image-4390" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-1024x627.png" alt="" width="1024" height="627" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-1024x627.png 1024w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-300x184.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-768x470.png 768w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest.png 1435w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/">LeetCode Weekly Contest 113</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/leetcode/leetcode-weekly-contest-113/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
