Cadence Design Systems
30+ Reliable Software Systems Private Limited Interview Questions and Answers
Q1. Longest Common Prime Subsequence Problem Statement
Imagine Ninja is tackling a puzzle during his long summer vacation. He has two arrays of integers, each with lengths 'N' and 'M'. Ninja's task is to determine ...read more
Find the length of the longest subsequence common to two arrays consisting only of prime numbers.
Iterate through both arrays to find prime numbers
Use dynamic programming to find the longest common subsequence
Consider edge cases like empty arrays or no common prime numbers
Q2. Validate Partial Binary Search Tree (BST) Problem Statement
You are provided with a binary tree containing 'N' nodes. Your task is to determine if this tree is a Partial Binary Search Tree (BST). Return true if...read more
Validate if a binary tree is a Partial Binary Search Tree (BST) by checking if each node's left subtree contains nodes with data less than or equal to the node's data, and each node's right subtree contains nodes with data greater than or equal to the node's data.
Check if each node's left subtree follows BST property (data <= node's data) and right subtree follows BST property (data >= node's data)
Recursively check if both left and right subtrees are partial BSTs
Handle cases ...read more
Q3. Maximum Sum Problem Statement
You are given an array ARR
of N integers. Your task is to perform operations on this array until it becomes empty, and maximize the sum of selected elements. In each operation, sel...read more
Given an array, select elements to maximize sum by removing adjacent elements. Return the maximum sum.
Iterate through the array and keep track of the frequency of each element.
Select the element with the highest frequency first, then remove adjacent elements.
Repeat the process until the array becomes empty and calculate the sum of selected elements.
Q4. Check If Preorder Traversal Is Valid
Determine whether a given array ARR
of positive integers is a valid Preorder Traversal of a Binary Search Tree (BST).
A binary search tree (BST) is a tree structure where ea...read more
Check if a given array of positive integers is a valid Preorder Traversal of a Binary Search Tree (BST).
Create a stack to keep track of nodes.
Iterate through the array and compare each element with the top of the stack.
If the current element is less than the top of the stack, push it onto the stack.
If the current element is greater than the top of the stack, pop elements from the stack until a greater element is found or the stack is empty.
The last popped element becomes the ...read more
Q5. Count Palindromic Substrings Problem Statement
Given a string STR
, determine the total number of palindromic substrings within STR
.
Input:
The first line contains an integer 't' representing the number of test ...read more
Count the total number of palindromic substrings in a given string.
Iterate through each character in the string and expand around it to find palindromic substrings.
Use dynamic programming to store previously calculated palindromic substrings.
Consider both odd and even length palindromes while counting.
Example: For input 'abbc', palindromic substrings are ['a', 'b', 'b', 'c', 'bb']. Total count is 5.
Q6. Next Greater Element Problem Statement
You are given an array arr
of length N
. For each element in the array, find the next greater element (NGE) that appears to the right. If there is no such greater element, ...read more
The task is to find the next greater element for each element in an array to its right, if no greater element exists, return -1.
Use a stack to keep track of elements for which the next greater element is not found yet.
Iterate through the array from right to left and pop elements from the stack until a greater element is found.
Store the next greater element for each element in a separate array.
If the stack is empty after iterating through the array, it means there is no greate...read more
Q7. Counting Sort Problem Statement
Ninja is learning about sorting algorithms, specifically those that do not rely on comparisons. Can you help Ninja implement the counting sort algorithm?
Example:
Input:
ARR = {-...read more
Implement counting sort algorithm to sort an array of integers without comparisons.
Count the frequency of each element in the input array.
Create a prefix sum array to determine the position of each element in the sorted array.
Iterate through the input array and place each element in its correct position based on the prefix sum array.
Time complexity of counting sort is O(n+k), where n is the number of elements and k is the range of input values.
Q8. Top View of a Binary Tree
You are given a binary tree. Your task is to print the Top View of the Binary Tree, displaying the nodes from left to right order.
Input:
The first line contains an integer 't' represe...read more
The task is to print the Top View of a Binary Tree from left to right order.
Use a map to store the horizontal distance of each node from the root.
Perform a level order traversal of the tree and keep track of the horizontal distance of each node.
Print the nodes in the map in ascending order of their horizontal distance.
Handle the case where multiple nodes have the same horizontal distance by printing the one that appears first in level order traversal.
Q9. Cycle Detection in a Linked List
Your task is to determine if a given Singly Linked List of integers forms a cycle.
Explanation: A cycle in a linked list occurs when there is a node in the list that connects ba...read more
Detect if a given singly linked list of integers forms a cycle.
Use Floyd's Tortoise and Hare algorithm to detect cycle in linked list
Maintain two pointers, one moving at double the speed of the other
If they meet at some point, there is a cycle in the linked list
Q10. K - Sum Path In A Binary Tree
Given a binary tree where each node contains an integer value, and a value 'K', your task is to find all the paths in the binary tree such that the sum of the node values in each p...read more
Find all paths in a binary tree where the sum of node values equals a given value 'K'.
Traverse the binary tree using DFS and keep track of the current path and its sum.
At each node, check if the current sum equals 'K' and add the path to the result.
Continue traversal to the left and right child nodes recursively.
Return the list of paths that sum up to 'K'.
Q11. Longest Increasing Subsequence Problem Statement
Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more
Find the length of the longest strictly increasing subsequence in an array of integers.
Use dynamic programming to solve this problem efficiently.
Initialize an array to store the length of the longest increasing subsequence ending at each index.
Iterate through the array and update the length of the longest increasing subsequence for each element.
Return the maximum value in the array as the result.
Q12. Power Set Generation
Given a sorted array of 'N' integers, your task is to generate the power set for this array. Each subset of this power set should be individually sorted.
A power set of a set 'ARR' is the s...read more
Generate power set of a sorted array of integers with individually sorted subsets.
Use recursion to generate all possible subsets by including or excluding each element in the array.
Sort each subset before adding it to the power set.
Handle base case when all elements have been considered to add the subset to the power set.
Q13. Smallest Window Problem Statement
Given two strings, S
and X
, your task is to find the smallest substring in S
that contains all the characters present in X
.
Example:
Input:
S = "abdd"
X = "bd"
Output:
bd
Explan...read more
Find the smallest substring in S that contains all characters in X.
Use a sliding window approach to find the smallest substring in S that contains all characters in X.
Keep track of the characters in X using a hashmap.
Move the window by adjusting the start and end pointers until all characters in X are found.
Return the smallest substring encountered.
To search for a node in a linked list, iterate through the list and compare each node's value with the target value.
Start at the head of the linked list
Iterate through each node by following the 'next' pointer
Compare the value of each node with the target value
Return the node if found, otherwise return null
Q15. You are given an array of elements. Some/all of them are duplicates. Find them in 0(n) time and 0(1) space. Property of inputs – Number are in the range of 1..n where n is the limit of the array
Find duplicates in an array of elements in 0(n) time and 0(1) space.
Use the property of inputs to your advantage
Iterate through the array and mark elements as negative
If an element is already negative, it is a duplicate
Return all the negative elements as duplicates
Q16. A point and a rectangle is present with the given coordinates. How will you determine whether the point is inside or outside the rectangle?
To determine if a point is inside or outside a rectangle, we check if the point's coordinates fall within the rectangle's boundaries.
Check if the point's x-coordinate is greater than the left edge of the rectangle
Check if the point's x-coordinate is less than the right edge of the rectangle
Check if the point's y-coordinate is greater than the top edge of the rectangle
Check if the point's y-coordinate is less than the bottom edge of the rectangle
If all four conditions are true...read more
Q17. There is a point inside the rectangle. How will you determine the line that passes through the point and divides the rectangle into 2 equal halves?
To find line that divides rectangle into 2 equal halves through a point inside it.
Find the center of the rectangle
Draw a line from the center to the given point
Extend the line to the opposite side of the rectangle
The extended line will divide the rectangle into 2 equal halves
Q18. There is a scheme which contains 8-bit and 16-bit signed numbers. How many such combinations are possible?
There are multiple combinations of 8-bit and 16-bit signed numbers. How many such combinations are possible?
There are 2^8 (256) possible combinations of 8-bit signed numbers.
There are 2^16 (65,536) possible combinations of 16-bit signed numbers.
To find the total number of combinations, we can add the number of combinations of 8-bit and 16-bit signed numbers.
Therefore, the total number of possible combinations is 256 + 65,536 = 65,792.
DELETE removes specific rows from a table, while TRUNCATE removes all rows and resets auto-increment values.
DELETE is a DML command, while TRUNCATE is a DDL command.
DELETE can be rolled back, while TRUNCATE cannot be rolled back.
DELETE triggers delete triggers, while TRUNCATE does not trigger any triggers.
DELETE is slower as it maintains logs, while TRUNCATE is faster as it does not maintain logs.
Example: DELETE FROM table_name WHERE condition; TRUNCATE table_name;
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity, while denormalization is the process of intentionally introducing redundancy to improve performance.
Normalization involves breaking down a table into smaller tables and defining relationships between them to reduce redundancy and dependency.
Denormalization involves combining tables and duplicating data to improve query performance by reducing the number of joins need...read more
Processes are instances of a program in execution, while threads are lightweight processes within a process.
A process is a program in execution, with its own memory space and resources.
Threads are lightweight processes within a process, sharing the same memory space and resources.
Processes are independent of each other, while threads within the same process can communicate and share data.
Example: A web browser running multiple tabs is a process, and each tab running JavaScrip...read more
To detect a loop in a linked list, we can use Floyd's Cycle Detection Algorithm.
Initialize two pointers, slow and fast, at the head of the linked list.
Move slow pointer by one step and fast pointer by two steps.
If there is a loop, the two pointers will eventually meet.
Alternatively, we can use a hash set to store visited nodes and check for duplicates.
Deleting a node from a linked list involves updating pointers to maintain the list's integrity.
Identify the node to be deleted by traversing the list
Update the previous node's next pointer to skip the node to be deleted
Free the memory allocated to the node to be deleted
Different types of semaphores include binary semaphores, counting semaphores, and mutex semaphores.
Binary semaphores: Can only have two states - 0 or 1. Used for mutual exclusion.
Counting semaphores: Can have multiple states. Used for managing resources with limited capacity.
Mutex semaphores: Similar to binary semaphores but with additional features like priority inheritance.
Named semaphores: Can be shared between processes by using a unique name.
Recursive semaphores: Allow a...read more
Q25. Locate the sum of 2 numbers in a linear array (Unsorted and sorted) and their complexities
Locate sum of 2 numbers in a linear array (unsorted and sorted) and their complexities
For unsorted array, use nested loops to compare each element with every other element until the sum is found
For sorted array, use two pointers approach starting from the beginning and end of the array and move them towards each other until the sum is found
Complexity for unsorted array is O(n^2) and for sorted array is O(n)
Vtable and VPTR are used in C++ for implementing polymorphism through virtual functions.
Vtable (Virtual Table) is a table of function pointers used to implement dynamic dispatch for virtual functions.
VPTR (Virtual Pointer) is a pointer that points to the Vtable of an object.
Vtable is created by the compiler for each class that has virtual functions.
VPTR is added as a hidden member in each object of a class with virtual functions.
Example: class Base { virtual void func() {} };...read more
The top view of a binary tree shows the nodes visible from the top when looking down from the root node.
The top view of a binary tree is the set of nodes visible from the top when looking down from the root node.
Nodes at the same horizontal distance from the root are considered at the same level in the top view.
If multiple nodes are at the same horizontal distance, only the topmost node at that level is included in the top view.
The top view can be obtained by performing a lev...read more
Friend functions in C++ are functions that are not members of a class but have access to its private and protected members.
Friend functions are declared inside a class with the keyword 'friend'.
They can access private and protected members of the class.
They are not member functions of the class, but have the same access rights as member functions.
Friend functions are useful when you want to allow a function external to the class to access its private members.
Q29. Pointers with increment/decrement, address of and value at operators (++,–,*,&)
Pointers are used to manipulate memory addresses and values in C++. Increment/decrement, address of and value at operators are commonly used.
Incrementing a pointer moves it to the next memory location of the same data type
Decrementing a pointer moves it to the previous memory location of the same data type
The address of operator (&) returns the memory address of a variable
The value at operator (*) returns the value stored at a memory address
Implement a stack using a singly linked list
Create a Node class with data and next pointer
Create a Stack class with top pointer pointing to the top of the stack
Implement push, pop, and peek operations by manipulating the linked list
Example: Node class - Node { int data; Node next; }
Q31. Reverse an array
Reverse an array of strings
Create a new array and iterate through the original array in reverse order, adding each element to the new array
Use built-in array methods like reverse() or spread operator for a more concise solution
Ensure to handle edge cases like empty array or null values
Interview Process at Reliable Software Systems Private Limited
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month