Software Engineer Interview Questions
Practice with real Software Engineer interview questions
01
A Software Engineer was asked
Asked in 2024
Q. What is recursion in algorithms, and how would you implement a function to calculate Fibonacci numbers using recursion?
Ans. Recursion is a programming technique where a function calls itself in order to solve a problem. It is often used for problems that can be broken down into smaller, similar sub-problems. The Fibonacci sequence is a classic example where each number is the sum of the two preceding ones.
Here’s how you can implement a recursive function to calculate Fibonacci numbers:
In this implementation, the base cases handle the scenarios for
n = 0 and n = 1. The recursive case calls the fibonacci function twice, leading to an exponential time complexity. It is important to note that this naive implementation can be inefficient for larger values of n due to repeated calculations. For improvement, memoization or an iterative approach can be utilized.Software EngineerCore Concept
02
A Software Engineer was asked
Asked in 2024
Q. What is the purpose of the GROUP BY clause in SQL? Provide an example using aggregated functions.
Ans. The GROUP BY clause in SQL is used to arrange identical data into groups and is often used with aggregate functions like COUNT, SUM, AVG, MAX, and MIN.
Example:
This query counts the number of employees in each department. If you want to get the average salary per department, you can do:
This will give you the average salary for each department, demonstrating how GROUP BY can be used effectively with aggregate functions.
Software EngineerCore Concept
