<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Backtrack on Yu-Cheng's Notes</title><link>https://linkingmon.github.io/blog/tags/backtrack/</link><description>Recent content in Backtrack on Yu-Cheng's Notes</description><generator>Hugo -- 0.166.0</generator><language>en-us</language><lastBuildDate>Sun, 04 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://linkingmon.github.io/blog/tags/backtrack/index.xml" rel="self" type="application/rss+xml"/><item><title>LC 3799 - Word Squares II</title><link>https://linkingmon.github.io/blog/coding/lc-3799/</link><pubDate>Sun, 04 Jan 2026 00:00:00 +0000</pubDate><guid>https://linkingmon.github.io/blog/coding/lc-3799/</guid><description>&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;This is like a backtracking problem, and we find that the size of the &lt;code&gt;words&lt;/code&gt; is not large, so this should be the solution.&lt;/p&gt;
&lt;p&gt;We simply just try all the permutations in &lt;code&gt;words[idx:end]&lt;/code&gt; (handling in &lt;code&gt;traverse()&lt;/code&gt; function).
This is done by swapping &lt;code&gt;idx&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; (from &lt;code&gt;idx&lt;/code&gt; to &lt;code&gt;end&lt;/code&gt;), and then call &lt;code&gt;traverse()&lt;/code&gt; recursively.
We can swap the &lt;code&gt;idx&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; back after the recursive call, in this case we can reuse the &lt;code&gt;words&lt;/code&gt; order, and don’t need extra cache for the original &lt;code&gt;words&lt;/code&gt; value (this method is commonly used in a backtracking problem).&lt;/p&gt;</description></item></channel></rss>