Siemens
20+ KJ System Interview Questions and Answers
Q1. Count Inversions Problem Statement
Given an integer array ARR
of size N
, your task is to find the total number of inversions that exist in the array.
An inversion is defined for a pair of integers in the array ...read more
Count the total number of inversions in an integer array.
Iterate through the array and for each pair of indices i and j, check if ARR[i] > ARR[j] and i < j.
Use a nested loop to compare all pairs of elements in the array.
Keep a count of the inversions found and return the total count at the end.
Q2. Maximum Subarray Sum Problem Statement
Given an array arr
of length N
consisting of integers, find the sum of the subarray (including empty subarray) with the maximum sum among all subarrays.
Explanation:
A sub...read more
Find the sum of the subarray with the maximum sum among all subarrays in an array of integers.
Iterate through the array and keep track of the current sum and maximum sum.
If the current sum becomes negative, reset it to 0.
Return the maximum sum found.
Q3. Remove Character from String Problem Statement
Given a string str
and a character 'X', develop a function to eliminate all instances of 'X' from str
and return the resulting string.
Input:
The first line contai...read more
Develop a function to remove all instances of a given character from a string.
Iterate through the string character by character and exclude the specified character while constructing the new string.
Use a StringBuilder or similar data structure for efficient string manipulation.
Handle edge cases such as empty string or character not found in the input string.
Ensure the function runs in O(N) time complexity where N is the length of the input string.
Q4. Maximum Length Pair Chain Problem Statement
You are provided with 'N' pairs of integers such that in any given pair (a, b), the first number is always smaller than the second number, i.e., a < b. A pair chain i...read more
Find the length of the longest pair chain that can be formed using given pairs.
Sort the pairs based on the second element in increasing order.
Iterate through the sorted pairs and keep track of the maximum chain length.
Update the chain length if the current pair can be added to the chain.
Return the maximum chain length at the end.
The ants will eventually meet at the centroid of the triangle.
The ants will move along the medians of the triangle towards each other.
They will meet at the centroid, which is the point of intersection of the medians.
This is because the centroid divides each median into a 2:1 ratio.
Q6. Search In Rotated Sorted Array Problem Statement
Given a rotated sorted array ARR
of size 'N' and an integer 'K', determine the index at which 'K' is present in the array.
Note:
1. If 'K' is not present in ARR,...read more
Given a rotated sorted array, find the index of a given integer 'K'.
Use binary search to find the pivot point where the array is rotated.
Based on the pivot point, perform binary search on the appropriate half of the array to find 'K'.
Handle cases where 'K' is not present in the array by returning -1.
Q7. Middle of a Linked List
You are given the head node of a singly linked list. Your task is to return a pointer pointing to the middle of the linked list.
If there is an odd number of elements, return the middle ...read more
Return the middle element of a singly linked list, or the one farther from the head if there are even elements.
Traverse the linked list with two pointers, one moving twice as fast as the other
When the fast pointer reaches the end, the slow pointer will be at the middle
If there are even elements, return the one that is farther from the head node
Handle edge cases like linked list of size 1 or no midpoint existing
Q8. Palindrome Linked List Problem Statement
You are provided with a singly linked list of integers. Your task is to determine whether the given singly linked list is a palindrome. Return true
if it is a palindrome...read more
Check if a given singly linked list is a palindrome or not.
Use two pointers approach to find the middle of the linked list.
Reverse the second half of the linked list.
Compare the first half with the reversed second half to determine if it's a palindrome.
Q9. Path Sum Calculation
You are provided with the root node of a binary tree containing 'N' nodes and an integer value 'TARGET'. Your task is to determine the number of leaf nodes for which the sum of the nodes al...read more
Calculate the number of leaf nodes in a binary tree with a path sum equal to a given target.
Traverse the binary tree from root to leaf nodes while keeping track of the sum along the path.
Recursively check if the current node is a leaf node and if the sum equals the target.
Increment a counter if the conditions are met and return the counter as the result.
Q10. Matrix Transpose Problem Statement
Given a matrix MAT
, your task is to return the transpose of the matrix. The transpose of a matrix is obtained by converting rows into columns and vice versa. Specifically, the...read more
Return the transpose of a given matrix by switching rows into columns and vice versa.
Iterate through the matrix and swap elements at indices (i, j) and (j, i) to obtain the transpose.
Ensure the dimensions of the transposed matrix are reversed from the original matrix.
Handle edge cases like empty matrix or single row/column matrix.
Q11. 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
Q12. Subset Sum Equal To K Problem Statement
Given an array/list of positive integers and an integer K, determine if there exists a subset whose sum equals K.
Provide true
if such a subset exists, otherwise return f...read more
Given an array of positive integers and an integer K, determine if there exists a subset whose sum equals K.
Use dynamic programming to solve this problem efficiently.
Create a 2D array to store if a subset sum is possible for each element and each sum up to K.
Initialize the first row and column of the 2D array accordingly.
Iterate through the array and update the 2D array based on the current element and sum.
Check if the last element of the 2D array is true, indicating a subset...read more
Q13. Check If Numbers Are Coprime
Determine if two given numbers 'a' and 'b' are coprime, meaning they have no common divisors other than 1.
Input:
t
a_1 b_1
a_2 b_2
...
a_t b_t
Output:
true / false
...
Example:
Input:
3...read more
Check if two numbers are coprime by finding their greatest common divisor (GCD) and determining if it is 1.
Calculate the GCD of the two numbers using Euclidean algorithm.
If GCD is 1, the numbers are coprime; otherwise, they are not.
Iterate through all pairs of numbers provided in the input.
Return true if GCD is 1, false otherwise.
Abstraction in OOP is the concept of hiding complex implementation details and showing only the necessary features to the outside world.
Abstraction allows us to focus on what an object does rather than how it does it.
It helps in reducing complexity and improving maintainability of code.
Example: In a car, we don't need to know the internal working of the engine to drive it. We just need to know how to operate the pedals and steering wheel.
Static polymorphism is resolved at compile time, while dynamic polymorphism is resolved at runtime.
Static polymorphism is achieved through function overloading and operator overloading.
Dynamic polymorphism is achieved through virtual functions and function overriding.
Example of static polymorphism: function overloading in C++.
Example of dynamic polymorphism: virtual functions in C++.
Q16. Do you know anything about cloud computing?
Yes, cloud computing refers to the delivery of computing services over the internet.
Cloud computing allows users to access data and applications from anywhere with an internet connection.
It offers scalability, flexibility, and cost-effectiveness compared to traditional on-premises computing.
Examples of cloud computing services include Amazon Web Services, Microsoft Azure, and Google Cloud Platform.
Q17. What is oops concepts
OOPs concepts are the principles of Object-Oriented Programming that help in designing and implementing software systems.
Encapsulation - bundling of data and methods that operate on that data
Inheritance - ability of a class to inherit properties and methods from its parent class
Polymorphism - ability of objects to take on multiple forms or behaviors
Abstraction - hiding of complex implementation details and showing only the necessary information
Examples: Java, C++, Python, Rub...read more
Q18. What is new in C# 10
C# 10 introduces new features like file-scoped namespaces, global using directives, and interpolated string handlers.
File-scoped namespaces allow defining namespaces at the file level instead of wrapping everything in a namespace block.
Global using directives simplify the process of importing namespaces across the entire project.
Interpolated string handlers provide a way to customize how interpolated strings are processed.
Q19. write program for finding duplicates
Program to find duplicates in an array of strings
Iterate through the array and store each element in a hash set
If an element is already in the hash set, it is a duplicate
Return a list of all duplicates found
Q20. Implementation of OOPS
OOPS (Object-Oriented Programming) is a programming paradigm based on the concept of objects, which can contain data and code.
OOPS focuses on the use of classes and objects to organize code and data
Encapsulation, inheritance, polymorphism, and abstraction are key principles of OOPS
Example: Inheritance allows a class to inherit properties and methods from another class
Q21. Design Patterns in C#
Design patterns in C# are reusable solutions to common problems in software design.
Design patterns help in creating maintainable and scalable code.
Some common design patterns in C# include Singleton, Factory, Observer, and Strategy.
Each design pattern has its own purpose and can be applied in different scenarios.
Design patterns promote code reusability and improve code organization.
Q22. Write basic code
Basic code example using an array of strings
Declare an array of strings in the preferred programming language
Initialize the array with some string values
Access and manipulate elements in the array as needed
Q23. Write simple profram
A simple program to print 'Hello, World!'
Create a new file with a .py extension
Write 'print('Hello, World!')' inside the file
Save the file and run it using a Python interpreter
Q24. Oops concept in C#
Oops concept in C# refers to Object-Oriented Programming principles like Inheritance, Polymorphism, Encapsulation, and Abstraction.
Inheritance allows a class to inherit properties and behavior from another class.
Polymorphism allows objects of different classes to be treated as objects of a common superclass.
Encapsulation hides the internal state of an object and only exposes necessary functionalities.
Abstraction focuses on the essential features of an object while hiding unne...read more
Q25. Explain oops concept
OOPs (Object-Oriented Programming) is a programming paradigm based on the concept of objects, which can contain data and code.
OOPs focuses on creating objects that interact with each other to solve a problem
Key principles include Inheritance, Encapsulation, Polymorphism, and Abstraction
Inheritance allows a class to inherit properties and behavior from another class
Encapsulation hides the internal state of an object and only exposes necessary functionality
Polymorphism allows o...read more
Interview Process at KJ System
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month