Rearrange a string in the form of integer sum followed by the minimized character | C # implementation of above approach ; function to return maximum volume ; separate digits and alphabets ; change digit sum to string ; change alphabet sum to string ; concatenate sum to alphabets string ; Driver code
using System ; public class Solution { static String separateChar ( String str ) { int n = str . Length , digitSum = 0 ; int alphabetSum = 0 , j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] >= '0' && str [ i ] <= '9' ) { digitSum += ( int ) ( str [ i ] - '0' ) ; } else { alphabetSum += str [ i ] - ' a ' + 1 ; alphabetSum %= 26 ; } } String sumStr = " " + ( digitSum ) ; char alphabetStr = ( char ) ( alphabetSum + ' a ' - 1 ) ; sumStr += alphabetStr ; return sumStr ; } public static void Main ( ) { String str = "3652adyz3423" ; Console . WriteLine ( separateChar ( str ) ) ; } }