Oracle Interview Question: String Palindrom, reverse wor... | Glassdoor.co.in

Interview Question

Test Automation Engineer Interview Bengaluru

String Palindrom, reverse words in a string, find longest

  substring in a string, duplicate characters in a string and print the count of it.
Answer

Interview Answer

5 Answers

0

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;
}

Shabana Khan on 06-May-2020
1

//* Using stack
public static boolean isPalindrome(String string)
{
String rev="";
Stack stack = new Stack();
for(int i=0;i

Shabana Khan on 06-May-2020
0

//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;
    }

Shabana Khan on 06-May-2020
0

//*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;

    }

Shabana Khan on 06-May-2020
0

//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());
}

Shabana Khan on 07-May-2020

Add Answers or Comments

To comment on this, Sign In or Sign Up.