Queries on substring palindrome formation | Query type 1 : update string position i with character x . ; Print " Yes " if range [ L . . R ] can form palindrome , else print " No " . ; Find the frequency of each character in S [ L ... R ] . ; Checking if more than one character have frequency greater than 1. ; Driven code
function qType1 ( l , x , str1 ) { str1 [ l - 1 ] = x ; } function qType2 ( l , r , str1 ) { let freq = new Array ( 27 ) ; for ( let i = 0 ; i < 27 ; i ++ ) { freq [ i ] = 0 ; } for ( let i = l - 1 ; i <= r - 1 ; i ++ ) { freq [ str1 [ i ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ] ++ ; } let count = 0 ; for ( let j = 0 ; j < 26 ; j ++ ) { if ( freq [ j ] % 2 != 0 ) { count ++ ; } } if ( count <= 1 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let str = " " . split ( " " ) ; let n = str . length ; qType1 ( 4 , ' ' , str ) ; qType2 ( 1 , 4 , str ) ; qType2 ( 2 , 3 , str ) ; qType1 ( 10 , ' ' , str ) ; qType2 ( 10 , 11 , str ) ;