Input: N = 4, K = 3
Output: 5
Explanation:
S = {1, 4, 16, 64, ...}.
Therefore, the non-empty subsets arranged in increasing order of their sum = {{1}, {4}, {1, 4}, {16}, {1, 16}, {4, 16}, {1, 4, 16}.........}.
So the elements of the subset in Kth(3rd) subset are {1, 4}. So the sum of the greatest and smallest elements of this subset = (4 + 1) = 5.
Input: N = 3, K = 4
Output: 18
Explanation:
S = {1, 3, 9, 27, 81, ...}.
Therefore, the non-empty subsets arranged in increasing order of their sum = {{1}, {3}, {1, 3}, {9}, {1, 9}, {3, 9}, {1, 3, 9} ........}.
So the element in the subset at 4th position is {9}. So the sum of the greatest and smallest elements of this subset = (9 + 9) = 18.