Maximum binary numbers(Hackerearth problem)

Can anyone help me to solve this problem :frowning:

Problem Link : Maximum binary numbers | Suffix Arrays & Data Structures Practice Problems | HackerEarth

What I want to understand :-

  • How can we know the maximum possible value of a binary string within time limits like O(n) or O(nlogn) (n is length of string)?
  • Is there some standard approach for this problem ?