Top 50 Coding Interview Questions for QA/SDET – Part 1 (Questions 1–10)

Master Arrays & Strings with Java

Introduction

Coding rounds have become an essential part of QA Automation and SDET interviews. Whether you're interviewing at Amazon, Microsoft, Google, Salesforce, Walmart, Oracle, Adobe, or any product-based company, you'll almost certainly face coding questions before moving on to Selenium, Playwright, API Testing, or System Design.

Unlike Software Development Engineer (SDE) interviews, SDET coding rounds focus on:

  • Writing clean and readable code

  • Optimizing time and space complexity

  • Solving real-world automation problems

  • Strong understanding of Java fundamentals

  • Ability to manipulate Strings, Arrays, Collections, and Maps

This series covers the Top 50 Coding Interview Questions most frequently asked in QA/SDET interviews.

In Part 1, we'll solve the first 10 questions based on Arrays and Strings.


Question 1: Reverse a String

Problem Statement

Write a Java program to reverse a given string.

Example

Input:

Automation

Output:

noitamotuA

Why Interviewers Ask This

Although this looks simple, interviewers want to evaluate:

  • Loop understanding

  • String manipulation

  • Java fundamentals

  • Knowledge of immutable Strings


Approach 1 – Using Loop (Recommended)

Traverse the string from the last character to the first.

Java Solution

public class ReverseString {

    public static void main(String[] args) {

        String str = "Automation";
        String reverse = "";

        for (int i = str.length() - 1; i >= 0; i--) {
            reverse += str.charAt(i);
        }

        System.out.println(reverse);
    }
}

Dry Run

String:

Automation

Iterations

n
no
noi
noit
...
noitamotuA

Better Approach Using StringBuilder

public class ReverseString {

    public static void main(String[] args) {

        String str = "Automation";

        String reverse = new StringBuilder(str)
                .reverse()
                .toString();

        System.out.println(reverse);
    }
}

Complexity

Loop

Time: O(n)

Space: O(n)

StringBuilder

Time: O(n)

Space: O(n)


Interview Follow-up Questions

  • Reverse without using StringBuilder.

  • Reverse each word instead of the complete string.

  • Reverse only vowels.

  • Reverse using recursion.


Question 2: Check Palindrome

Problem Statement

Check whether a string is a palindrome.

A palindrome reads the same forward and backward.

Examples

madam
level
racecar

Approach

Reverse the string and compare it with the original.


Java Solution

public class Palindrome {

    public static void main(String[] args) {

        String str = "madam";
        String reverse = "";

        for (int i = str.length() - 1; i >= 0; i--) {
            reverse += str.charAt(i);
        }

        if (str.equals(reverse))
            System.out.println("Palindrome");
        else
            System.out.println("Not Palindrome");
    }
}

Optimized Solution

Instead of reversing, compare characters from both ends.

public class Palindrome {

    public static boolean isPalindrome(String str){

        int left = 0;
        int right = str.length()-1;

        while(left < right){

            if(str.charAt(left)!=str.charAt(right))
                return false;

            left++;
            right--;
        }

        return true;
    }

    public static void main(String[] args){

        System.out.println(isPalindrome("madam"));
    }
}

Complexity

Time: O(n)

Space: O(1)


Common Mistakes

  • Ignoring uppercase/lowercase.

  • Not removing spaces.

  • Forgetting special characters.


Question 3: Find Duplicate Characters in a String

Problem Statement

Find duplicate characters along with their occurrence.

Input

programming

Output

r -> 2
g -> 2
m -> 2

Approach

Use a HashMap to count frequency.


Java Solution

import java.util.*;

public class DuplicateCharacters {

    public static void main(String[] args) {

        String str = "programming";

        Map<Character,Integer> map = new HashMap<>();

        for(char ch : str.toCharArray()){
            map.put(ch,map.getOrDefault(ch,0)+1);
        }

        for(Map.Entry<Character,Integer> entry : map.entrySet()){

            if(entry.getValue()>1){
                System.out.println(entry.getKey()+" -> "+entry.getValue());
            }
        }
    }
}

Complexity

Time: O(n)

Space: O(n)


Interview Tips

Interviewers often ask:

  • Count all characters.

  • Print unique characters.

  • Print first duplicate.


Question 4: Count Vowels and Consonants

Problem Statement

Count vowels and consonants in a string.

Input

Automation

Output

Vowels = 6
Consonants = 4

Java Solution

public class CountCharacters {

    public static void main(String[] args) {

        String str = "Automation".toLowerCase();

        int vowels = 0;
        int consonants = 0;

        for(char ch : str.toCharArray()){

            if(Character.isLetter(ch)){

                if("aeiou".indexOf(ch)!=-1)
                    vowels++;
                else
                    consonants++;
            }
        }

        System.out.println("Vowels = "+vowels);
        System.out.println("Consonants = "+consonants);
    }
}

Complexity

Time: O(n)

Space: O(1)


Follow-up

Ignore numbers and special characters.


Question 5: Find First Non-Repeated Character

Problem Statement

Input

automation

Output

u

Approach

Count frequency using LinkedHashMap to preserve insertion order.


Java Solution

import java.util.*;

public class FirstUniqueCharacter {

    public static void main(String[] args){

        String str="automation";

        Map<Character,Integer> map=new LinkedHashMap<>();

        for(char ch:str.toCharArray()){
            map.put(ch,map.getOrDefault(ch,0)+1);
        }

        for(Map.Entry<Character,Integer> entry:map.entrySet()){

            if(entry.getValue()==1){

                System.out.println(entry.getKey());
                break;
            }
        }
    }
}

Complexity

Time: O(n)

Space: O(n)


Question 6: Check Anagram

Problem Statement

Two strings are anagrams if they contain the same characters with the same frequency.

Example

listen
silent

Approach

Sort both strings and compare.


Java Solution

import java.util.Arrays;

public class Anagram {

    public static void main(String[] args){

        String s1="listen";
        String s2="silent";

        char[] c1=s1.toCharArray();
        char[] c2=s2.toCharArray();

        Arrays.sort(c1);
        Arrays.sort(c2);

        System.out.println(Arrays.equals(c1,c2));
    }
}

Complexity

Time: O(n log n)

Space: O(n)


Better Approach

Use a frequency array for lowercase English letters to achieve O(n) time.


Question 7: Remove Duplicate Characters from a String

Problem Statement

Input

programming

Output

progamin

Java Solution

import java.util.LinkedHashSet;

public class RemoveDuplicates {

    public static void main(String[] args){

        String str="programming";

        LinkedHashSet<Character> set=new LinkedHashSet<>();

        for(char ch:str.toCharArray()){
            set.add(ch);
        }

        StringBuilder sb=new StringBuilder();

        for(char ch:set){
            sb.append(ch);
        }

        System.out.println(sb);
    }
}

Complexity

Time: O(n)

Space: O(n)


Question 8: Find Maximum and Minimum Element in an Array

Problem Statement

Input

{5,3,8,1,10}

Output

Min = 1

Max = 10

Java Solution

public class MinMax {

    public static void main(String[] args){

        int[] arr={5,3,8,1,10};

        int min=arr[0];
        int max=arr[0];

        for(int num:arr){

            if(num<min)
                min=num;

            if(num>max)
                max=num;
        }

        System.out.println("Min = "+min);
        System.out.println("Max = "+max);
    }
}

Complexity

Time: O(n)

Space: O(1)


Question 9: Find Second Largest Element

Problem Statement

Input

{12,45,67,23,89}

Output

67

Approach

Maintain two variables:

  • Largest

  • Second Largest


Java Solution

public class SecondLargest {

    public static void main(String[] args){

        int[] arr={12,45,67,23,89};

        int first=Integer.MIN_VALUE;
        int second=Integer.MIN_VALUE;

        for(int num:arr){

            if(num>first){

                second=first;
                first=num;

            }else if(num>second && num!=first){

                second=num;
            }
        }

        System.out.println(second);
    }
}

Complexity

Time: O(n)

Space: O(1)


Edge Cases

  • Duplicate maximum values

  • Negative numbers

  • Array with fewer than two elements


Question 10: Move All Zeros to the End

Problem Statement

Input

{1,0,5,0,7,8,0}

Output

{1,5,7,8,0,0,0}

Approach

Use two pointers:

  • One pointer tracks the next non-zero position.

  • Another scans the array.

Swap non-zero elements into the correct position while preserving order.


Java Solution

import java.util.Arrays;

public class MoveZeros {

    public static void main(String[] args){

        int[] arr={1,0,5,0,7,8,0};

        int index=0;

        for(int i=0;i<arr.length;i++){

            if(arr[i]!=0){

                int temp=arr[index];
                arr[index]=arr[i];
                arr[i]=temp;

                index++;
            }
        }

        System.out.println(Arrays.toString(arr));
    }
}

Complexity

Time: O(n)

Space: O(1)


Interview Variations

  • Move all negative numbers to one side.

  • Move even numbers to the beginning.

  • Move all null values to the end in a list.


Key Takeaways

After completing Part 1, you should be comfortable with:

  • String traversal and manipulation

  • Palindrome checking

  • Frequency counting using HashMap

  • Finding duplicates and unique characters

  • Anagram detection

  • Working with arrays efficiently

  • Finding minimum, maximum, and second-largest elements

  • Two-pointer techniques

  • Time and space complexity analysis

These questions form the foundation of most QA Automation and SDET coding interviews. Practice writing each solution without referring to notes, explain your approach aloud, and analyze the complexity of your code. This not only prepares you for coding rounds but also improves your ability to write efficient automation utilities and framework code.


What's Next?

In Part 2, we'll cover another 10 high-frequency interview questions focused on:

  • HashMap-based problems

  • Array frequency questions

  • Stack and Queue fundamentals

  • String compression

  • Missing number problems

  • Array intersection and union

  • Valid parentheses

  • Character frequency sorting

  • Longest common prefix

  • Majority element

By the end of Part 2, you'll have mastered many of the coding patterns that frequently appear in QA/SDET interviews.