SDET Coding Interview Questions

Automation testing and SDET interviews almost always include a coding round built around arrays, numbers, strings and collections. Below are the 30 questions asked most often, each with the approach interviewers expect, its complexity, and tested Java code for the most important ones — plus four SDET-specific tasks that show you can apply coding to real test automation.

⭐ marks the questions asked most frequently. For the underlying patterns (running max, HashSet, HashMap, two pointers, digit extraction, complement lookup), read the Java Coding Programs for Interview guide first.

Advertisement

Array Questions (Q1–12)

Q1. How do you find the sum and average of array elements?

Accumulate all elements in a loop, then divide the total by the length after casting to double so the average isn't truncated. Complexity: O(n).

Learn more: Array Basics · average of array elements

Q2. How do you find the largest and smallest element in an array?

Traverse the array once while tracking the current maximum and minimum. Complexity: O(n).

Learn more: maximum element · minimum element

Q3. How do you find the second largest element in an array? ⭐

Keep two variables, largest and secondLargest. When a new maximum appears, the old maximum becomes the second largest. Skip values equal to the largest so duplicates don't break the answer. Complexity: O(n), no sorting.

Code: Pattern 1 in the coding programs guide · full tutorial

Q4. How do you find the second smallest element?

Mirror of Q3: track smallest and secondSmallest, both initialized to Integer.MAX_VALUE. Complexity: O(n).

Learn more: second smallest element

Q5. How do you sort an array using Bubble Sort?

Repeatedly compare adjacent elements and swap them, so the largest value "bubbles" to the end on each pass. Stop early if a pass makes no swaps. Complexity: O(n²).

Learn more: Sort & Duplicates · sort ascending

Q6. How do you reverse an array?

Two pointers: swap the first and last elements and move both pointers inward until they meet. Complexity: O(n), in place.

Learn more: reverse an array

Q7. How do you find duplicate elements in an array? ⭐

Add elements to a HashSet; if add() returns false, the element is a duplicate. Complexity: O(n).

Code: Pattern 2 in the coding programs guide · full tutorial

Q8. How do you remove duplicates from an array? ⭐

A LinkedHashSet removes duplicates while keeping the original order. Complexity: O(n).

public static int[] removeDuplicates(int[] a) {
    Set<Integer> unique = new LinkedHashSet<>();
    for (int x : a) unique.add(x);
    return unique.stream().mapToInt(Integer::intValue).toArray();
}
// removeDuplicates(new int[]{3, 1, 3, 2, 1}) → [3, 1, 2]

Learn more: remove duplicates from an array

Q9. How do you count the frequency of each array element?

Use a HashMap with merge() or getOrDefault(); a visited[] array also works without collections. Complexity: O(n) with a HashMap.

Learn more: frequency of each element

Q10. How do you find the missing number in an array? ⭐

For numbers 1 to n with one missing, subtract the actual sum from the expected sum n(n+1)/2. Use long to avoid overflow. Complexity: O(n) time, O(1) space.

public static int missingNumber(int[] a, int n) {
    long expected = (long) n * (n + 1) / 2;
    long actual = 0;
    for (int x : a) actual += x;
    return (int) (expected - actual);
}
// missingNumber(new int[]{1, 2, 4, 5, 6}, 6) → 3

Learn more: Rotation, Missing Number & Pair Sum

Q11. How do you find a pair with a given sum? ⭐

For each element, check whether target − element is already in a HashSet of seen values. Complexity: O(n).

Code: Pattern 6 in the coding programs guide · full tutorial

Q12. How do you find the majority element?

Boyer–Moore voting: keep a candidate and a counter; matching values increment it, others decrement it, and a zero counter picks a new candidate. Complexity: O(n) time, O(1) space.

public static int majorityElement(int[] a) {
    int candidate = 0, count = 0;
    for (int x : a) {
        if (count == 0) candidate = x;
        count += (x == candidate) ? 1 : -1;
    }
    return candidate;   // verify with a second pass if a majority isn't guaranteed
}
// majorityElement(new int[]{2, 2, 1, 1, 2, 2, 3}) → 2

Learn more: majority element

Number Questions (Q13–21)

Q13. How do you reverse a number? ⭐

Take the last digit with % 10, append it with rev * 10 + digit, and drop it with / 10. Mention integer overflow for very large inputs.

Code: Pattern 5 in the coding programs guide · full tutorial

Q14. How do you check whether a number is a palindrome?

Reverse the number (Q13) and compare it with the original. Negative numbers are not palindromes.

Learn more: palindrome number

Q15. How do you check whether a number is prime? ⭐

Numbers ≤ 1 are not prime. Check divisors from 2 up to √n — if none divides n, it's prime. Complexity: O(√n).

public static boolean isPrime(int n) {
    if (n <= 1) return false;
    for (int i = 2; (long) i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}
// isPrime(29) → true, isPrime(49) → false

Learn more: Number Basics · prime number

Q16. How do you find the factorial of a number?

Multiply the integers from 1 to n in a loop (or recursively). Use long — it holds values up to 20! — and BigInteger beyond that.

Learn more: factorial

Q17. How do you check whether a number is an Armstrong number?

Raise each digit to the power of the number of digits and add them up; it's an Armstrong number if the sum equals the original. For three digits that means cubes (153 = 1³ + 5³ + 3³), but 9474 uses fourth powers.

public static boolean isArmstrong(int n) {
    int digits = String.valueOf(n).length();
    int sum = 0, t = n;
    while (t > 0) {
        sum += (int) Math.pow(t % 10, digits);
        t /= 10;
    }
    return sum == n;
}
// isArmstrong(153) → true, isArmstrong(9474) → true

Learn more: Armstrong number

Q18. How do you generate the Fibonacci series? ⭐

Each term is the sum of the previous two. The iterative version is O(n); naive recursion is exponential, so mention memoization if you use recursion.

public static List<Long> fibonacci(int count) {
    List<Long> series = new ArrayList<>();
    long a = 0, b = 1;
    for (int i = 0; i < count; i++) {
        series.add(a);
        long next = a + b;
        a = b;
        b = next;
    }
    return series;
}
// fibonacci(8) → [0, 1, 1, 2, 3, 5, 8, 13]

Learn more: Fibonacci series

Q19. How do you find the GCD and LCM of two numbers?

Euclid's algorithm: gcd(a, b) = gcd(b, a % b) until b is 0. Then LCM = a / GCD × b (dividing first avoids overflow).

public static int gcd(int a, int b) { 
    return b == 0 ? a : gcd(b, a % b); 
}

public static long lcm(int a, int b) { 
    return (long) a / gcd(a, b) * b; 
}

// gcd(12, 18) → 6, lcm(12, 18) → 36

Learn more: Number Advanced · GCD · LCM

Q20. How do you reverse a number using recursion?

Pass the partially reversed value as a parameter: take one digit, add it to the result, and recurse on n / 10 until n is 0.

Learn more: reverse a number without a loop

Q21. How do you convert a decimal number to binary?

Repeatedly divide by 2, store the remainders, and read them in reverse — or use Integer.toBinaryString(n) and explain what it does.

Learn more: decimal to binary

String Questions (Q22–30)

Q22. How do you reverse a string? ⭐

new StringBuilder(str).reverse().toString() is the one-liner — but interviewers usually ask you to do it manually as well:

public static String reverse(String s) {
    char[] c = s.toCharArray();
    for (int i = 0, j = c.length - 1; i < j; i++, j--) {
        char tmp = c[i]; 
        c[i] = c[j]; 
        c[j] = tmp;
    }
    return new String(c);
}
// reverse("selenium") → "muineles"

Learn more: reverse a string (5 methods)

Q23. How do you check whether a string is a palindrome? ⭐

Two pointers from both ends, after normalizing case and removing non-alphanumeric characters.

Code: Pattern 4 in the coding programs guide · full tutorial

Q24. How do you count vowels and consonants?

Lowercase the string, then for each letter check whether "aeiou".indexOf(ch) >= 0; other letters are consonants, and non-letters are skipped.

Learn more: String Basics

Q25. How do you find duplicate characters in a string? ⭐

Count characters in a HashMap and print those with a count above one.

Learn more: duplicate characters · character frequency

Q26. How do you remove duplicate characters from a string? ⭐

Add each character to a LinkedHashSet<Character> to keep the first occurrence in order, then join them back.

Learn more: remove duplicate characters

Q27. How do you find the first non-repeated character? ⭐

Count characters in a LinkedHashMap (which keeps insertion order), then return the first with a count of one. Complexity: O(n).

public static Character firstNonRepeated(String s) {
    Map<Character, Integer> freq = new LinkedHashMap<>();
    for (char ch : s.toCharArray()) {
        freq.merge(ch, 1, Integer::sum);
    }

    for (Map.Entry<Character, Integer> e : freq.entrySet()) {
        if (e.getValue() == 1) return e.getKey();
    }

    return null;   // every character repeats
}
// firstNonRepeated("swiss") → 'w'

Q28. How do you reverse each word in a sentence? ⭐

Split on whitespace, reverse each word with StringBuilder, and join them back.

public static String reverseEachWord(String sentence) {
    StringBuilder out = new StringBuilder();

    for (String word : sentence.trim().split("\\s+")) {
        out.append(new StringBuilder(word).reverse()).append(' ');
    }

    return out.toString().trim();
}
// reverseEachWord("Java for testers") → "avaJ rof sretset"

Learn more: reverse each word · reverse word order

Q29. How do you count word frequency in a sentence?

Lowercase, split on \\s+, and count with HashMap.merge(). Complexity: O(n).

Code: Pattern 3 in the coding programs guide · full tutorial

Q30. How do you check whether two strings are anagrams? ⭐

Normalize both strings, then compare character counts (O(n)) — or sort both and compare (O(n log n)).

// letters a–z only, after removing spaces and lowercasing
public static boolean isAnagram(String a, String b) {
    String x = a.replaceAll("\\s", "").toLowerCase();
    String y = b.replaceAll("\\s", "").toLowerCase();

    if (x.length() != y.length()) return false;

    int[] count = new int[26];

    for (int i = 0; i < x.length(); i++) {
        count[x.charAt(i) - 'a']++;
        count[y.charAt(i) - 'a']--;
    }

    for (int c : count) {
        if (c != 0) return false;
    }

    return true;
}
// isAnagram("Listen", "Silent") → true

Learn more: String Advanced · anagram (4 methods)

Bonus: 4 SDET-Specific Coding Tasks

Mid-level SDET interviews increasingly ask for code you would actually use in a test framework. These show you can apply Java to automation, not just puzzles.

B1. Verify that a list of UI values is sorted

Typical use: after clicking "Sort by name", collect the column's text and assert it's in order.

public static boolean isSortedAscending(List<String> values) {
    for (int i = 1; i < values.size(); i++) {
        if (values.get(i - 1).compareToIgnoreCase(values.get(i)) > 0) {
            return false;
        }
    }
    return true;
}

B2. Compare expected and actual values ignoring order

Typical use: checking a dropdown or menu contains exactly the expected options. Sorting copies keeps duplicates meaningful.

public static boolean sameElements(List<String> expected, List<String> actual) {
    List<String> a = new ArrayList<>(expected);
    List<String> b = new ArrayList<>(actual);

    Collections.sort(a);
    Collections.sort(b);

    return a.equals(b);
}

B3. Sort a list of objects by a field

Typical use: sorting test data or API response objects before comparing them.

record Employee(String name, int salary) {}

List<Employee> staff = new ArrayList<>(List.of(
        new Employee("Asha", 72000),
        new Employee("Ravi", 65000),
        new Employee("Meera", 90000)
));

staff.sort(Comparator.comparingInt(Employee::salary).reversed());

// staff.get(0).name() → "Meera"

B4. Count occurrences with streams

Typical use: summarizing status codes from a batch of API calls or results from a test run.

List<Integer> statusCodes = List.of(200, 404, 200, 500, 200, 404);

Map<Integer, Long> counts = statusCodes.stream()
        .collect(Collectors.groupingBy(
                code -> code,
                TreeMap::new,
                Collectors.counting()
        ));

// counts → {200=3, 404=2, 500=1}

How to Prepare for the Coding Round

  • Write programs from memory without an IDE — use paper or a plain editor for practice.
  • Learn the brute-force and the optimized approach, and be able to explain the difference.
  • Think out loud: interviewers score your reasoning, not just the final code.
  • Dry-run with a sample input, then test edge cases: null, empty, one element, duplicates, negatives.
  • Always state time and space complexity when you finish.
  • Run your practice code in the Java Online Compiler and take timed rounds in the Java Interview Simulator.

From Real Projects

In the automation roles I've worked in, coding was always practical: Selenium WebDriver scripts in Java, TestNG annotations, groups and data from Excel through Apache POI, and page classes in a POM-based hybrid framework. That's why interviewers for SDET and automation roles usually pair a coding problem with framework questions. When you solve a problem here, practice explaining how you'd use the same idea in a test — for example, comparing two lists of values read from a page, or finding duplicates in test data.

📚 Official documentation: dev.java: Learn Java (Oracle) · Java 21 API documentation

Frequently Asked Questions

How difficult is the coding round in SDET interviews?

For most automation and SDET roles it is easier than a software developer interview: array, string and number programs with basic collections. Product companies may add harder problems, but the fundamentals on this page cover the majority of rounds.

Should I use Java 8 streams in the coding round?

Write a loop-based solution first so your logic is visible, then mention the stream version as an alternative. Use streams freely for SDET tasks like B4, where they're the natural choice.

Which language should I use for the SDET coding round?

Use the language of your automation framework — usually Java for Selenium and REST Assured roles, or JavaScript/TypeScript for Playwright roles. Most companies let you choose.

How many coding questions should I practice?

Master these 30 plus the four SDET tasks until you can write each from memory and explain its complexity. That covers most service- and product-company coding rounds for automation roles.

Next Steps