Given a transmission string and a subsequence of that string representing corrupted data, find the minimum number of operations required to correct the subsequence in-place, where an operation is a swap of two adjacent characters in the string.
Explanation: Step-by-step: 1. Find the position of 'c' in the transmission string, which is 2. 2. Find the position of 'c' in the subsequence, which is 0. 3. Swap 'c' with 'b' in the transmission string. 4. Find the position of 'd' in the transmission string, which is 3. 5. Find the position of 'd' in the subsequence, which is 1. 6. Swap 'd' with 'e' in the transmission string. The corrected subsequence is 'cde' in 'abcde' with 2 swaps.
Explanation: Step-by-step: 1. Find the position of 'c' in the transmission string, which is 2. 2. Find the position of 'c' in the subsequence, which is 0. 3. Swap 'c' with 'b' in the transmission string. 4. Find the position of 'e' in the transmission string, which is 4. 5. Find the position of 'e' in the subsequence, which is 1. 6. Swap 'e' with 'a' in the transmission string. 7. Find the position of 'b' in the transmission string, which is 1. 8. Find the position of 'b' in the subsequence, which is 3. 9. Swap 'b' with 'c' in the transmission string. The corrected subsequence is 'ceba' in 'abcde' with 3 swaps.
Master coding challenges related to Strings and solve the [Backup] Galactic Transmission Correction problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak