Minimum number of swaps needed to reduce absolute difference between integer strings

Правка en3, от govind53, 2024-07-12 21:43:28

Need help with figuring out best possible solution for this problem: There are two strings of same length representing numbers, we can swap the elements at corresponding index in both strings. There exist some integer k such that k swaps results in strings with minimum absolute difference. Task is to find k. Example of one of possible swap: s = "123" and t = "456" -> swap at index 0 makes s = "423" and t = "156" -> abs diff is 267 a possible solution is using back tracking but there should be better solution for this.

A follow-up question, given some k we want to find minimum possible absolute difference after k swaps.

Теги dynamic programming, binary search, graphs, greedy

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский govind53 2024-07-12 21:43:28 15 Tiny change: 'o strings represent' -> 'o strings of same length represent'
en2 Английский govind53 2024-07-12 21:11:05 33
en1 Английский govind53 2024-07-12 21:10:10 673 Initial revision (published)