<?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>submatrix Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/submatrix/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/submatrix/</link>
	<description></description>
	<lastBuildDate>Sun, 24 Jan 2021 06:27:04 +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>submatrix Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/submatrix/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1738. Find Kth Largest XOR Coordinate Value</title>
		<link>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-1738-find-kth-largest-xor-coordinate-value/</link>
					<comments>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-1738-find-kth-largest-xor-coordinate-value/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 24 Jan 2021 06:23:11 +0000</pubDate>
				<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[k-th]]></category>
		<category><![CDATA[submatrix]]></category>
		<category><![CDATA[xor]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8029</guid>

					<description><![CDATA[<p>You are given a 2D&#160;matrix&#160;of size&#160;m x n, consisting of non-negative integers. You are also given an integer&#160;k. The&#160;value&#160;of coordinate&#160;(a, b)&#160;of the matrix is the&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-1738-find-kth-largest-xor-coordinate-value/">花花酱 LeetCode 1738. Find Kth Largest XOR Coordinate Value</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 a 2D&nbsp;<code>matrix</code>&nbsp;of size&nbsp;<code>m x n</code>, consisting of non-negative integers. You are also given an integer&nbsp;<code>k</code>.</p>



<p>The&nbsp;<strong>value</strong>&nbsp;of coordinate&nbsp;<code>(a, b)</code>&nbsp;of the matrix is the XOR of all&nbsp;<code>matrix[i][j]</code>&nbsp;where&nbsp;<code>0 &lt;= i &lt;= a &lt; m</code>&nbsp;and&nbsp;<code>0 &lt;= j &lt;= b &lt; n</code>&nbsp;<strong>(0-indexed)</strong>.</p>



<p>Find the&nbsp;<code>k<sup>th</sup></code>&nbsp;largest value&nbsp;<strong>(1-indexed)</strong>&nbsp;of all the coordinates of&nbsp;<code>matrix</code>.</p>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> matrix = [[5,2],[1,6]], k = 1
<strong>Output:</strong> 7
<strong>Explanation:</strong> The value of coordinate (0,1) is 5 XOR 2 = 7, which is the largest value.</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> matrix = [[5,2],[1,6]], k = 2
<strong>Output:</strong> 5
<strong>Explanation: </strong>The value of coordinate (0,0) is 5 = 5, which is the 2nd largest value.</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> matrix = [[5,2],[1,6]], k = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> The value of coordinate (1,0) is 5 XOR 1 = 4, which is the 3rd largest value.</pre>



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



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> matrix = [[5,2],[1,6]], k = 4
<strong>Output:</strong> 0
<strong>Explanation:</strong> The value of coordinate (1,1) is 5 XOR 2 XOR 1 XOR 6 = 0, which is the 4th largest value.</pre>



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



<ul><li><code>m == matrix.length</code></li><li><code>n == matrix[i].length</code></li><li><code>1 &lt;= m, n &lt;= 1000</code></li><li><code>0 &lt;= matrix[i][j] &lt;= 10<sup>6</sup></code></li><li><code>1 &lt;= k &lt;= m * n</code></li></ul>



<h2><strong>Solution: DP</strong></h2>



<p>Similar to <a href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-304-range-sum-query-2d-immutable/" data-type="post" data-id="348">花花酱 LeetCode 304. Range Sum Query 2D – Immutable</a></p>



<p>xor[i][j] = matrix[i][j] ^ xor[i &#8211; 1][j &#8211; 1] ^ xor[i &#8211; 1][j] ^ xor[i][j- 1]</p>



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



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

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int kthLargestValue(vector&lt;vector&lt;int&gt;&gt;&amp; matrix, int k) {    
    const int m = matrix.size(), n = matrix[0].size();
    vector&lt;int&gt; v;
    for (int i = 0; i &lt; m; ++i)
      for (int j = 0; j &lt; n; ++j)
        v.push_back(matrix[i][j] 
                      ^= (i ? matrix[i - 1][j] : 0) 
                       ^ (j ? matrix[i][j - 1] : 0) 
                       ^ (i * j ? matrix[i - 1][j - 1] : 0));
    nth_element(begin(v), begin(v) + k - 1, end(v), greater&lt;int&gt;());    
    return v[k - 1];
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-1738-find-kth-largest-xor-coordinate-value/">花花酱 LeetCode 1738. Find Kth Largest XOR Coordinate Value</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/dynamic-programming/leetcode-1738-find-kth-largest-xor-coordinate-value/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
