My logic is as follows :
#include<bits/stdc++.h>
    using namespace std;
    
    int main(){
        char a[50] = {'h','i',' ','m','e',' ','t','e'};
        
        
        // k = 4 because i have 2 spaces and for each
       // space i have to insert 2 spaces . so total 4 
       //spaces
        int k=4;
        for(int i=strlen(a)-1 ; i>0 && k >0 ; i--){
            if(a[i] != ' ')
            {
                a[i+k] = a[i];
                a[i] = ' ';
            }
            else
            {
                k = k - 2;
            }
            
        }
    
        printf("%s" , a);
    
        return 0;
    }
I have to character array to solve it. I am able to do it using string stl The output i get is hi---me. But the answer is hi---me---te.
 
     
    