Find a permutation of 2 N numbers such that the result of given expression is exactly 2 K | Function to find the required permutation of first 2 * N natural numbers ; Iterate in blocks of 2 ; We need more increments , so print in reverse order ; We have enough increments , so print in same order ; Driver Code
< ? php function printPermutation ( $ n , $ k ) { for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ x = 2 * $ i - 1 ; $ y = 2 * $ i ; if ( $ i <= $ k ) echo $ y . " " ▁ . ▁ $ x ▁ . ▁ " " else echo $ x . " ▁ " . $ y . " ▁ " ; } } $ n = 2 ; $ k = 1 ; printPermutation ( $ n , $ k ) ; ? >