Pergunta de entrevista da empresa Oracle
String Palindrom, reverse words in a string, find longest substring in a string, duplicate characters in a string and print the count of it.
Respostas da entrevista
//Reverse Words in String
public static String reverseWords(String string){
String[] stAr=string.split(" ");
String result="";
for(int i=stAr.length-1;i>=0;i--)
{
result=result+" "+stAr[i];
}
return result.subString(1,result.length());
}
public static boolean isPalindrome(String string)
{
String reverse ="";
for(int i=string.length()-1;i>=0;i--)
{
reverse=reverse+string.charAt(i);
}
if(string.equalsIgnoreCase(reverse)
{
return true;
}
return false;
}
//Reverse Words In a String
public static String reverseWords(String s)
{
String res="";
String[] string=s.split(" ");
for(int i=0;i=0;i--)
{
rev=rev+string.charAt(i);
}
return rev;
}
//*Counting duplicates
public static int countDuplicates(String str)
{
char[] charArray = str.toCharArray();
Map hash_map = new HashMap();
for(int i=0;i entry:hash_map.entrySet())
{
if(entry.getValue()>1)
{
count=count+1;
}
}
return count;
}
//* Using stack
public static boolean isPalindrome(String string)
{
String rev="";
Stack stack = new Stack();
for(int i=0;i