compute the change in led and keep on adding the change
int sum = Led [ n . charAt ( 0 ) - '0' ] ; for ( int i = 1 ; i < len ; i ++ ) { sum = sum + Math . abs ( Led [ n . charAt ( i ) - '0' ] - Led [ n . charAt ( i - 1 ) - '0' ] ) ; } return sum ; }