Alphabet Streak
Given a string s of lowercase alphabets, find the length of the longest streak and the alphabet with the longest streak.
Input Format
The first line of input consists of an integer t denoting the number of test cases. t test cases follow. The first line of each test case consists of an integer n denoting the length of string s. Second line of the test case consists of string s.
Output Format
For each test case, output the length of the longest streak and the alphabet with longest streak separated by space. In case of ties, output the tied alphabets in lexicographical order.
input
3
cba
1
c
6
abator
36
eygesoznssineggisbbsiininnegniseebny
output
1 abc
1 c
1 abort
2 begins
Answers
Answer:
ano daw sorry grade four plang ako
3
cba
1
c
6
abator
36
eygesoznssineggisbbsiininnegniseebny
output
1 abc
1 c
1 abort
2 begins
Explanation:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
class abc
{
public static void main(String args[]) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int N = Integer.parseInt(line);
ArrayList<Integer> inputs = new ArrayList<Integer>();
for (int i = 0; i < N; i++) {
inputs.add(Integer.valueOf(br.readLine()));
}
ArrayList<BigInteger> outputs = new ArrayList<BigInteger>();
for(Integer input : inputs){
outputs.add(factorial(input));
}
for(BigInteger result: outputs){
System.out.println(result);
}
}
private static BigInteger factorial(Integer input) {
if(input == 1) return BigInteger.ONE;
return factorial(input - 1).multiply(new BigInteger(String.valueOf(input)));
}
}