How to solve these questions?

  1. The number is said to be beautiful if it contains exactly one 1s ,two 2s , three 3s and so on .A number is given as input and we need to output the smallest beautiful number greater than the given number.
    Examples of beautiful numbers :
    1,22,122,212,221,333,3331,1333 etc.

sample test cases:
input:
10
output:
22

input:
125
output:
212

2.We are given an array and a number k .Here we need to split the given array in to k sub arrays such that each subarray consists of at least one element in it. We can split an array in many ways but we need to split the given array in two ways so that we get minimum and maximum possible cost .we need to output the difference of this max and min values.(cost of a subarray= first element + last element)
Example :
A=[1,3,5,1]
k=2
we have to split the given array in to two subarrays
[1,3] [5,1] this combination gives maximum cost i.e (1+3)+(5+1)=10
[1] [3,5,1] this combination gives minimum cost i.e (1+1)+(3+1)=6

difference->10-6=4(ans)

If there are any similar questions of this type please share them with me