All Tracks Algorithms Greedy Algorithms Basics of Greedy Algorithms Problem

Mike and LMS
Tag(s):

Algorithms, Easy, Greedy algorithm, String, String, sorting, strings

Problem
Editorial
Analytics

Disappointed and Disheartened Mike is really tired of jail life, and needs to take his mind off all this. Mike's roomate and good friend Kevin decidedes to help him, and tells him to try the following task:

Given a string S consisting of lowercase English alphabets of size N, can you find the lexicographically maximum substring of this string ? Mike has no knowledge what so ever of strings, and needs your help. Can you help Mike and improve his mood?

Input Format :

The first line contains a single integer N denoting the length of string S. The next line contains the string S.

Output Format :

Print the lexicographically maximum substring of String S on a single line.

Constraints :

\( 1 \le N \le 5000 \)

SAMPLE INPUT
6
ababaa
SAMPLE OUTPUT
babaa
Explanation

Lexicographically maximum string of the given string is \(babaa\) .

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

Mad Street Den

Challenge Name

Mad Street Den Python Hiring Challenge

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?