MAQ Software
20+ Jaytech Interview Questions and Answers
Q1. Find the Duplicate Number Problem Statement
Given an integer array 'ARR' of size 'N' containing numbers from 0 to (N - 2). Each number appears at least once, and there is one number that appears twice. Your tas...read more
Find the duplicate number in an array of integers from 0 to N-2.
Iterate through the array and keep track of the frequency of each number using a hashmap.
Return the number with a frequency greater than 1 as the duplicate number.
Q2. Character Frequency Problem Statement
You are given a string 'S' of length 'N'. Your task is to find the frequency of each character from 'a' to 'z' in the string.
Example:
Input:
S : abcdg
Output:
1 1 1 1 0 0 ...read more
The task is to find the frequency of each character from 'a' to 'z' in a given string.
Create an array of size 26 to store the frequency of each character from 'a' to 'z'.
Iterate through the string and increment the count of the corresponding character in the array.
Print the array of frequencies as the output for each test case.
Q3. Sort 0 1 2 Problem Statement
Given an integer array arr
of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.
Input:
The first line contains an integer 'T' representing the number of...read more
Sort an array of 0s, 1s, and 2s in linear time complexity.
Use three pointers to keep track of 0s, 1s, and 2s while traversing the array.
Swap elements based on the values encountered to sort the array in-place.
Time complexity should be O(N) and space complexity should be O(1).
Q4. N Queens Problem
Given an integer N
, find all possible placements of N
queens on an N x N
chessboard such that no two queens threaten each other.
Explanation:
A queen can attack another queen if they are in the...read more
The N Queens Problem involves finding all possible placements of N queens on an N x N chessboard without threatening each other.
Use backtracking algorithm to explore all possible configurations.
Keep track of rows, columns, and diagonals to ensure queens do not threaten each other.
Generate all valid configurations and print them out.
Q5. Reverse Words in a String: Problem Statement
You are given a string of length N
. Your task is to reverse the string word by word. The input may contain multiple spaces between words and may have leading or trai...read more
Reverse words in a string while handling leading, trailing, and multiple spaces.
Split the input string by spaces to get individual words
Reverse the order of the words
Join the reversed words with a single space in between
Q6. Reverse Array Elements
Given an array containing 'N' elements, the task is to reverse the order of all array elements and display the reversed array.
Explanation:
The elements of the given array need to be rear...read more
Reverse the order of elements in an array and display the reversed array.
Iterate through the array from both ends and swap the elements until the middle is reached.
Use a temporary variable to store the element being swapped.
Print the reversed array after all elements have been swapped.
Q7. Buy and Sell Stock Problem Statement
Imagine you are Harshad Mehta's friend, and you have been given the stock prices of a particular company for the next 'N' days. You can perform up to two buy-and-sell transa...read more
The task is to determine the maximum profit that can be achieved by performing up to two buy-and-sell transactions on a given set of stock prices.
Iterate through the array of stock prices and calculate the maximum profit that can be achieved by buying and selling at different points.
Keep track of the maximum profit after the first transaction and the maximum profit overall by considering different combinations of buy and sell points.
Return the maximum profit obtained after co...read more
Q8. Pair Sum Problem Statement
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.
Note:
Each pa...read more
Find pairs of elements in an array that sum up to a given value, sorted in a specific order.
Iterate through the array and for each element, check if the complement (S - current element) exists in a hash set.
Keep track of pairs in a hash set to avoid duplicates.
Sort the pairs based on the criteria mentioned in the question.
Return the sorted list of pairs.
Q9. Circular Linked List Detection
You are provided with the head of a linked list containing integers. Your task is to determine if the linked list is circular.
Note:
- A linked list is considered circular if it co...read more
Detect if a given linked list is circular by checking if it forms a closed loop.
Traverse the linked list using two pointers, one moving at double the speed of the other.
If the two pointers meet at any point, the linked list is circular.
If the faster pointer reaches the end of the list (NULL), the linked list is not circular.
Q10. Sum of Digits Problem Statement
Given an integer 'N', continue summing its digits until the result is a single-digit number. Your task is to determine the final value of 'N' after applying this operation iterat...read more
Given an integer, find the final single-digit value after summing its digits iteratively.
Iteratively sum the digits of the given integer until the result is a single-digit number
Output the final single-digit integer for each test case
Handle multiple test cases efficiently
Q11. Pancake Sorting Problem Statement
You are given an array of integers 'ARR'. Sort this array using a series of pancake flips. In each pancake flip, you need to:
Choose an integer 'K' where 1 <= 'K' <= ARR.LENGTH...read more
Sort an array using pancake flips and return the sequence of flips made.
Iterate through the array and find the position of the maximum element in each iteration.
Perform pancake flips to move the maximum element to the correct position.
Continue this process until the array is sorted.
Return the sequence of positions from where flips were made.
Q12. Fibonacci Number Verification
Identify if the provided integer 'N' is a Fibonacci number.
A number is termed as a Fibonacci number if it appears in the Fibonacci sequence, where each number is the sum of the tw...read more
Check if a given number is a Fibonacci number or not.
Iterate through the Fibonacci sequence until you find a number greater than or equal to the given number.
Check if the given number matches the Fibonacci number found in the sequence.
If the number matches, output 'YES'; otherwise, output 'NO'.
Q13. Reverse Only Letters Problem Statement
You are given a string S
. The task is to reverse the letters of the string while keeping non-alphabet characters in their original position.
Example:
Input:
S = "a-bcd"
Ou...read more
Reverse the letters of a string while keeping non-alphabet characters in their original position.
Iterate through the string and store the non-alphabet characters in their original positions
Reverse the letters using two pointers technique
Combine the reversed letters with the non-alphabet characters to get the final reversed string
Q14. 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 and reuse previously calculated Fibonacci numbers.
Start with base cases F(1) and F(2) as 1, then calculate subsequent Fibonacci numbers.
Optimize the solution to avoid redundant calculations by storing intermediate results.
Time complexity can be reduced to O(N) using dynamic programming.
Example: For N = 5, the 5th Fibonacci number is 5.
Q15. Find Duplicates in an Array
Given an array ARR
of size 'N', where each integer is in the range from 0 to N - 1, identify all elements that appear more than once.
Return the duplicate elements in any order. If n...read more
Find duplicates in an array of integers within a specified range.
Iterate through the array and keep track of the count of each element using a hashmap.
Return elements with count greater than 1 as duplicates.
Time complexity can be optimized to O(N) using a set to store duplicates.
Example: For input [0, 3, 1, 2, 3], output should be [3].
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity.
Normalization is a technique used to organize data in a database efficiently.
Third Normal Form (3NF) is a level of normalization that ensures that data is stored in a way that prevents certain types of data anomalies.
In 3NF, every non-prime attribute is fully functionally dependent on the primary key.
For example, if we have a table 'Employees' with columns 'EmployeeID...read more
SQL query to find the second highest salary from a table
Use the MAX() function to find the highest salary
Use the NOT IN operator to exclude the highest salary from the results
Order the results in descending order and limit the query to return only the second row
Q18. find the occurrence of each element in an array
Count the occurrence of each element in an array of strings
Iterate through the array and use a hashmap to store the count of each element
If element already exists in the hashmap, increment its count by 1
Return the hashmap with element counts
Q19. sort a vector according to other other vector ?
Sort a vector based on another vector
Use std::sort with a custom comparator function
The comparator function should compare the indices of the elements in the second vector
The first vector should be sorted based on the order of the indices in the second vector
Q20. Minimum swaps to group all ones together
The minimum number of swaps needed to group all ones together in an array of 0s and 1s.
Iterate through the array to count the total number of ones.
Use a sliding window of size equal to the total number of ones to find the window with the minimum number of zeros.
Calculate the number of swaps needed to move all ones to that window.
Q21. Zigzag traversal of binary tree
Zigzag traversal of binary tree involves alternating the direction of traversal at each level.
Use a queue to perform level order traversal of the binary tree.
For each level, alternate between adding nodes to the result list from left to right and right to left.
Continue this process until all levels have been traversed.
Q22. Sort 0,1,2 array
Sort an array of strings containing '0', '1', and '2'.
Use counting sort algorithm to count the occurrences of '0', '1', and '2'.
Create a new array with the sorted counts of '0', '1', and '2'.
Join the sorted array back into a single array of strings.
Interview Process at Jaytech
Top Software Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month