Today, Shubham is very busy with a string. He is observing the journey of each character of the string. Journey of a character in the string can be defined as the array of locations coordinates at which the character is present in the string.
For example in string "vivekanand"
Journey of 'v':- [0,2]
Journey of 'i':- [1]
Journey of 'e':- [3]
Journey of 'k':- [4]
Journey of 'a':- [5,7]
Journey of 'n':- [6,8]
Journey of 'd':- [9]
Journey of a character is said to be "marvellous" if the sum journey of the character is greater than sum journey of any other character in the string.
Sum journey of character in the string can be defined as the sum of all the location coordinates in its path.
Can you find the lexicographically smallest character whose journey is marvellous.
Input Format
The only line of input consists of a single string, S.
Constraints
1<= |S| <=1e9
String contains only Lowercase English alphabets.
Output Format
Print a character C which represents lexicographically smallest character whose journey is marvellous and an integer I which represents sum journey of the character space-separated.
Sample TestCase 1
Input
vivekanand
Output
n 14
Answers
Answer:
Sign In
Home
Courses
Practice DS & Algo.
Algorithms
Analysis of Algorithms
Data Structures
Interview Corner
Languages
CS Subjects
GATE
Web Technologies
Software Designs
School Learning
Mathematics
Maths Notes (Class 8-11)
NCERT Solutions
RD Sharma Solutions
ISRO CS
UGC NET CS
Student
Jobs
GBlog
Puzzles
What's New ?
Change Language
Related Articles
▲
Related Articles
Lexicographically smallest string obtained after concatenating array
Lexicographically smallest string formed by appending a character from the first K characters of a given string
Lexicographically smallest string formed by removing at most one character
Find lexicographically smallest string in at most one swaps
Lexicographically largest sub-sequence of the given string
Lexicographically smallest and largest substring of size k
Lexicographical Maximum substring of string
Smallest window that contains all characters of string itself
Find the smallest window in a string containing all characters of another string
Length of the smallest sub-string consisting of maximum distinct characters
Length of the longest substring without repeating characters
Print Longest substring without repeating characters
Find the longest substring with k unique characters in a given string
Find the two non-repeating elements in an array of repeating elements/ Unique Numbers 2
Find the two numbers with odd occurrences in an unsorted array
Add two numbers without using arithmetic operators
Subtract two numbers without using arithmetic operators
Subtract 1 without arithmetic operators
Add 1 to a given number
Multiply a given Integer with 3.5
Turn off the rightmost set bit
Find whether a given number is a power of 4 or not
Compute modulus division by a power-of-2-number
Rotate bits of a number
Write a program to reverse an array or string
Longest Common Subsequence | DP-4
Write a program to print all permutations of a given string
Reverse a string in Java
Write a program to reverse an array or string
Check for Balanced Brackets in an expression (well-formedness) using Stack
Lexicographically smallest string formed by appending a character from the first K characters of a given string
Difficulty Level : Easy
Last Updated : 14 May, 2021
Given a string S consisting of lowercase alphabets. The task is to find the lexicographically smallest string X of the same length only that can be formed using the operation given below:
In a single operation, select any one character among the at most first K characters of string S, remove it from string S and append it to string X. Apply this operation as many times as he wants.
Examples:
Input: str = “gaurang”, k=3
Output: agangru
Remove ‘a’ in the first step and append to X.
Remove ‘g’ in the second step and append to X.
Remove ‘a’ in the third step and append to X.
Remove ‘n’ in the third step and append to X.
Pick the lexicographically smallest character at every step from the first K characters to get the
string “agangru”
Input: str = “geeksforgeeks”, k=5
Output: eefggeekkorss