-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathInterviewQuestion.java
More file actions
37 lines (29 loc) · 956 Bytes
/
InterviewQuestion.java
File metadata and controls
37 lines (29 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Arrays;
public class InterviewQuestion {
public static void main(String[] args) {
// First Question
//String a = "Hello How are You I am Fine";
//System.out.println(a.split(" ").length);
// Second Question
int highestCount = 0;
String data = "axywghkbbmthnmbshyatpkbfhstrgcngstynbmdhjh";
char array[] = data.toCharArray();
Arrays.sort(array);
//aabbbbbcdfggghhhhhhjkkmmmnnnprsssttttwxyyy
String sortedString = new String(array);
System.out.println(sortedString);
char highestChar = '#';
for(int i = 0 ; i<sortedString.length();){
char singleChar = sortedString.charAt(i);
int startIndex = sortedString.indexOf(singleChar);
int lastIndex = sortedString.lastIndexOf(singleChar);
int count = lastIndex - startIndex;
if(count>=highestCount){
highestCount =count;
highestChar = singleChar;
}
i = lastIndex + 1;
}
System.out.println(highestCount+" "+highestChar);
}
}