10X Sale
kh logo
All Courses

Introduction

A senior software engineer is an experienced software developer who has demonstrated expertise in designing, developing, testing, and maintaining complex software systems. They have advanced technical skills and a strong knowledge of programming languages, software development methodologies, and software engineering best practices. The question comprises both interview questions for beginners and advanced senior software interview questions. The questions are segmented in various topics including programming languages, OOPS concepts, software development methodologies, data structure, database management, and more. Our senior software engineer interview questions and answers will help you prepare with confidence to ace any interview.

Senior Software Engineer Interview Questions and Answers
Beginner

1. How is a bubble sort algorithm implemented?

The basic sorting method known as a bubble sort involves periodically switching nearby entries in an array. Because of its high average and worst-case temporal complexity, this is not appropriate for processing large amounts of data. Bubble sort tries to solve this by first comparing adjacent elements. If the element being compared is smaller than a given threshold value, the larger one is swapped with it and vice versa if the element being compared is larger than that threshold value. Thus samples are evaluated using less space than they used to be before the swap process started, hence making this algorithm faster than its variants such as heap sort or quick sort.

Implementation of bubble sort

Our example uses an unsorted array. Because bubble sort requires O(n2) time, we're making it concise and direct.

bubble sort algorithm

The first two items in a bubble sort are compared to see which one is bigger in the beginning.

bubble sort algorithm

Value 33 is bigger than 14, therefore, which is already in sorted places in this instance.

bubble sort algorithm

We now compare 33 with 27. Since 27 is less than 33, these two numbers must be switched.

bubble sort algorithm

The resulting array should seem as follows:

bubble sort algorithm

Let's next evaluate 33 and 35. These are already in ordered places, as we discover.

bubble sort algorithm

Afterward, we get to the further two values: 35 and 10.

bubble sort algorithm

However, we knew that 10 is less than 35. So they really aren't sorted as a result.

bubble sort algorithm

The values are switched. We discover that the array's end has been approached. The array shall seem as follows after the first iterative process:

bubble sort algorithm

We are specifically demonstrating the state of an array following each loop right now. After the second revision, it ought to resemble this:

bubble sort algorithm

Remember that at least a single value shifts at the end of every iteration.

bubble sort algorithm

Additionally, bubble sorts discover that an array is fully sorted when no switch is necessary. shown here

bubble sort algorithm

Program :

import java.util.Arrays; 
public class BubbleSort 
{ 
public static void main(String args[])
{
bubbleSort(new int[] { 20, 12, 45, 19, 91, 55 });
bubbleSort(new int[] { -1, 0, 1 });
bubbleSort(new int[] { -3, -9, -2, -1 });
} 
public static void bubbleSort(int[] numbers) 
 {
System.out.printf("Unsorted array in Java :%s %n", Arrays.toString(numbers));
for (int i = 0; i < numbers.length; i++) { 
for (int j = numbers.length -1; j > i; j--) { 
if (numbers[j] < numbers[j - 1]) { 
swap(numbers, j, j-1);
} 
} 
}
System.out.printf("Sorted Array using Bubble sort algorithm :%s %n", Arrays.toString(numbers)); 
} 
public static void swap(int[] array, int from, int to){ 
int temp = array[from]; 
array[from] = array[to];
array[to] = temp; 
} 
}

Output:

Unsorted array in Java : [20, 12, 45, 19, 91, 55]

Sorted Array using Bubble sort algorithm : [12, 19, 20, 45, 55, 91]

Unsorted array in Java : [-1, 0, 1]

Sorted Array using Bubble sort algorithm : [-1, 0, 1]

Unsorted array in Java : [-3, -9, -2, -1]

Sorted Array using Bubble sort algorithm : [-9, -3, -2, -1]

2. How is a merge sort algorithm implemented?

A Divide and Conquer is an algorithm that splits the problem into smaller parts and solves them completely before combining the solutions. Merge Sort is a Divide and Conquer algorithm, which divides input arrays in two halves and merges these halves efficiently over a vector. 

The divide-and-conquer approach is a problem-solving paradigm that addresses problems across different areas of expertise. 

Implementation 

Let's have a look at an array with the values arr[] = 38, 27, 43, 3, 9, 82, 10 to understand how merge sort works. 

Firstly determine whether the array's left index is lower than its right index; if so, get the array's midway point. 

merge sort algorithm

However, since we already knew, until the atomic values are attained, merge sort consists of dividing arrays into equivalent parts repeatedly first. 

In this, one could see that a 7-item array is split up into two arrays with sizes of 4 and 3, accordingly. 

merge sort algorithm

Find out once more if the left index for both arrays is lower than the right index, and if so, determine the centroid for both arrays once more. 

merge sort algorithm

Furthermore, keep dividing these two arrays into smaller and smaller parts until the array's atomic units are achieved, and more subdivision becomes impossible. 

merge sort algorithm

Begin combining the items once more, relying on comparisons of element sizes following dividing the array into the smallest units. 

To integrate the elements from two lists into one, you must examine each list's elements first. 

merge sort algorithm

Following the final merger, the list appears as follows: 

merge sort algorithm

Program:

class MergeSort 

{ 
void merge(int arr[], int l, int m, int r) 
{ 
int n1 = m - l + 1; 
int n2 = r - m; 
int L[] = new int [n1]; 
int R[] = new int [n2]; 
for (int i=0; i<n1; ++i) 
L[i] = arr[l + i]; 
for (int j=0; j<n2; ++j) 
R[j] = arr[m + 1+ j]; 
int i = 0, j = 0; 
int k = l; 
while (i < n1 && j < n2) 
{ 
if (L[i] <= R[j]) 
{ 
arr[k] = L[i]; 
i++; 
} 
else 
{ 
arr[k] = R[j]; 
j++; 
} 
k++; 
} 
while (i < n1) 
{ 
arr[k] = L[i]; 
i++; 
k++; 
} 
while (j < n2) 
{ 
arr[k] = R[j]; 
j++; 
k++; 
} 
} 
void sort(int arr[], int l, int r) 
{ 
if (l < r) 
{ 
int m = (l+r)/2; 
sort(arr, l, m); 
sort(arr , m+1, r); 
merge(arr, l, m, r); 
} 
} 
static void printArray(int arr[]) 
{ 
int n = arr.length; 
for (int i=0; i<n; ++i) 
System.out.print(arr[i] + " "); 
System.out.println(); 
} 
public static void main(String args[]) 
{ 
int arr[] = {12, 11, 13, 5, 6, 7}; 
System.out.println("Given Array is :"); 
printArray(arr); 
MergeSort ob = new MergeSort(); 
ob.sort(arr, 0, arr.length-1); 
System.out.println("\nSorted array is:"); 
printArray(arr); 
} 
} 

Output:

Given array is
12 11 13 5 6 7
Sorted array is
5 6 7 11 12 13 

3. How do you count the occurrence of a given character in a string?

Expect to come across this popular question in senior software engineer technical interview questions.

In the given problem, we need to count the occurrences of a given character in a string. In any programming language, this problem can have multiple solutions. Let's explain this problem a little bit further. There are numerous ways to determine the frequency of each letter, including Naive Approach, Counter Array, Java HashMap, and Java 8. 

 Here is a general working of a solution or, in more technical term, an algorithm for the problem 

  1. Set up a counter variable to keep track of the total number of times a character appears in a string. 
  2. Letter by letter, go through the entire String. 
  3. If somehow the letter in the sequence matched the designated letter, raise the value of the count parameter. 
  4. Finally, revert back to the counter variable 

For this approach, we use the StringUtils class from the Spring framework, whose static method countOccurrenceOf(String, character) accepts a Text as input and a letter and outputs the character's frequency in that Text. 

As an alternative, the Apache Commons StringUtils class for calculating the frequency of a letter in a sentence can be used to resolve this specific issue. To calculate the instances of a specific character or sub-string, use the countMatches() method of the Apache Commons StringUtils.

Program 

import org.springframework.util.StringUtils; 
public class CountCharacters { 
    public static void main(String args[]) { 
        String input = "Today is Monday"; 
        int count = StringUtils.countOccurrencesOf(input, "a"); 
        System.out.println("count of occurrence of character 'a' on String: " + " Today is Monday' using Spring StringUtils " + count); 
 int number = org.apache.commons.lang.StringUtils.countMatches(input, "a"); 
        System.out.println("count of character 'a' on String: 'Today is Monday' using commons StringUtils " + number); 
             int charCount = 0; 
        for(int i =0 ; i<input.length(); i++){ 
            if(input.charAt(i) == 'a'){ 
                charCount++; 
            } 
        } 
        System.out.println("count of character 'a' on String: 'Today is Monday' using for loop  " + charCount);  
        charCount = 0; //resetting character count 
        for(char ch: input.toCharArray()){ 
            if(ch == 'a'){ 
                charCount++; 
            } 
        }     
        System.out.println("count of character 'a' on String: 'Today is Monday' using for each loop  " + charCount); 
    }    
}

Output 

count of occurrence of the character 'a' on String: 'Today is Monday' using Spring StringUtils 2
count of character 'a' on String: 'Today is Monday' using commons StringUtils 2
count of character 'a' on String: 'Today is Monday' using for loop 2
count of character 'a' on String: 'Today is Monday' using for each loop 2

4. How do you print the first non-repeated character from a string?

Locating the very first non-repeated letter in a Sequence of String is a frequent programming exam question. But since the concept of strings is frequently covered in coding jobs, it is best to practice with very well topics like flipping strings with recursion or determining whether a string is a palindrome. 

Dealing with all the non-repeated characters such as w, x, and y is a common problem in computational linguistics. Making a chart to hold the total of every character and selecting the very first entry that is unique will solve these issues. 

Working 

 The solution above is implemented in the getFirstNonRepeatedChar(String str) method: The character array is looped through, and each element is compared to the index of the first non-repeated character. If there is a match, then that character's count will be stored in a hash table with its corresponding position as the key and that index as the value. 

Since LinkedHashMap retains insertion order, next iterates through all the character arrays from start to finish in the following sequence to identify an item with value 1, which is your initial non-repeated character. First, it iterates through the remaining elements. Then it checks if the current character equals the value. If yes, then it concatenates the current character and repeated char. If not, then it returns a null value. 

Program 

import java.io.IOException;  
import java.util.ArrayList;  
import java.util.HashMap;  
import java.util.HashSet;  
import java.util.LinkedHashMap;  
import java.util.List;  
import java.util.Map;  
import java.util.Map.Entry;  
import java.util.Set; 
public class Programming { 
public static char getFirstNonRepeatedChar(String str) {  
Map<Character,Integer> counts = new LinkedHashMap<>(str.length()); 
for (char c : str.toCharArray()) {  
counts.put(c, counts.containsKey(c) ? counts.get(c) + 1 : 1);  
} 
for (Entry<Character,Integer> entry : counts.entrySet()) {  
if (entry.getValue() == 1) {  
return entry.getKey(); 
} 
} 
throw new RuntimeException("didn't find any non repeated Character"); 
} 
public static char firstNonRepeatingChar(String word) {  
Set<Character> repeating = new HashSet<>(); 
List<Character> nonRepeating = new ArrayList<>();  
for (int i = 0; i < word.length(); i++) { 
     char letter = word.charAt(i); 
            if (repeating.contains(letter)) { 
    continue; 
} 
if (nonRepeating.contains(letter)) {  
nonRepeating.remove((Character) letter);  
repeating.add(letter); 
 } else {  
    nonRepeating.add(letter);  
 
 
return nonRepeating.get(0);  
} 
public static char firstNonRepeatedCharacter(String word) {  
HashMap<Character,Integer> scoreboard = new HashMap<>(); 
for (int i = 0; i < word.length(); i++) {  
      char c = word.charAt(i);  
      if (scoreboard.containsKey(c)) {  
                    scoreboard.put(c, scoreboard.get(c) + 1);  
                } else { 
         scoreboard.put(c, 1);  
               }  
       } 
for (int i = 0; i < word.length(); i++) { 
            char c = word.charAt(i); 
            if (scoreboard.get(c) == 1) { 
                return c; 
            } 
        } 
        throw new RuntimeException("Undefined behavior"); 
    } 
} 

Output:

Enter the string: ssss 

didn't find any non-repeated Character 

Enter the string: missing 

First non-repeating character is m 

5. How do you convert a given String into int like the atoi()?

One of the fundamental Java duties is turning strings to integers and integers to strings, and most individuals learned about this while studying the Programming language. Provided that String and Integer are the most commonly applied types in all kinds of applications and you frequently get data between either of these types, even though String to Integer as well as Integer to String conversion is simple things at the same time, it was most helpful because of its regular necessity.

There are various methods for converting an int value to a string. If the last example of string conversion didn't suit you, here is one given below.

For this instance of turning an integer into a string, we utilized the static utility method String.valueOf(), which allows us to turn any integer variable into a string.

Since the String.valueOf() function is extended to handle practically every primitive type, you may utilize it to transform any other data type—including char, double, and float—into a String. Java uses static binding to invoke the appropriate method. Here is an example utilizing String.valueOf to convert an int to a string ()

Price as a string = Price.valueOf(123);

When the above line is executed, the integer 123 will be changed to the string "123".

Program

class GFG {
static int myAtoi(String str)
{
if (str == "" || str.matches("[a-zA-Z]+") || str.matches(".*[0-9].*")) {
return 0;
}
int res = 0;
for (int i = 0; i < str.length(); ++i)
res = res * 10 + str.charAt(i) - '0';
return res;
}
public static void main(String[] args)
{
String str = "8f9789";
// Function call
int val = myAtoi(str);
System.out.println(val);
}
}

Output:

String = 1234
Integer value = 1234

String = 123s
Invalid String
Integer value = 0

Want to Know More?
+91

By Signing up, you agree to ourTerms & Conditionsand ourPrivacy and Policy

Description

A senior software developer has several roles and responsibilities apart from coding. Hence, the recruiter judges a senior software engineer an applicant on both concept base and job base questions. In addition, by asking senior software developer interview questions based on the job, they note your personality, experience, and qualifications for the position you are applying for. To ace your following interview, ensure you grasp the principal software engineer interview questions mentioned in this article. Moreover, we would recommend you enrich your answer with confidence and clarity. Finally, make sure you have mastered communication skills as well.

These last few days' preparations will help you with your senior software engineer interview. However, suppose you have more time on hand. In that case, you can always look into some of the best full-stack web developer BootCamp. These courses will clear out your basics and advanced level concepts in the field of web development and prepare you for placements in companies offering a high salary.

There are several good courses out there, of which we would recommend the Full Stack Web Development course with KnowledgeHut. One can develop in-demand skills from the ground level through this full-stack development course. The course has several lectures recorded and in-class live training to make you job-ready.

Coming back to the interview, as long as you are good with these senior software engineer interview questions and answers and have researched well regarding the company you are applying for, you have a high chance of landing your dream job. You can also research your interviewer to know the senior set of interview questions they can put up.

As a senior software developer, you might have seen several interviews already, and you would know how important a last-night checklist is. Look at your resume, cover letter, and job description the day before your interview. Give attention to minute details.

Before going for the interview, be hundred and one percent sure of a few things:

  1. You should always carry a physical copy of your resume to the interview.
  2. The impression does matter. Interviewees can know your personality from the way you talk, the way you walk, the way you sit, and the way you dress. Your dress code should be formal.
  3. No matter the situation, try your best to arrive at the interview on time.

After appearing for the interview, leave a thank you note to your interviewers. In addition, craft a customized thank you note by mentioning your learning experience in the interview. If there are multiple interviewers, have a thank you note for each. These tips and tricks will help boost your confidence in the interview. But, of course, the rest depends on your preparation and skills.

Recommended Courses

Learners Enrolled For
CTA
Got more questions? We've got answers.
Book Your Free Counselling Session Today.