Longest Common Extension / LCE | Set 1 ( Introduction and Naive Method ) | Structure to represent a query of form ( L , R ) ; A utility function to find longest common extension from index - L and index - R ; A function to answer queries of longest common extension ; Driver code ; LCA Queries to answer
class Query { constructor ( L , R ) { this . L = L ; this . R = R ; } } function LCE ( str , n , L , R ) { let length = 0 ; while ( R + length < n && str [ L + length ] == str [ R + length ] ) length ++ ; return ( length ) ; } function LCEQueries ( str , n , q , m ) { for ( let i = 0 ; i < m ; i ++ ) { let L = q [ i ] . L ; let R = q [ i ] . R ; document . write ( " " + L + " " + R + " " + LCE ( str , n , L , R ) + " " ) ; } return ; } let str = " " ; let n = str . length ; let q = new Array ( 3 ) ; q [ 0 ] = new Query ( 1 , 2 ) ; q [ 1 ] = new Query ( 1 , 6 ) ; q [ 2 ] = new Query ( 0 , 5 ) ; let m = q . length ; LCEQueries ( str , n , q , m ) ;