<?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>increasing Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/increasing/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/increasing/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Dec 2018 07:18:41 +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>increasing Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/increasing/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 960. Delete Columns to Make Sorted III</title>
		<link>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-960-delete-columns-to-make-sorted-iii/</link>
					<comments>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-960-delete-columns-to-make-sorted-iii/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Thu, 20 Dec 2018 05:49:15 +0000</pubDate>
				<category><![CDATA[Dynamic Programming]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[hard]]></category>
		<category><![CDATA[increasing]]></category>
		<category><![CDATA[subsequence]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4505</guid>

					<description><![CDATA[<p>We are given an array&#160;A&#160;of&#160;N&#160;lowercase letter strings, all of the same length. Now, we may choose any set of deletion indices, and for each string,&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-960-delete-columns-to-make-sorted-iii/">花花酱 LeetCode 960. Delete Columns to Make Sorted III</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>We are given an array&nbsp;<code>A</code>&nbsp;of&nbsp;<code>N</code>&nbsp;lowercase letter strings, all of the same length.</p>



<p>Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.</p>



<p>For example, if we have an array&nbsp;<code>A = ["babca","bbazb"]</code>&nbsp;and deletion indices&nbsp;<code>{0, 1, 4}</code>, then the final array after deletions is&nbsp;<code>["bc","az"]</code>.</p>



<p>Suppose we chose a set of deletion indices&nbsp;<code>D</code>&nbsp;such that after deletions, the final array has&nbsp;<strong>every element (row) in&nbsp;lexicographic</strong>&nbsp;order.</p>



<p>For clarity,&nbsp;<code>A[0]</code>&nbsp;is in lexicographic order (ie.&nbsp;<code>A[0][0] &lt;= A[0][1] &lt;= ... &lt;= A[0][A[0].length - 1]</code>),&nbsp;<code>A[1]</code>&nbsp;is in lexicographic order (ie.&nbsp;<code>A[1][0] &lt;= A[1][1] &lt;= ... &lt;= A[1][A[1].length - 1]</code>), and so on.</p>



<p>Return the minimum possible value of&nbsp;<code>D.length</code>.</p>



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



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>["babca","bbazb"]
<strong>Output: </strong>3
<strong>Explanation: </strong>After deleting columns 0, 1, and 4, the final array is A = ["bc", "az"].
Both these rows are individually in lexicographic order (ie. A[0][0] &lt;= A[0][1] and A[1][0] &lt;= A[1][1]).
Note that A[0] &gt; A[1] - the array A isn't necessarily in lexicographic order.
</pre>



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



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>["edcba"]
<strong>Output: </strong>4
<strong>Explanation: </strong>If we delete less than 4 columns, the only row won't be lexicographically sorted.
</pre>



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



<pre class="wp-block-preformatted crayon:false"><strong>Input: </strong>["ghi","def","abc"]
<strong>Output: </strong>0
<strong>Explanation: </strong>All rows are already lexicographically sorted.
</pre>



<p><strong>Note:</strong></p>



<ol><li><code>1 &lt;= A.length &lt;= 100</code></li><li><code>1 &lt;= A[i].length &lt;= 100</code></li></ol>



<h1><strong>Solution: DP</strong></h1>



<p>dp[i] := max length of increasing sub-sequence (of all strings) ends with i-th letter.<br>dp[i] = max(dp[j] + 1) if all A[*][j] &lt;= A[*][i], j &lt; i<br>Time complexity: (n*L^2)<br>Space complexity: O(L)</p>



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


<pre class="crayon-plain-tag">// Author: Huahua, running time: 24 ms
class Solution {
public:
  int minDeletionSize(vector&lt;string&gt;&amp; A) {
    vector&lt;int&gt; dp(A[0].length(), 1);
    for (int i = 0; i &lt; A[0].length(); ++i)
      for (int j = 0; j &lt; i; ++j) {
        bool valid = true;
        for (const auto&amp; a : A)
          if (a[j] &gt; a[i]) {
            valid = false;
            break;
          }
        if (valid) dp[i] = max(dp[i], dp[j] + 1);
      }
    return A[0].length() - *max_element(begin(dp), end(dp));
  }
};</pre>


</div><h2 class="tabtitle">Python3</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 176 ms
class Solution:
  def minDeletionSize(self, A):
    n = len(A[0])
    dp = [1] * n
    for i in range(1, n):
      for j in range(i):
        valid = True
        for a in A:
          if a[j] &gt; a[i]: 
            valid = False
            break
        if valid:
          dp[i] = max(dp[i], dp[j] + 1)
    return n - max(dp)</pre>

</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-960-delete-columns-to-make-sorted-iii/">花花酱 LeetCode 960. Delete Columns to Make Sorted III</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-960-delete-columns-to-make-sorted-iii/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 491. Increasing Subsequences</title>
		<link>https://zxi.mytechroad.com/blog/searching/leetcode-491-increasing-subsequences/</link>
					<comments>https://zxi.mytechroad.com/blog/searching/leetcode-491-increasing-subsequences/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Wed, 18 Jul 2018 04:19:36 +0000</pubDate>
				<category><![CDATA[Search]]></category>
		<category><![CDATA[combination]]></category>
		<category><![CDATA[DFS]]></category>
		<category><![CDATA[increasing]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[subsequence]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=3207</guid>

					<description><![CDATA[<p>Problem Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/searching/leetcode-491-increasing-subsequences/">花花酱 LeetCode 491. Increasing Subsequences</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="question-description__3U1T">
<div>
<h2><strong>Problem</strong></h2>
<p>Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 .</p>
<p><b>Example:</b></p>
<pre class="crayon:false "><b>Input:</b> [4, 6, 7, 7]
<b>Output:</b> [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7, 7], [6, 7], [6, 7, 7], [7,7], [4,7,7]]
</pre>
<p><b>Note:</b></p>
<ol>
<li>The length of the given array will not exceed 15.</li>
<li>The range of integer in the given array is [-100,100].</li>
<li>The given array may contain duplicates, and two equal integers should also be considered as a special case of increasing sequence.</li>
</ol>
</div>
</div>
<h1><strong>Solution: DFS</strong></h1>
<p>Time complexity: O(2^n)</p>
<p>Space complexity: O(n)</p>
<p>C++</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 140 ms (&lt;99.88%)
class Solution {
public:
  vector&lt;vector&lt;int&gt;&gt; findSubsequences(vector&lt;int&gt;&amp; nums) {
    vector&lt;vector&lt;int&gt;&gt; ans;
    vector&lt;int&gt; cur;
    dfs(nums, 0, cur, ans);
    return ans;
  }
private:
  void dfs(const vector&lt;int&gt;&amp; nums, int s, vector&lt;int&gt;&amp; cur, vector&lt;vector&lt;int&gt;&gt;&amp; ans) {    
    unordered_set&lt;int&gt; seen;
    for (int i = s; i &lt; nums.size(); ++i) {
      if (!cur.empty() &amp;&amp; nums[i] &lt; cur.back()) continue;
      // each number can be used only once at the same depth.
      if (seen.count(nums[i])) continue; 
      seen.insert(nums[i]);
      cur.push_back(nums[i]);
      if (cur.size() &gt; 1) 
        ans.push_back(cur);
      dfs(nums, i + 1, cur, ans);
      cur.pop_back();
    }
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/searching/leetcode-491-increasing-subsequences/">花花酱 LeetCode 491. Increasing Subsequences</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/searching/leetcode-491-increasing-subsequences/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode 334. Increasing Triplet Subsequence</title>
		<link>https://zxi.mytechroad.com/blog/greedy/leetcode-334-increasing-triplet-subsequence/</link>
					<comments>https://zxi.mytechroad.com/blog/greedy/leetcode-334-increasing-triplet-subsequence/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Tue, 29 May 2018 00:09:10 +0000</pubDate>
				<category><![CDATA[Greedy]]></category>
		<category><![CDATA[increasing]]></category>
		<category><![CDATA[subsequence]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=2868</guid>

					<description><![CDATA[<p>Problem 题目大意：判断一个数组中是否存在长度为3的单调递增子序列。 Formally the function should: Return true if there exists i, j, k  such that arr[i] &#60; arr[j] &#60; arr[k] given 0 ≤ i &#60; j &#60; k ≤ n-1 else return false. Your algorithm should run in&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/greedy/leetcode-334-increasing-triplet-subsequence/">花花酱 LeetCode 334. Increasing Triplet Subsequence</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1>Problem</h1>
<p>题目大意：判断一个数组中是否存在长度为3的单调递增子序列。</p>
<p>Formally the function should:</p>
<blockquote><p>Return true if there exists <i>i, j, k </i><br />
such that <i>arr[i]</i> &lt; <i>arr[j]</i> &lt; <i>arr[k]</i> given 0 ≤ <i>i</i> &lt; <i>j</i> &lt; <i>k</i> ≤ <i>n</i>-1 else return false.</p></blockquote>
<p>Your algorithm should run in O(<i>n</i>) time complexity and O(<i>1</i>) space complexity.</p>
<p><b>Examples:</b><br />
Given <code>[1, 2, 3, 4, 5]</code>,<br />
return <code>true</code>.</p>
<p>Given <code>[5, 4, 3, 2, 1]</code>,<br />
return <code>false</code>.</p>
<p><b>Credits:</b><br />
Special thanks to <a href="https://leetcode.com/discuss/user/DjangoUnchained">@DjangoUnchained</a> for adding this problem and creating all test cases.</p>
<h1><img class="alignnone size-full wp-image-2871" src="http://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/334-ep193.png" alt="" width="960" height="540" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/334-ep193.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/334-ep193-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/05/334-ep193-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></h1>
<h1><strong>Solution: Greedy</strong></h1>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(1)</p>
<p>C++</p><pre class="crayon-plain-tag">// Author: Huahua
// Running time: 7 ms
class Solution {
public:
  bool increasingTriplet(vector&lt;int&gt;&amp; nums) {
    int min1 = INT_MAX;
    int min2 = INT_MAX;
    for (int num : nums) {
      if (num &gt; min2) return true;
      else if (num &lt; min1) {
        min1 = num;
      } else if (num &gt; min1 &amp;&amp; num &lt; min2) {
        min2 = num;
      }
    }
    return false;
  }
};</pre><p>&nbsp;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/greedy/leetcode-334-increasing-triplet-subsequence/">花花酱 LeetCode 334. Increasing Triplet Subsequence</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/greedy/leetcode-334-increasing-triplet-subsequence/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
