Interview Q&A Selenium Tutorial for Beginners

Selenium Automation Interview questions | Java algorithms 11-15

As soon as you write Selenium Java in your resume, interviewer is bound to give you a sheet of paper & ask write a Java program. Though Selenium doesn’t require extensive Java knowledge but still there is a set of basic Java programs that you should be able to write on-the-spot. Continuing on our Java interview series for Selenium Automation, this article covers five of the common Java programs frequently asked in the basic technical interview. 

Selenium Java Interview Algorithms

The questions are easy, but don’t forget to mark these java-program in your to do list before attending any entry-level technical interview for Selenium automation testing.

Flashback: Selenium Automation Interview Questions | Java Algorithms 6-10

Java program | Remove Duplicate numbers

One of the simple, yet common algorithms – given an array of numbers, write a program to remove the duplicates. As you might have guessed, the logic is quite simple – compare the current element with further elements until you find a duplicate OR identify its uniqueness. Keep adding the unique elements to the output array.

Reverse a number

This particular algorithm takes me back to school days. How will you reverse a number? Or rather how will you extract the last digit of a particular number? Simple, keep the remainder after diving it by 10. Now that you have extracted the last digit, what’s next? Yeah! Remove the last digit and iterate until you get to the first digit. And how do you remove the last digit keeping all other digits as-is? Yeah! Divide the number by 10 to get an integer value.

Calculate the sum of first 1000 Prime numbers

A number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11). The thumb rule – Every number is divisible by 1 and won’t be divisible by any number greater than n/2. Take the opposite route to identify if the number is prime, i.e. try dividing the number by 2, 3, 4…until n/2. If it is divisible, mark it as not prime – else if the loop ends, it is a prime number. At last, keep adding all the prime numbers from 1 to 1000.

Swap two numbers without using temporary variable

The general way to swap two numbers is to use a temporary variable to hold value of either one. But this program asks us specifically to swap two numbers without using a temporary variable. How? Again, it’s a simple mathematics trick.

  • A = 10, B = 20;
  • A = A + B, i.e. A = 30
  • B = A – B, i.e. 30 – 20 = 10
  • A = A – B, i.e. 30 – 10 = 20

Finally A = 20, B = 10. Simple right?

Identify two max numbers

Out of a given array of numbers, identify the two maximum numbers. Initially let’s take the maxOne & maxTwo as 0. Now iterate through the array comparing the current element’s value first with maxOne and then with maxTwo.

  • If its greater than maxOne, copy maxOne to maxTwo and element to maxOne.
  • If its greater than maxTwo, copy the element to maxTwo
  • If it is not greater than either maxOne & maxTwo, move on.

These are just some simple programs related to array processing. Very simple, in fact. But something is better than nothing. It’s never too late to start learning something new. Forget the notion of “Software Testers need not program”. In today’s competitive era, we as Software Testers need to adapt to changing times & at least learn the basics of programming. At least!

Leave a Reply

Your email address will not be published. Required fields are marked *