SAP
30+ Servotech Power Systems Interview Questions and Answers
Q1. Duplicate Integer in Array
Given an array ARR
of size N
, containing each number between 1 and N-1
at least once, identify the single integer that appears twice.
Input:
The first line contains an integer, 'T', r...read more
Identify the duplicate integer in an array containing numbers between 1 and N-1.
Iterate through the array and keep track of the frequency of each element using a hashmap.
Return the element with a frequency greater than 1 as the duplicate integer.
Time complexity can be optimized to O(N) using Floyd's Tortoise and Hare algorithm.
Example: For input [1, 2, 3, 4, 4], the output should be 4.
Q2. Overlapping Intervals Problem Statement
You are given the start and end times of 'N' intervals. Write a function to determine if any two intervals overlap.
Note:
If an interval ends at time T and another interv...read more
Given start and end times of intervals, determine if any two intervals overlap.
Iterate through intervals and check if any two intervals overlap by comparing their start and end times
Sort intervals based on start times for efficient comparison
Consider edge cases where intervals end and start at the same time
Q3. Covid Vaccination Distribution Problem
As the Government ramps up vaccination drives to combat the second wave of Covid-19, you are tasked with helping plan an effective vaccination schedule. Your goal is to ma...read more
Maximize the number of vaccines administered on a specific day while adhering to certain rules.
Given n days, maxVaccines available, and a specific dayNumber, distribute vaccines to maximize on dayNumber
Administer positive number of vaccines each day with a difference of 1 between consecutive days
Ensure sum of vaccines distributed does not exceed maxVaccines
Output the maximum number of vaccines administered on dayNumber for each test case
Q4. Level Order Traversal Problem Statement
Given a binary tree of integers, return the level order traversal of the binary tree.
Input:
The first line contains an integer 'T', representing the number of test cases...read more
The task is to implement a function that returns the level order traversal of a binary tree given in level order.
Create a queue to store nodes for level order traversal
Start with the root node and enqueue it
While the queue is not empty, dequeue a node, print its value, and enqueue its children
Repeat until all nodes are traversed
Q5. Longest Increasing Subsequence Problem Statement
Given 'N' students standing in a row with specific heights, your task is to find the length of the longest strictly increasing subsequence of their heights, ensu...read more
Find the length of the longest strictly increasing subsequence of heights of students in a row.
Iterate through the heights array and for each element, find the length of the longest increasing subsequence ending at that element.
Use dynamic programming to keep track of the longest increasing subsequence length for each element.
Return the maximum length found as the result.
Q6. Merge Sort Problem Statement
You are given a sequence of numbers, ARR
. Your task is to return a sorted sequence of ARR
in non-descending order using the Merge Sort algorithm.
Explanation:
The Merge Sort algorit...read more
Implement Merge Sort algorithm to sort a sequence of numbers in non-descending order.
Divide the input array into two halves recursively until each array has only one element.
Merge the sorted halves to produce a completely sorted array.
Time complexity of Merge Sort is O(n log n).
Example: Input: [3, 1, 4, 1, 5], Output: [1, 1, 3, 4, 5]
Q7. Zig-Zag String Problem Statement
Given a string STR
of size N
and an integer M
representing the number of rows in the zig-zag pattern, return the string formed by concatenating all rows when the string STR
is w...read more
Arrange a string in zig-zag pattern with given number of rows and concatenate the rows.
Iterate through the string and distribute characters to rows based on zig-zag pattern
Concatenate the characters in each row to get the final result
Handle edge cases like when number of rows is 1 or equal to the length of the string
Q8. Floyd Warshall Algorithm Problem
You are given a directed weighted graph with 'N' vertices, labeled from 1 to 'N', and 'M' edges. Each edge connects two nodes 'u' and 'v' with a weight 'w', representing the dis...read more
The Floyd Warshall algorithm is used to find the shortest paths between all pairs of vertices in a graph, including graphs with negative edge weights.
The algorithm works by considering all pairs of vertices and all intermediate vertices to find the shortest path.
It can handle graphs with negative edge weights, but not negative weight cycles.
The time complexity of the algorithm is O(N^3), where N is the number of vertices.
Example: Given a graph with 4 vertices and 5 edges, fin...read more
Q9. Longest Unique Substring Problem Statement
Given a string input of length 'n', your task is to determine the length of the longest substring that contains no repeating characters.
Explanation:
A substring is a ...read more
Find the length of the longest substring with unique characters in a given string.
Use a sliding window approach to keep track of the longest substring without repeating characters.
Use a hashmap to store the index of each character in the string.
Update the start index of the window when a repeating character is encountered.
Calculate the maximum length of the window as you iterate through the string.
Q10. Binary Pattern Problem Statement
Given an input integer N
, your task is to print a binary pattern as follows:
Example:
Input:
N = 4
Output:
1111
000
11
0
Explanation:
The first line contains 'N' 1s. The next line ...read more
Print a binary pattern based on input integer N in a specific format.
Iterate from 1 to N and print N - i + 1 numbers alternatively as 1 or 0 in each line
Follow the pattern of increasing 1s and decreasing 0s in each line
Handle the number of test cases and constraints as specified
Two people with torch cross, one returns, two faster people cross, one with torch returns, two slower people cross.
Two slower people cross first (A and B), A returns with torch (1 minute)
Two faster people cross (C and D), B returns with torch (2 minutes)
Two slower people cross last (A and B) (10 minutes)
Q12. Print Permutations - String Problem Statement
Given an input string 'S', you are tasked with finding and returning all possible permutations of the input string.
Input:
The first and only line of input contains...read more
Return all possible permutations of a given input string.
Use recursion to generate all possible permutations of the input string.
Swap characters at different positions to generate permutations.
Handle duplicate characters in the input string by using a set to store unique permutations.
Q13. Factorial of a Number Problem Statement
You are provided with an integer 'N'. Your task is to calculate and print the factorial of 'N'. The factorial of a number 'N', denoted as N!, is the product of all positi...read more
Calculate and print the factorial of a given integer 'N'.
Iterate from 1 to N and multiply each number to calculate factorial
Handle edge cases like N=0 or N=1 separately
Use recursion to calculate factorial efficiently
Q14. Bubble Sort Problem Statement
Sort the given unsorted array consisting of N non-negative integers in non-decreasing order using the Bubble Sort algorithm.
Input:
The first line contains an integer 'T' represent...read more
Bubble Sort algorithm is used to sort an array of non-negative integers in non-decreasing order.
Iterate through the array and compare adjacent elements, swapping them if they are in the wrong order.
Repeat this process until the array is sorted.
Time complexity of Bubble Sort is O(n^2) in worst case.
Space complexity of Bubble Sort is O(1) as it is an in-place sorting algorithm.
Q15. Remove Consecutive Duplicates Problem Statement
Given a string S, your task is to recursively remove all consecutive duplicate characters from the string.
Input:
String S
Output:
Output string
Constraints:
- 1 <...read more
Recursively remove consecutive duplicate characters from a string.
Use recursion to check if the current character is the same as the next character, if so skip the next character
Base case: if the string is empty or has only one character, return the string
Example: Input: 'aaabcc', Output: 'abc'
Primary key uniquely identifies each record in a table, while unique key ensures that all values in a column are distinct.
Primary key does not allow NULL values, while unique key allows one NULL value.
A table can have only one primary key, but multiple unique keys.
Primary key is automatically indexed, while unique key may or may not be indexed.
Example: In a table of students, student ID can be a primary key as it uniquely identifies each student, while email address can be a ...read more
Q17. What is polymorphism? Explain using a real life example
Polymorphism is the ability of an object to take on many forms. It allows objects of different classes to be treated as the same type.
Polymorphism allows a single interface to be used for different types of objects.
It enables code reusability and flexibility in object-oriented programming.
For example, a parent class 'Animal' can have multiple child classes like 'Dog', 'Cat', and 'Bird'. They can all be treated as 'Animal' objects.
Each child class can have its own implementati...read more
The database design for an ATM system should include tables for users, accounts, transactions, and ATM machines.
Create a table for users with fields like user_id, name, pin, etc.
Create a table for accounts with fields like account_id, user_id, balance, etc.
Create a table for transactions with fields like transaction_id, account_id, amount, date, etc.
Create a table for ATM machines with fields like atm_id, location, status, etc.
AES is a more secure and efficient cipher compared to DES.
AES has a block size of 128 bits, while DES has a block size of 64 bits.
AES supports key sizes of 128, 192, or 256 bits, while DES supports only 56-bit keys.
AES is considered more secure and efficient than DES due to its stronger encryption algorithm and larger key sizes.
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity.
Normalization involves breaking down a database into smaller, more manageable tables.
It helps in reducing data redundancy by storing data in a structured way.
There are different normal forms such as 1NF, 2NF, 3NF, BCNF, etc., each with specific rules to follow.
Normalization ensures data integrity and reduces the chances of anomalies like insertion, update, and deletio...read more
Public cloud is shared infrastructure available to anyone, while private cloud is dedicated infrastructure for a single organization.
Public cloud is accessible to multiple organizations or users, while private cloud is exclusive to a single organization.
Public cloud services are provided over the internet, while private cloud services can be hosted on-premises or in a dedicated data center.
Public cloud offers cost-effective scalability and flexibility, while private cloud off...read more
Various SQL queries related to data manipulation and retrieval were asked during the interview.
Basic SELECT queries to retrieve data from a single table
JOIN queries to retrieve data from multiple tables based on a common column
Aggregate functions like COUNT, SUM, AVG, etc. to perform calculations on data
Subqueries to retrieve data based on the result of another query
UPDATE queries to modify existing data in a table
DELETE queries to remove specific records from a table
Query to find the nth highest salary in a database
Use the ORDER BY clause to sort salaries in descending order
Use the LIMIT clause to specify the nth highest salary
Consider handling cases where there may be ties for the nth highest salary
RDBMS is a type of DBMS that manages data in a structured format using tables with relationships.
RDBMS enforces referential integrity through foreign keys, while DBMS does not.
RDBMS supports ACID properties (Atomicity, Consistency, Isolation, Durability), while DBMS may not.
RDBMS allows for normalization of data to reduce redundancy, while DBMS does not have this feature.
Examples of RDBMS include MySQL, Oracle, SQL Server. Examples of DBMS include Microsoft Access, FoxPro.
Design an e-commerce website similar to Flipkart or Amazon.
Implement user-friendly interface for easy navigation
Include search functionality with filters for products
Incorporate secure payment gateway for transactions
Provide personalized recommendations based on user behavior
Include customer reviews and ratings for products
Implement order tracking and delivery status updates
Offer various payment options like credit/debit cards, net banking, and COD
Q26. What is inheritance?
Inheritance is a concept in object-oriented programming where a class inherits properties and behaviors from another class.
Inheritance allows for code reuse and promotes modularity.
The class that is being inherited from is called the superclass or base class.
The class that inherits from the superclass is called the subclass or derived class.
The subclass can access the public and protected members of the superclass.
Inheritance can be single, where a subclass inherits from only...read more
A semaphore is a synchronization construct used to control access to a shared resource by multiple processes or threads.
Semaphores can have an integer value representing the number of available resources.
They can be used to implement mutual exclusion and synchronization between processes.
Examples include binary semaphores (mutexes) and counting semaphores.
Operations on semaphores include wait (P) and signal (V).
Q28. Maximum area rectangle of 1s in a binary matrix
Find the maximum area rectangle of 1s in a binary matrix.
Iterate through each row of the matrix and calculate the maximum area of rectangle with that row as the base.
Use a stack to keep track of the indices of the rows with increasing heights.
For each row, calculate the area of rectangle with that row as the height and update the maximum area.
Q29. Regular expressions in PhP
Regular expressions in PHP are powerful tools for pattern matching and manipulating strings.
Regular expressions are defined using the preg_match() function in PHP.
They are used to search, replace, and validate strings based on specific patterns.
Regex patterns consist of a combination of characters and special symbols.
Modifiers can be added to the pattern to control the matching behavior.
Common regex functions in PHP include preg_match(), preg_replace(), and preg_split().
Q30. K-reverse a linked list
Reverses every k nodes in a linked list
Iterate through the linked list in groups of k nodes
Reverse each group of k nodes
Connect the reversed groups back together
More about working at SAP
Top HR Questions asked in Servotech Power Systems
Interview Process at Servotech Power Systems
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month