Are you searching for PHP program to find smallest permutation of given number? We have shared the PHP program to find smallest permutation of given number.
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 | <?php /** * PHP program to find smallest permutation of given number. */ function findSmallestPermutation($s) { $len = strlen($s); $s = str_split($s); // sort the string sort($s); $i = 0; while ($s[$i] == '0') $i++; $tmp = $s[0]; $s[0] = $s[$i]; $s[$i] = $tmp; $s=implode("", $s); return $s; } // input in string $s = "5468001"; $res = findSmallestPermutation($s); echo $res; |
Program Output
1 | 1004568 |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.