<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Table on Algorithm Solutions</title><link>https://algorithm.liangqin.ren/tags/table/</link><description>Recent content in Table on Algorithm Solutions</description><generator>Hugo -- gohugo.io</generator><lastBuildDate>Thu, 24 Sep 2026 20:29:24 -0500</lastBuildDate><atom:link href="https://algorithm.liangqin.ren/tags/table/index.xml" rel="self" type="application/rss+xml"/><item><title>6. Count Pairs That Differ by at Most One Digit Swap</title><link>https://algorithm.liangqin.ren/oa/6/</link><pubDate>Thu, 24 Sep 2026 20:29:24 -0500</pubDate><guid>https://algorithm.liangqin.ren/oa/6/</guid><description>1. Description You are given an array of positive integers numbers.
A pair of indices (i, j), where i &amp;lt; j, is valid if numbers[i] can be transformed into numbers[j] by swapping at most two digits in one of the numbers. No swap is also allowed.
Return the number of valid pairs.
2. Solution n = numbers.size()
Time complexity: O(n$^2$)
Space complexity: O(n)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 int solution(const vector&amp;lt;int&amp;gt;&amp;amp; numbers) { unordered_map&amp;lt;string, vector&amp;lt;string&amp;gt;&amp;gt; buckets; for (int num : numbers) { string s = to_string(num); string key = s; sort(key.</description></item></channel></rss>