Check if string can be made lexicographically smaller by reversing any substring | C ++ implementation of the approach ; Function that returns true if s can be made lexicographically smaller by reversing a sub - string in s ; Traverse in the string ; Check if s [ i + 1 ] < s [ i ] ; Not possible ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( string s ) { int n = s . size ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( s [ i ] > s [ i + 1 ] ) return true ; } return false ; } int main ( ) { string s = " geeksforgeeks " ; if ( check ( s ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }