MAQ Software
30+ Mehta Stone Export House Interview Questions and Answers
Q1. Nth Fibonacci Number Problem Statement
Calculate the Nth term in the Fibonacci sequence, where the sequence is defined as follows: F(n) = F(n-1) + F(n-2)
, with initial conditions F(1) = F(2) = 1
.
Input:
The inp...read more
Calculate the Nth Fibonacci number efficiently using dynamic programming.
Use dynamic programming to store previously calculated Fibonacci numbers to avoid redundant calculations.
Start with base cases F(1) and F(2) as 1, then iterate to calculate F(N) efficiently.
Time complexity can be optimized to O(N) using dynamic programming.
Example: For N = 5, the 5th Fibonacci number is 5.
Q2. Print Series Problem Statement
Given two positive integers N
and K
, your task is to generate a series of numbers by subtracting K
from N
until the result is 0 or negative, then adding K
back until it reaches N
...read more
Generate a series of numbers by subtracting K from N until 0 or negative, then adding K back to reach N without using loops.
Create a recursive function to generate the series.
Subtract K from N until N is 0 or negative, then add K back until N is reached.
Return the series as an array of integers.
Q3. Unique Element In Sorted Array
Nobita wants to impress Shizuka by correctly guessing her lucky number. Shizuka provides a sorted list where every number appears twice, except for her lucky number, which appears...read more
Find the unique element in a sorted array where all other elements appear twice.
Iterate through the array and XOR all elements to find the unique element.
Use a hash set to keep track of elements and find the unique one.
Sort the array and check adjacent elements to find the unique one.
Q4. Remove Invalid Parentheses
Given a string containing only parentheses and letters, your goal is to remove the minimum number of invalid parentheses to make the input string valid and return all possible valid s...read more
Given a string with parentheses and letters, remove minimum invalid parentheses to make it valid and return all possible valid strings.
Use BFS to explore all possible valid strings by removing parentheses one by one
Keep track of visited strings to avoid duplicates
Return all unique valid strings obtained after removing minimum number of parentheses
Q5. Problem: Permutations of a String
Given a string STR
consisting of lowercase English letters, your task is to return all permutations of the given string in lexicographically increasing order.
Explanation:
A st...read more
Return all permutations of a given string in lexicographically increasing order.
Use backtracking to generate all permutations of the string.
Sort the permutations in lexicographical order before printing.
Ensure the string contains unique characters for correct output.
Handle multiple test cases by iterating over each case.
Q6. Rotate Array Problem Statement
The task is to rotate a given array with N elements to the left by K steps, where K is a non-negative integer.
Input:
The first line contains an integer N representing the size of...read more
Rotate a given array to the left by K steps.
Create a new array to store the rotated elements.
Use modular arithmetic to handle cases where K is greater than the array size.
Shift elements to the left by K steps and update the new array.
Return the rotated array as output.
Q7. Remove String from Linked List Problem
You are provided with a singly linked list where each node contains a single character, along with a string 'STR'. Your task is to remove all occurrences of the string 'ST...read more
Remove all occurrences of a specified string from a singly linked list by checking from the end of the list.
Traverse the linked list from the end to efficiently remove the specified string occurrences.
Update the pointers accordingly after removing the string to maintain the integrity of the linked list.
Consider edge cases such as when the entire linked list contains the specified string.
Use a temporary buffer to keep track of the nodes that need to be removed.
Q8. MergeSort Linked List Problem Statement
You are given a Singly Linked List of integers. Your task is to sort the list using the 'Merge Sort' algorithm.
Input:
The input consists of a single line containing the ...read more
Sort a Singly Linked List using Merge Sort algorithm.
Implement the Merge Sort algorithm for linked lists.
Divide the list into two halves, sort each half recursively, and then merge them.
Make sure to handle the base case of an empty or single-node list.
Example: Input: 4 3 2 1 -1, Output: 1 2 3 4
Q9. Sort String with Alternate Lower and Upper Case
Given a string STR
containing both lowercase and uppercase letters, the task is to sort the string so that the resulting string contains uppercase and lowercase l...read more
Sort a string with alternate lowercase and uppercase letters in sorted order.
Create two separate arrays for lowercase and uppercase letters.
Sort both arrays individually.
Merge the two arrays alternately to form the final sorted string.
Q10. Which data structure inserts and deletes in O(1) time and is it possible to create a data structure with insertion, deletion and search retrieval in O(1) time
Hash table. No, it is not possible to create a data structure with all operations in O(1) time.
Hash table uses a hash function to map keys to indices in an array.
Insertion and deletion can be done in O(1) time on average.
Search retrieval can also be done in O(1) time on average.
However, worst-case scenarios can result in O(n) time complexity.
It is not possible to create a data structure with all operations in O(1) time.
Q11. Factorial Calculation Problem
Given an integer N
, determine the factorial value of N
. The factorial of a number N
is the product of all positive integers from 1 to N
.
Input:
First line of input: An integer 'T',...read more
Calculate factorial of a given number N.
Iterate from 1 to N and multiply each number to get the factorial value.
Handle edge cases like N=0 or N=1 separately.
Use recursion or iteration to calculate factorial efficiently.
Q12. Find the Second Largest Element
Given an array or list of integers 'ARR', identify the second largest element in 'ARR'.
If a second largest element does not exist, return -1.
Example:
Input:
ARR = [2, 4, 5, 6, ...read more
Find the second largest element in an array of integers.
Iterate through the array to find the largest and second largest elements.
Handle cases where all elements are identical.
Return -1 if a second largest element does not exist.
Q13. Find the Kth Row of Pascal's Triangle Problem Statement
Given a non-negative integer 'K', determine the Kth row of Pascal’s Triangle.
Example:
Input:
K = 2
Output:
1 1
Input:
K = 4
Output:
1 4 6 4 1
Constraints...read more
To find the Kth row of Pascal's Triangle given a non-negative integer K.
Create an array to store the values of the Kth row of Pascal's Triangle
Use the formula C(n, k) = C(n-1, k-1) + C(n-1, k) to calculate the values
Return the array as the output
Q14. Flip Bits Problem Explanation
Given an array of integers ARR
of size N, consisting of 0s and 1s, you need to select a sub-array and flip its bits. Your task is to return the maximum count of 1s that can be obta...read more
Given an array of 0s and 1s, find the maximum count of 1s by flipping a sub-array at most once.
Iterate through the array and keep track of the maximum count of 1s obtained by flipping a sub-array.
Consider flipping a sub-array from index i to j and calculate the count of 1s in the resulting array.
Return the maximum count of 1s obtained by flipping a sub-array at most once.
Q15. Number of Islands Problem Statement
You are provided with a 2-dimensional matrix having N
rows and M
columns, containing only 1s (land) and 0s (water). Your goal is to determine the number of islands in this ma...read more
Count the number of islands in a 2D matrix of 1s and 0s.
Iterate through the matrix and perform depth-first search (DFS) to find connected 1s.
Mark visited cells to avoid redundant traversal.
Increment island count whenever a new island is encountered.
Q16. Find the third largest element from array, give the optimized approach using just half traversal of array.
Optimized approach to find third largest element from array using half traversal.
Sort the array in descending order and return the element at index 2.
Use a max heap to keep track of the top 3 elements while traversing the array.
Use two variables to keep track of the second and third largest elements while traversing the array.
Divide the array into two halves and find the maximum and second maximum in each half, then compare them to find the third largest element.
Q17. What are indexes , example, Is it possible to have more than one clustered index and more than one non clustered index ?
Indexes are used to improve query performance. Multiple clustered and non-clustered indexes can be created on a table.
Indexes are used to quickly locate data without scanning the entire table.
Clustered index determines the physical order of data in a table.
Non-clustered index is a separate structure that contains a copy of the indexed columns and a pointer to the actual data.
A table can have only one clustered index, but multiple non-clustered indexes.
Indexes should be create...read more
Q18. What are acid properties , how two transactions occur simultaneously while maintaining Acid properties
ACID properties ensure database transactions are reliable. Two transactions can occur simultaneously using locking and isolation.
ACID stands for Atomicity, Consistency, Isolation, and Durability.
Atomicity ensures that a transaction is treated as a single unit of work, either all or none of it is executed.
Consistency ensures that a transaction brings the database from one valid state to another.
Isolation ensures that concurrent transactions do not interfere with each other.
Dur...read more
Q19. Print first character of words in a string 1) using one stack and 2)using an array.
Answering how to print first character of words in a string using one stack and an array.
For using one stack, push each character onto the stack and pop when a space is encountered. Print the popped character.
For using an array, split the string into words and print the first character of each word.
In both cases, handle edge cases like empty string and string with only one word.
Q20. Given a array and a number , find whether number can be generated using sum of array members if yes output those numbers
Given an array and a number, find if the number can be generated using sum of array members and output those numbers.
Iterate through the array and check if the number can be generated using the sum of array members
Use a hash table to store the difference between the number and each array element
If the difference is found in the hash table, output the corresponding array elements
If no such combination is found, output 'Not possible'
Query to find the Nth highest salary with employee name
Use a subquery to rank the salaries in descending order
Select the distinct salary from the subquery with LIMIT N-1, 1 to get the Nth highest salary
Join the main table with the subquery on the salary column to get the employee name
Q22. Time complexity of various data structure operations
Time complexity of data structure operations
Arrays: O(1) for access, O(n) for search/insert/delete
Linked Lists: O(n) for access/search, O(1) for insert/delete
Stacks/Queues: O(1) for access/insert/delete
Hash Tables: O(1) for access/insert/delete (average case)
Trees: O(log n) for access/search/insert/delete (balanced)
Heaps: O(log n) for access/insert/delete
Graphs: Varies depending on algorithm used
Q23. Difference between span and div tag
Span is an inline element used for styling small portions of text, while div is a block-level element used for grouping and styling larger sections of content.
Span is an inline element, div is a block-level element
Span is used for styling small portions of text, div is used for grouping larger sections of content
Span does not create a new line, div creates a new block-level element
Q24. -----+all+permutation+of+a+string+geeksforgeeks -----/
Generate all permutations of a given string using recursion and backtracking.
Use recursion to generate all possible permutations of the string.
Use backtracking to backtrack and explore all possible combinations.
Store each permutation in an array of strings.
Q25. k nodes reversal of linked list
Reversing k nodes in a linked list
Iterate through the linked list in groups of k nodes
Reverse each group of k nodes
Update the pointers accordingly to maintain the reversed order
Q26. what is joins in sql
Joins in SQL are used to combine rows from two or more tables based on a related column between them.
Joins are used to retrieve data from multiple tables based on a related column
Common types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN
Example: SELECT * FROM table1 INNER JOIN table2 ON table1.column = table2.column
Q27. Normalization and all its forms
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity.
Normalization is used to eliminate data redundancy by breaking up tables into smaller, related tables.
There are different normal forms such as 1NF, 2NF, 3NF, BCNF, and 4NF, each with specific rules to follow.
Normalization helps in reducing data anomalies and ensures data integrity.
Example: Breaking up a customer table into separate tables for customer details and orde...read more
Q28. Circular linked list algorithm
Circular linked list is a data structure where the last node points back to the first node.
In a circular linked list, each node has a pointer to the next node and the last node points back to the first node.
Traversal in a circular linked list can start from any node and continue until the starting node is reached again.
Insertion and deletion operations in a circular linked list are similar to those in a regular linked list, but special care must be taken to update the pointer...read more
Q29. Index in sql theoretical
Indexes in SQL are used to improve the performance of queries by allowing the database to quickly retrieve data.
Indexes are created on columns in a table to speed up data retrieval.
They work similar to an index in a book, allowing the database to quickly find the relevant data.
Primary keys automatically have an index created on them.
Indexes can be unique, meaning that each value in the indexed column must be unique.
Examples: CREATE INDEX idx_name ON table_name(column_name);
Q30. reverse the array
Reverse the 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 array with only one element
Interview Process at Mehta Stone Export House
Top Software Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month