Amazon Interview Question
Quality Assurance EngineersCountry: India
Interview Type: Phone Interview
public static void main(String[] args) {
// TODO Auto-generated method stub
String line = "Happy%Christmas%%&&&A@New^^$#@";
String regexp = "[a-zA-Z][!@#$%^&*?][a-zA-Z]+";
Pattern p = Pattern.compile(regexp);
String last_match = "";
Matcher m = p.matcher(line);
while(m.find())
{
if(last_match.length()< m.group().length() && (m.start()%2) ==0)
last_match = m.group();
System.out.println(m.start()+"-"+m.end());
System.out.println(m.group());
}
System.out.println("longest match -"+ last_match);
}
}
public static void largestword(String str){
String str1[] = str.replaceAll("[^a-zA-Z]", " ").split(" ");
int temp = 0;
String longestWord = "";
for(int i=0; i<str1.length;i++) {
if(temp < str1[i].length()) {
temp = str1[i].length();
longestWord = str1[i];
}
}
System.out.println(longestWord+" is the largest word with "+temp +" characters");
}
public static void largestword(String str){
- koushalm31 February 09, 2020String str1[] = str.replaceAll("[^a-zA-Z]", " ").split(" ");
int temp = 0;
String longestWord = "";
for(int i=0; i<str1.length;i++) {
if(temp < str1[i].length()) {
temp = str1[i].length();
longestWord = str1[i];
}
}
System.out.println(longestWord+" is the largest word with "+temp +" characters");
}