<?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>Permutation on Kelly Dev</title><link>https://kelly-chui.github.io/algorithmtags/permutation/</link><description>Recent content in Permutation on Kelly Dev</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 29 Jul 2026 10:36:59 +0900</lastBuildDate><atom:link href="https://kelly-chui.github.io/algorithmtags/permutation/index.xml" rel="self" type="application/rss+xml"/><item><title>LeetCode 3518. Smallest Palindromic Rearrangement II</title><link>https://kelly-chui.github.io/ps/2026/ps-leetcode-3518-smallest-palindromic-rearrangement-ii/</link><pubDate>Wed, 29 Jul 2026 10:36:59 +0900</pubDate><guid>https://kelly-chui.github.io/ps/2026/ps-leetcode-3518-smallest-palindromic-rearrangement-ii/</guid><description>&lt;h2 id="문제"&gt;문제&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://leetcode.com/problems/smallest-palindromic-rearrangement-ii"&gt;https://leetcode.com/problems/smallest-palindromic-rearrangement-ii&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="풀이"&gt;풀이&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://kelly-chui.github.io/ps/2026/ps-leetcode-3517-smallest-palindromic-rearrangement-i/"&gt;1번 문제&lt;/a&gt;와 마찬가지로 팰린드롬의 성질상 절반만 결정하면 전체가 결정된다. 따라서 이 문제는 절반 문자열의 &lt;code&gt;k&lt;/code&gt;번째 사전순 순열을 구하는 문제로 단순화된다.&lt;/p&gt;
&lt;p&gt;각 문자의 등장 횟수를 세고, 홀수 번 등장하는 문자는 팰린드롬의 가운데에 배치한다. 나머지는 2로 나눠 &lt;code&gt;halfTable&lt;/code&gt;을 만든다. 절반 문자열에는 중복 문자가 있을 수 있으므로, 전체 순열 수는 단순히 $n!$이 아니라 중복 순열 공식으로 구해야 한다.&lt;/p&gt;
&lt;p&gt;$$\frac{n!}{\prod_{i} n_i!}$$&lt;/p&gt;
&lt;p&gt;여기서 &lt;code&gt;n&lt;/code&gt;은 절반 문자열의 길이, &lt;code&gt;n_i&lt;/code&gt;는 각 문자의 개수이다. 이 값이 &lt;code&gt;k&lt;/code&gt;보다 작으면 &lt;code&gt;k&lt;/code&gt;번째 순열이 존재하지 않으므로 빈 문자열을 반환한다.&lt;/p&gt;</description></item></channel></rss>