Add office photos
Engaged Employer

Oracle

3.7
based on 5.2k Reviews
Video summary
Filter interviews by

600+ Comvision Interview Questions and Answers

Updated 24 Feb 2025
Popular Designations

Q1. Triplets with Given Sum Problem

Given an array or list ARR consisting of N integers, your task is to identify all distinct triplets within the array that sum up to a specified number K.

Explanation:

A triplet i...read more

Ans.

The task is to find all distinct triplets in an array that sum up to a specified number.

  • Iterate through all possible triplets using three nested loops.

  • Check if the sum of the triplet equals the target sum.

  • Print the triplet if found, else print -1.

  • Handle duplicate triplets by skipping duplicates during iteration.

Add your answer

Q2. Minimum Cost to Connect All Points Problem Statement

Given an array COORDINATES representing the integer coordinates of some points on a 2D plane, determine the minimum cost required to connect all points. The ...read more

Ans.

The problem involves finding the minimum cost to connect all points on a 2D plane using Manhattan distance.

  • Create a function that calculates the Manhattan distance between two points.

  • Implement a function to find the minimum spanning tree to connect all points.

  • Consider using Prim's or Kruskal's algorithm for finding the minimum spanning tree.

  • Ensure that all points are connected with one simple path only.

View 1 answer

Q3. Square Root (Integral) Problem Statement

Given a number N, calculate its square root and output the integer part only.

Example:

Input:
18
Output:
4
Explanation:

The square root of 18 is approximately 4.24. The ...read more

Ans.

Calculate the integer square root of a given number.

  • Use binary search to find the square root of the number.

  • Start with a range from 0 to N, and iteratively narrow down the range until you find the integer square root.

  • Return the integer part of the square root as the output.

View 1 answer

Q4. Puzzle: – Two persons X and Y are sitting side by side with a coin in each’s hand. The game is to simultaneously flip the coin till anyone wins. Player X will win if he gets a consecutive HEAD, TAIL however Y w...

read more
Ans.

The game is not fair.

  • Player X has a higher chance of winning as they only need to get a consecutive HEAD, TAIL.

  • Player Y needs to get a consecutive HEAD, HEAD which is less likely to occur.

  • The probability of Player X winning is higher than Player Y winning.

Add your answer
Discover Comvision interview dos and don'ts from real experiences

Q5. Count Subsequences Problem Statement

Given an integer array ARR of size N, your task is to find the total number of subsequences in which all elements are equal.

Explanation:

A subsequence of an array is derive...read more

Ans.

Count the total number of subsequences in which all elements are equal in an integer array.

  • Iterate through the array and count the frequency of each element.

  • Calculate the total number of subsequences for each element using the formula (frequency * (frequency + 1)) / 2.

  • Sum up the total number of subsequences for all elements and return the result modulo 10^9 + 7.

Add your answer

Q6. Remove the Kth Node from the End of a Linked List

You are given a singly Linked List with 'N' nodes containing integer data and an integer 'K'. Your task is to delete the Kth node from the end of this Linked Li...read more

Ans.

Remove the Kth node from the end of a singly linked list given the position 'K'.

  • Traverse the list to find the length 'N' of the linked list.

  • Calculate the position from the beginning as 'N - K + 1'.

  • Delete the node at the calculated position from the beginning.

Add your answer
Are these interview questions helpful?

Q7. 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

Ans.

Reverse words in a string word by word, removing leading/trailing spaces and extra spaces between words.

  • 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

Add your answer

Q8. In a bag you have 20 black balls and 16 red balls.When you take out 2 black balls you take another white ball.If you take 2 white balls then you take out 1 black ball and if balls are of different color you tak...

read more
Ans.

The last ball that will be left is black.

  • When you take out 2 black balls, you take another white ball.

  • If you take 2 white balls, you take out 1 black ball.

  • If balls are of different color, you take out another black ball.

  • Since there are more black balls initially, the last ball will be black.

Add your answer
Share interview questions and help millions of jobseekers 🌟

Q9. Search in a Row-wise and Column-wise Sorted Matrix Problem Statement

You are given an N * N matrix of integers where each row and each column is sorted in increasing order. Your task is to find the position of ...read more

Ans.

Given a sorted N * N matrix, find the position of a target integer 'X'.

  • Use binary search in each row to narrow down the search space.

  • Start from the top-right corner or bottom-left corner for efficient search.

  • Handle cases where 'X' is not found by returning {-1, -1}.

Add your answer

Q10. Minimum Number of Platforms Needed Problem Statement

You are given the arrival and departure times of N trains at a railway station for a particular day. Your task is to determine the minimum number of platform...read more

Ans.

The task is to determine the minimum number of platforms needed at a railway station based on arrival and departure times of trains.

  • Sort the arrival and departure times in ascending order.

  • Use two pointers to track overlapping schedules.

  • Increment platform count when a new train arrives before the previous one departs.

Add your answer

Q11. 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

Ans.

Count the total number of inversions in an integer array.

  • Iterate through the array and for each pair of elements, check if the conditions for inversion are met.

  • Use a nested loop to compare each pair of elements efficiently.

  • Keep a count of the inversions found and return the total count at the end.

Add your answer

Q12. Partition Equal Subset Sum Problem

Given an array ARR consisting of 'N' positive integers, determine if it is possible to partition the array into two subsets such that the sum of the elements in both subsets i...read more

Ans.

The problem is to determine if it is possible to partition an array into two subsets with equal sum.

  • Use dynamic programming to solve this problem efficiently.

  • Create a 2D array to store the results of subproblems.

  • Check if the sum of the array is even before attempting to partition it.

  • Iterate through the array and update the 2D array based on the sum of subsets.

  • Return true if a subset with half the sum is found, false otherwise.

Add your answer

Q13. Palindromic Substrings Problem Statement

Given a string S, your task is to return all distinct palindromic substrings of the given string in alphabetical order.

Explanation:

A string is considered a palindrome ...read more

Ans.

Return all distinct palindromic substrings of a given string in alphabetical order.

  • Iterate through all possible substrings of the given string

  • Check if each substring is a palindrome

  • Store distinct palindromic substrings in alphabetical order

Add your answer

Q14. Find All Occurrences in Matrix

You are provided with a matrix of characters, CHARACTER_MATRIX of size M x N, and a string WORD. Your goal is to locate and display all occurrences of the string within the matrix...read more

Ans.

The goal is to find all occurrences of a given string in a matrix in all eight possible directions.

  • Iterate through each cell in the matrix and check for the starting character of the word.

  • For each starting character found, check in all eight directions for the complete word.

  • Keep track of the coordinates of each character in the word for each occurrence.

  • Print the coordinates of each character for each occurrence found.

  • If no occurrences are found, output 'No match found'.

Add your answer

Q15. LCA of Binary Tree Problem Statement

You are given a binary tree consisting of distinct integers and two nodes, X and Y. Your task is to find and return the Lowest Common Ancestor (LCA) of these two nodes.

The ...read more

Ans.

Find the Lowest Common Ancestor (LCA) of two nodes in a binary tree.

  • Traverse the binary tree to find the paths from the root to nodes X and Y.

  • Compare the paths to find the last common node, which is the LCA.

  • Handle cases where one node is an ancestor of the other.

  • Consider edge cases like when X or Y is the root node.

  • Implement a recursive or iterative solution to find the LCA efficiently.

Add your answer

Q16. 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
Add your answer
Q17. ...read more

Number and Digits Problem Statement

You are provided with a positive integer N. Your task is to identify all numbers such that the sum of the number and its digits equals N.

Example:

Input:
N = 21
Output:
[15]
Ans.

Identify numbers whose sum with digits equals given integer N.

  • Iterate through numbers from 1 to N and check if sum of number and its digits equals N.

  • Use a helper function to calculate sum of digits for a given number.

  • Return -1 if no such number exists for a test case.

Add your answer

Q18. Find All Pairs Adding Up to Target

Given an array of integers ARR of length N and an integer Target, your task is to return all pairs of elements such that they add up to the Target.

Input:

The first line conta...read more
Ans.

Find all pairs of elements in an array that add up to a given target.

  • Iterate through the array and store each element in a hashmap along with its index.

  • For each element, check if the target minus the element exists in the hashmap.

  • If found, print the pair of elements. If not found, print (-1, -1).

Add your answer

Q19. 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

Ans.

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

Add your answer

Q20. Valid Parentheses Problem Statement

Given a string 'STR' consisting solely of the characters “{”, “}”, “(”, “)”, “[” and “]”, determine if the parentheses are balanced.

Input:

The first line contains an integer...read more
Ans.

The task is to determine if a given string consisting of parentheses is balanced or not.

  • Iterate through each character in the string and use a stack to keep track of opening parentheses

  • If an opening parenthesis is encountered, push it onto the stack

  • If a closing parenthesis is encountered, check if it matches the top of the stack. If not, the string is not balanced

  • If all parentheses are matched correctly and the stack is empty at the end, the string is balanced

Add your answer

Q21. Heap Sort Problem Statement

Your task is to sort an array of integers in non-decreasing order using the Heap Sort algorithm.

Input:

The first line contains an integer 'T' denoting the number of test cases.
Each...read more
Ans.

Heap Sort algorithm is used to sort an array of integers in non-decreasing order.

  • Implement Heap Sort algorithm to sort the array in non-decreasing order.

  • Use a max heap to sort the array in ascending order.

  • Time complexity of Heap Sort is O(n log n).

Add your answer

Q22. Design a website similar to bookmyshow.com for booking cinema tickets but it must be for a single location only which can have multiple theatres in it. In this he wanted me to design a basic rough GUI, relevant...

read more
Ans.

Design a website similar to bookmyshow.com for booking cinema tickets for a single location with multiple theatres.

  • Design a user-friendly GUI with options for advance booking, user login, user registration, movie rating, and saving card details.

  • Create relevant database tables to store information about movies, theatres, bookings, user details, and card details.

  • Link the GUI to the database to enable data flow and retrieval.

  • Implement features like advance booking, where users c...read more

Add your answer

Q23. Rotational Equivalence of Strings Problem Statement

Given two strings 'P' and 'Q' of equal length, determine if string 'P' can be transformed into string 'Q' by cyclically rotating it to the right any number of...read more

Add your answer

Q24. 1. Write a program to remove duplicate elements from String and mention the count of duplication.

Ans.

Program to remove duplicate elements from String and count their occurrences.

  • Create a HashSet to store unique characters from the String.

  • Iterate through the String and add each character to the HashSet.

  • While adding, check if the character already exists in the HashSet and increment its count.

  • Print the count of each character that has duplicates.

  • Return the modified String with duplicates removed.

View 3 more answers

Q25. 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

Ans.

Transpose a given matrix by switching rows and columns.

  • Iterate through the matrix and swap elements at [i][j] with [j][i].

  • Create a new matrix to store the transposed values.

  • Ensure the dimensions of the transposed matrix are switched from the original matrix.

Add your answer

Q26. Convert Sentence to Pascal Case

Given a string STR, your task is to remove spaces from STR and convert it to Pascal case format. The function should return the modified STR.

In Pascal case, words are concatenat...read more

Ans.

Convert a given string to Pascal case format by removing spaces and capitalizing the first letter of each word.

  • Iterate through each character in the string

  • If the character is a space, skip it

  • If the character is not a space and the previous character is a space or it is the first character, capitalize it

Add your answer

Q27. Infix to Postfix Conversion

You are provided with a string EXP which represents a valid infix expression. Your task is to convert this given infix expression into a postfix expression.

Explanation:

An infix exp...read more

Ans.

Convert a given infix expression to a postfix expression.

  • Use a stack to keep track of operators and operands

  • Follow the rules of precedence for operators

  • Convert the infix expression to postfix using the stack

  • Handle parentheses by pushing them onto the stack and popping when necessary

Add your answer

Q28. Merge Two Sorted Linked Lists Problem Statement

You are provided with two sorted linked lists. Your task is to merge them into a single sorted linked list and return the head of the combined linked list.

Input:...read more

Ans.

Merge two sorted linked lists into a single sorted linked list with linear time complexity and constant space usage.

  • Iterate through both linked lists simultaneously, comparing elements and merging them into a new linked list

  • Update the pointers of the new linked list as you merge elements from the two input linked lists

  • Ensure to handle cases where one linked list is empty or both linked lists are empty

  • Maintain the sorted order while merging the elements from the two linked lis...read more

Add your answer

Q29. Best Time To Buy and Sell Stock Problem Statement

You are given an array 'PRICES' of 'N' integers, where 'PRICES[i]' represents the price of a certain stock on the i-th day. An integer 'K' is also provided, ind...read more

Add your answer

Q30. Tell me about the OS your phone uses? What are the other phone operating systems available in the market

Ans.

My phone uses iOS. Other phone operating systems available in the market are Android, Windows, and Blackberry OS.

  • iOS is developed by Apple and is exclusive to iPhones and iPads.

  • Android is developed by Google and is used by various phone manufacturers such as Samsung, LG, and HTC.

  • Windows is developed by Microsoft and is used by Nokia and other phone manufacturers.

  • Blackberry OS is developed by Blackberry and is exclusive to Blackberry phones.

View 1 answer

Q31. Kth Largest Element Problem Statement

Ninja enjoys working with numbers, and Alice challenges him to find the Kth largest value from a given list of numbers.

Input:

The first line contains an integer 'T', repre...read more
Add your answer

Q32. Provided a string a character and a count, you have to print the string after the specified character has occurred count number of times. Ex: String: “This is demo string” Character: ‘i’ Count: 3 Output: “ng” H...

read more
Ans.

The program prints the substring after a specified character has occurred a certain number of times in a given string.

  • Iterate through the string to find the specified character.

  • Keep track of the count of occurrences of the character.

  • Once the count reaches the specified count, extract the substring after that position.

  • Handle corner cases such as when the character is not in the string or when it doesn't occur the specified number of times.

Add your answer

Q33. Valid Parenthesis Problem Statement

Given a string str composed solely of the characters "{", "}", "(", ")", "[", and "]", determine whether the parentheses are balanced.

Input:

The first line contains an integ...read more
Ans.

Check if given string of parentheses is balanced or not.

  • Use a stack to keep track of opening parentheses

  • Pop from stack when encountering a closing parenthesis

  • Return 'YES' if stack is empty at the end, 'NO' otherwise

Add your answer

Q34. Subarray Challenge: Largest Equal 0s and 1s

Determine the length of the largest subarray within a given array of 0s and 1s, such that the subarray contains an equal number of 0s and 1s.

Input:

Input begins with...read more

Ans.

Find the length of the largest subarray with equal number of 0s and 1s in a given array.

  • Iterate through the array and maintain a count of 0s and 1s encountered so far.

  • Store the count difference in a hashmap with the index as key.

  • If the same count difference is encountered again, the subarray between the two indices has equal 0s and 1s.

  • Return the length of the largest such subarray found.

Add your answer

Q35. There N rooms in a hotel so customers will check-in and check-out a rooms simultaneously so which type of data structure you implement and it should be efficient and extension of this prebooking will also happe...

read more
Ans.

To efficiently manage room bookings and prebookings in a hotel, a priority queue data structure can be implemented.

  • A priority queue can be used to prioritize room bookings based on check-in dates.

  • When a customer checks out, the room becomes available and can be assigned to the next customer in the priority queue.

  • Prebookings can be stored separately and checked against the availability of rooms before assigning them to customers.

  • The priority queue can be implemented using a bi...read more

Add your answer

Q36. 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

Add your answer

Q37. Detect and Remove Loop in Linked List

For a given singly linked list, identify if a loop exists and remove it, adjusting the linked list in place. Return the modified linked list.

Expected Complexity:

Aim for a...read more

Add your answer

Q38. Greatest Common Divisor Problem Statement

You are tasked with finding the greatest common divisor (GCD) of two given numbers 'X' and 'Y'. The GCD is defined as the largest integer that divides both of the given...read more

Ans.

Finding the greatest common divisor (GCD) of two given numbers 'X' and 'Y'.

  • Iterate through each test case

  • Use Euclidean algorithm to find GCD

  • Output the GCD for each test case

Add your answer

Q39. Sum Tree Conversion

Convert a given binary tree into its sum tree. In a sum tree, every node's value is replaced with the sum of its immediate children's values. Leaf nodes are set to 0. Finally, return the pre...read more

Ans.

Convert a binary tree into a sum tree by replacing each node's value with the sum of its children's values. Return the preorder traversal of the sum tree.

  • Traverse the tree in a bottom-up manner to calculate the sum of children for each node.

  • Set leaf nodes to 0 and update non-leaf nodes with the sum of their children.

  • Return the preorder traversal of the modified tree.

Add your answer

Q40. Convert a Number to Words

Given an integer number num, your task is to convert 'num' into its corresponding word representation.

Input:

The first line of input contains an integer ‘T’ denoting the number of tes...read more
Ans.

Convert a given integer number into its corresponding word representation.

  • Implement a function that takes an integer as input and returns the word representation of the number in English lowercase letters.

  • Break down the number into its individual digits and convert each digit into its word form (e.g., 1 to 'one', 2 to 'two').

  • Combine the word forms of individual digits to form the word representation of the entire number.

  • Ensure there is a space between consecutive words and th...read more

Add your answer

Q41. Merge K Sorted Arrays Problem Statement

Given 'K' different arrays that are individually sorted in ascending order, merge all these arrays into a single array that is also sorted in ascending order.

Input

The f...read more
Ans.

Merge K sorted arrays into a single sorted array.

  • Iterate through all arrays and merge them using a min-heap.

  • Use a priority queue to efficiently merge the arrays.

  • Time complexity can be optimized to O(N log K) using a min-heap.

Add your answer

Q42. Subarray With Given Sum Problem Statement

Given an array ARR of N integers and an integer S, determine if there exists a contiguous subarray within the array with a sum equal to S. If such a subarray exists, re...read more

Add your answer
Q43. Can you write a SQL query that joins two tables A and B on the common attribute ID and selects records (ID_NAME) that have matching ID values in both tables?
Ans.

Yes, I can write a SQL query to join two tables on a common attribute and select matching records.

  • Use INNER JOIN to join tables A and B on the common attribute ID

  • Select the records (ID_NAME) where ID values match in both tables

Add your answer
Q44. Why is Java considered platform independent, while the Java Virtual Machine (JVM) is platform dependent?
Ans.

Java is platform independent because the code is compiled into bytecode that can run on any system with a JVM, which is platform dependent.

  • Java code is compiled into bytecode, which is a platform-independent intermediate code

  • The JVM interprets and executes the bytecode on different platforms, making it platform dependent

  • The JVM acts as a layer of abstraction between the Java code and the underlying operating system

  • Example: A Java program compiled on a Windows machine can run ...read more

Add your answer

Q45. There are five glasses that are kept upside down.At a time you are bound to turn four glasses.Give minimum number of times in which you can turn back all the glasses so that now none among them are upside down

Ans.

Minimum number of times to turn all glasses upside down when 4 can be turned at a time.

  • Turn over any four glasses, leaving one untouched.

  • Repeat the above step until only one glass is left upside down.

  • Finally, turn over the last glass to complete the task.

  • Minimum number of turns required is 3.

Add your answer

Q46. Vertical Sum in a Binary Tree

Given a binary tree with positive integers at each node, calculate the vertical sum for node values, where the vertical sum is the sum of nodes that can be connected by a vertical ...read more

Ans.

Calculate the vertical sum of node values in a binary tree.

  • Traverse the binary tree in a vertical order and keep track of the sum for each vertical line.

  • Use a hashmap to store the sum for each vertical line.

  • Recursively traverse the tree, updating the sum for each vertical line as you go.

  • Output the vertical sums for each test case in the order they were given.

Add your answer

Q47. Graph Coloring Problem

You are given a graph with 'N' vertices numbered from '1' to 'N' and 'M' edges. Your task is to color this graph using two colors, such as blue and red, in a way that no two adjacent vert...read more

Ans.

Given a graph with 'N' vertices and 'M' edges, determine if it can be colored using two colors without adjacent vertices sharing the same color.

  • Use graph coloring algorithm like BFS or DFS to check if it is possible to color the graph with two colors.

  • Check if any adjacent vertices have the same color. If yes, then it is not possible to color the graph as described.

  • If the graph has connected components, color each component separately to determine if the entire graph can be co...read more

Add your answer

Q48. Preorder Traversal to BST Problem Statement

Given an array or list PREORDER representing the preorder traversal of a Binary Search Tree (BST) with N nodes, construct the BST which matches the given preorder tra...read more

Ans.

Given a preorder traversal of a BST, construct the BST and print its inorder traversal.

  • Parse the input to get the number of test cases and preorder traversal for each case

  • Construct the BST using the preorder traversal by recursively building the tree

  • Print the inorder traversal of the constructed BST for each test case

Add your answer

Q49. Find The Repeating And Missing Number Problem Statement

You are provided with an array nums which contains the first N positive integers. In this array, one integer appears twice, and one integer is missing. Yo...read more

Ans.

Given an array of first N positive integers with one number repeating and one missing, find the repeating and missing numbers.

  • Iterate through the array and keep track of the sum of elements and sum of squares of elements.

  • Calculate the missing number using the formula: missing = N*(N+1)/2 - sum of elements.

  • Calculate the repeating number using the formula: repeating = missing + sum of elements - sum of squares of elements.

Add your answer

Q50. Inplace Rotate Matrix 90 Degrees Anti-Clockwise

You are provided with a square matrix of non-negative integers of size 'N x N'. The task is to rotate this matrix by 90 degrees in an anti-clockwise direction wit...read more

Ans.

Rotate a square matrix by 90 degrees anti-clockwise without using extra space.

  • Iterate through each layer of the matrix from outer to inner layers

  • Swap elements in groups of 4 to rotate the matrix in place

  • Handle odd-sized matrices separately by adjusting the loop boundaries

Add your answer

Q51. Regular Expression Match Problem Statement

Given a string str and a string pat, where str may contain wildcard characters '?' and '*'.

If a character is '?', it can be replaced with any single character. If a c...read more

Ans.

The task is to determine if it is possible to transform a string to match another string using wildcard characters '?' and '*'.

  • Iterate through both strings simultaneously, handling wildcard characters '?' and '*' accordingly.

  • Use dynamic programming to keep track of matching subproblems.

  • Return true if at the end both strings match, false otherwise.

Add your answer

Q52. Bursting Balloons Problem

Given an array ARR of size N, where each element represents the height of a balloon. The task is to destroy all balloons by shooting arrows from left to right. When an arrow hits a bal...read more

Ans.

Find the minimum number of arrows needed to burst all balloons by shooting arrows from left to right.

  • Sort the array in ascending order to make it easier to determine the minimum number of arrows needed.

  • Iterate through the sorted array and count the number of times the height decreases.

  • The count of height decreases plus 1 gives the minimum number of arrows needed to burst all balloons.

Add your answer

Q53. Validate BST Problem Statement

Given a binary tree with N nodes, determine whether the tree is a Binary Search Tree (BST). If it is a BST, return true; otherwise, return false.

A binary search tree (BST) is a b...read more

Ans.

Validate if a binary tree is a Binary Search Tree (BST) based on given properties.

  • Check if the left subtree of a node contains only nodes with data less than the node's data.

  • Verify if the right subtree of a node contains only nodes with data greater than the node's data.

  • Ensure that both the left and right subtrees are also binary search trees.

  • Iterate through the tree in level order form to validate the BST properties.

Add your answer

Q54. Rearrange The Array Problem Statement

You are given an array/list 'NUM' of integers. Rearrange the elements of 'NUM' such that no two adjacent elements are the same in the rearranged array.

Example:

Input:
NUM[...read more
Ans.

The task is to rearrange an array such that no two adjacent elements are the same.

  • Iterate through the array and check if any adjacent elements are the same.

  • If adjacent elements are the same, swap one of them with a different element.

  • Return 'YES' if a valid rearrangement is possible, 'NO' otherwise.

Add your answer

Q55. There are 25 horses in which you need to find out the fastest 3 horses. you can conduct a race among at most 5 horses to find out relative speed. At no point, you can find out the actual speed of the horse in a...

read more
Ans.

Minimum 7 races required to find the top 3 fastest horses.

  • Divide the 25 horses into 5 groups of 5 horses each.

  • Conduct a race among the horses in each group to determine the fastest horse in each group.

  • Take the top 2 horses from each group and conduct a race among them to determine the fastest horse overall.

  • The winner of this race is the fastest horse.

  • Now, take the second-place horse from the final race and the second-place horse from each group race.

  • Conduct a race among these...read more

Add your answer
Q56. Can you explain the different types of normalization forms in a DBMS?
Ans.

Normalization forms in a DBMS help reduce data redundancy and improve data integrity.

  • 1NF (First Normal Form) - Each column contains atomic values, and there are no repeating groups.

  • 2NF (Second Normal Form) - Meets 1NF and all non-key attributes are fully functional dependent on the primary key.

  • 3NF (Third Normal Form) - Meets 2NF and there are no transitive dependencies between non-key attributes.

  • BCNF (Boyce-Codd Normal Form) - Every determinant is a candidate key.

  • 4NF (Fourth ...read more

Add your answer

Q57. 4. What is marker interface? Example of marker interface. Why it is used.

Ans.

Marker interface is an interface with no methods. It is used to mark a class for special treatment.

  • Marker interface is used to provide metadata to the JVM.

  • It is used to indicate that a class has some special behavior or characteristics.

  • Example: Serializable interface in Java.

  • Marker interfaces are used for reflection and serialization.

  • They are also used in frameworks like Spring and Hibernate.

  • Marker interfaces are also known as tagging interfaces.

  • They are used to group classes...read more

Add your answer

Q58. Construct Tree from Preorder Traversal

Given a list of integers pre[] of size n, representing the preorder traversal of a special binary tree where each node has 0 or 2 children, and a boolean array isLeaf[] in...read more

Ans.

Construct a binary tree from preorder traversal and leaf node information.

  • Create a binary tree using preorder traversal and leaf node information

  • Use recursion to build the tree

  • Handle both leaf and non-leaf nodes appropriately

Add your answer

Q59. Check if a Number is Binary

Determine if a given string of integers bin represents a valid binary number. Return 'true' if the string represents a valid binary number, otherwise return 'false'. A binary number ...read more

Ans.

Check if a given string represents a valid binary number composed of 0s and 1s.

  • Iterate through each character in the string and check if it is either '0' or '1'.

  • If any character is not '0' or '1', return 'false'.

  • Return 'true' if all characters are '0' or '1'.

Add your answer

Q60. Anagram Pairs Verification Problem

Your task is to determine if two given strings are anagrams of each other. Two strings are considered anagrams if you can rearrange the letters of one string to form the other...read more

Ans.

Determine if two strings are anagrams of each other by checking if they have the same characters in different order.

  • Create character frequency maps for both strings

  • Compare the frequency of characters in both maps to check if they are anagrams

  • Return True if the frequencies match, False otherwise

Add your answer

Q61. There are 25 horses and only 5 horses can be raced at a time and the top 3 are announced in each such race. What is the minimum number of races required to find the top 3 among 25 horses

Ans.

The minimum number of races required to find the top 3 among 25 horses is 7.

  • Divide the 25 horses into 5 groups of 5 horses each.

  • Race the 5 groups, which will give us the top 3 horses from each group.

  • Now we have 15 horses remaining.

  • Race the top 3 horses from each group, which will give us the top 3 horses overall.

  • This requires a total of 7 races.

Add your answer

Q62. Code: – Given the value of a starting position and an ending position, you have to reach from start to end in a linear way, and you can move either to position immediate right to current position or two step ri...

read more
Ans.

Print all possible paths from start to end in a linear way, moving either one or two steps right.

  • Use dynamic programming to solve the problem

  • Create a 2D array to store the number of paths to each position

  • Start from the end position and work backwards

  • At each position, calculate the number of paths by summing the number of paths from the next two positions

  • Print all the paths by backtracking from the start position

Add your answer

Q63. Remove BST Keys Outside Given Range

Given a Binary Search Tree (BST) and a specified range [min, max], your task is to remove all keys from the BST that fall outside this range. The BST should remain valid afte...read more

Add your answer

Q64. 2. Write a program to capitalise all the first letter of a word in a sentence.

Ans.

A program to capitalize the first letter of each word in a sentence.

  • Split the sentence into words

  • Loop through each word and capitalize the first letter

  • Join the words back into a sentence

View 2 more answers

Q65. Root to Leaf Path Problem Statement

Given a binary tree with 'N' nodes numbered from 1 to 'N', your task is to print all the root-to-leaf paths of the binary tree.

Input:

The first line of the input contains a ...read more
Ans.

Given a binary tree, print all root-to-leaf paths in order.

  • Traverse the binary tree from root to leaf nodes, keeping track of the path nodes.

  • Use depth-first search (DFS) to explore all possible paths.

  • Return each path as a string of nodes separated by spaces.

  • Handle cases where nodes have NULL values by skipping them in the path.

  • Ensure the order of nodes in each path is maintained.

Add your answer

Q66. #Introduction 1. What is White box testing, Black box testing, Grey box testing? 2. Explain Bug Life cycle? 3. What is Deferred? 4. Open Flipkart application, Search for Some product eg, phone, Write the test c...

read more
Ans.

Interview questions for Test Engineer position covering topics like testing types, bug life cycle, constructors, locators, and priority/severity.

  • White box testing is testing the internal structure of the application, black box testing is testing the functionality without knowledge of internal structure, and grey box testing is a combination of both.

  • Bug life cycle includes stages like new, open, assigned, fixed, verified, and closed.

  • Deferred means postponing the bug fix to a l...read more

Add your answer
Q67. Can you explain the concepts of method overloading and method overriding in object-oriented programming?
Ans.

Method overloading is when multiple methods in the same class have the same name but different parameters. Method overriding is when a subclass provides a specific implementation of a method that is already provided by its superclass.

  • Method overloading allows a class to have multiple methods with the same name but different parameters. For example, having multiple constructors in a class with different parameter lists.

  • Method overriding occurs when a subclass provides a specif...read more

Add your answer

Q68. 6. Consider an array of String, remove those string from array whose length is less than 3.

Ans.

Remove strings from an array whose length is less than 3.

  • Loop through the array and check the length of each string.

  • If the length is less than 3, remove that string from the array.

  • Use a for loop or filter method to remove the strings.

  • Example: ['cat', 'dog', 'bird', 'elephant'] -> ['cat', 'dog', 'bird', 'elephant']

  • Example: ['a', 'to', 'the', 'in'] -> ['the', 'in']

View 1 answer

Q69. Merge Sort Problem Statement

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 Algorithm is a D...read more

Ans.

Implement the merge sort algorithm to sort a given sequence of numbers in non-descending order.

  • Divide the input array into two halves recursively until each subarray has only one element.

  • Merge the sorted subarrays back together in non-descending order.

  • Time complexity of merge sort is O(n log n) and space complexity is O(n).

Add your answer

Q70. Implementing a Priority Queue Using Heap

Ninja has been tasked with implementing a priority queue using a heap data structure. However, he is currently busy preparing for a tournament and has requested your ass...read more

Ans.

Implement a priority queue using a heap data structure by completing the provided functions.

  • Implement push() function to insert elements into the queue.

  • Implement pop() function to remove the largest element from the queue.

  • Implement getMaxElement() function to return the largest element.

  • Implement isEmpty() function to check if the queue is empty.

Add your answer

Q71. LRU Cache Design Question

Design a data structure for a Least Recently Used (LRU) cache that supports the following operations:

1. get(key) - Return the value of the key if it exists in the cache; otherwise, re...read more

Ans.

Design a Least Recently Used (LRU) cache data structure that supports get and put operations with capacity constraint.

  • Implement a doubly linked list to keep track of the order of keys based on their recent usage.

  • Use a hashmap to store key-value pairs for quick access and update.

  • When capacity is reached, evict the least recently used item before inserting a new item.

  • Handle get and put operations efficiently to maintain the LRU property.

  • Ensure the time complexity of operations ...read more

Add your answer

Q72. Reverse a String Problem Statement

Given a string STR containing characters from [a-z], [A-Z], [0-9], and special characters, determine the reverse of the string.

Input:

The input starts with a single integer '...read more
Ans.

Reverse a given string containing characters from [a-z], [A-Z], [0-9], and special characters.

  • Iterate through each character in the string and append them in reverse order to a new string

  • Use built-in functions like reverse() or slice() to reverse the string

  • Handle special characters and numbers along with alphabets

Add your answer

Q73. 4. When to use list and when to use linked list.

Ans.

Lists are used for small collections, linked lists for large or frequently modified collections.

  • Use lists for small collections that don't require frequent modifications.

  • Use linked lists for large collections or collections that require frequent modifications.

  • Linked lists are better for inserting or deleting elements in the middle of the collection.

  • Lists are better for accessing elements by index.

  • Example: Use a list to store a small list of names, use a linked list to impleme...read more

Add your answer

Q74. Convert a Binary Tree to its Sum Tree

Given a binary tree of integers, convert it to a sum tree where each node is replaced by the sum of the values of its left and right subtrees. Set leaf nodes to zero.

Input...read more

Ans.

Convert a binary tree to a sum tree by replacing each node with the sum of its left and right subtrees, setting leaf nodes to zero.

  • Traverse the tree in postorder fashion to calculate the sum of left and right subtrees for each node.

  • Set leaf nodes to zero by checking if a node has no children.

  • Update the value of each node to be the sum of its left and right subtrees.

  • Return the level order traversal of the converted sum tree.

Add your answer

Q75. Intersection of Linked List Problem

You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.

Your task is to determine the data...read more

Ans.

Find the node where two linked lists merge, return -1 if no merging occurs.

  • Traverse both lists to find their lengths and the difference in lengths

  • Move the pointer of the longer list by the difference in lengths

  • Traverse both lists simultaneously until they meet at the merging point

Add your answer

Q76. How can you create a 3-tier architecture? What are the alternatives of Load Balancer? How can you create PV and PVC in Kubernetes? How much you know about the cloud and networking? How on-prem is different from...

read more
Ans.

Answering questions related to 3-tier architecture, load balancer alternatives, PV and PVC creation in Kubernetes, cloud and networking, on-prem vs cloud, and server migration tools.

  • To create a 3-tier architecture, separate the presentation layer, application layer, and database layer into three distinct tiers.

  • Alternatives to Load Balancer include DNS-based load balancing and IP-based load balancing.

  • To create PV and PVC in Kubernetes, use the kubectl command-line tool or YAML...read more

Add your answer

Q77. Spring Collections Difference between list and set What is sorted mean in hashed set java Serialization Exceptions How can you give an exception to caller method Unix- how to move a folder without giving yes/no...

read more
Ans.

Interview questions for Software Developer related to Spring, Collections, Serialization, Exceptions, Unix, Annotations, Json, Build tools, Restful services, and more.

  • List and Set are both collection interfaces in Java. List allows duplicates and maintains insertion order while Set doesn't allow duplicates and doesn't maintain any order.

  • Sorted in Hashed Set means that the elements are stored in a sorted order based on their hash code.

  • Serialization is the process of converting...read more

Add your answer

Q78. Modified Balanced Parentheses where a character can be matched with any other character, i.e. / with &, ! with ? and so on.

Ans.

Modified Balanced Parentheses where characters can be matched with any other character.

  • Use a stack to keep track of opening characters

  • When encountering a closing character, check if it matches the top of the stack

  • If it matches, pop from the stack, else return false

  • Continue until end of string, return true if stack is empty

Add your answer

Q79. BST to Greater Tree Conversion

Convert a given binary search tree (BST) with 'N' nodes into a Greater Tree. In this transformation, each node's data is modified to the sum of the original node's data plus the s...read more

Ans.

Convert a given BST into a Greater Tree by updating each node's data to the sum of original data and all greater nodes' data.

  • Traverse the BST in reverse inorder (right, root, left) to update nodes' data.

  • Keep track of the sum of greater nodes' data while traversing.

  • Update each node's data by adding the sum of greater nodes' data to the original data.

  • Example: Input BST: 4 1 6 0 2 5 7 -1 -1 -1 3 -1 -1 -1 -1. Output Greater Tree: 22 26 15 30 27 18 7 -1 -1 -1 33 -1 -1 -1 -1.

Add your answer

Q80. What are abstract classes in Java and what is the difference between an abstract class and an interface

Ans.

Abstract classes in Java are classes that cannot be instantiated and are used as blueprints for other classes.

  • Abstract classes cannot be instantiated, meaning you cannot create objects of an abstract class.

  • Abstract classes can have both abstract and non-abstract methods.

  • Interfaces in Java are similar to abstract classes, but they cannot have any method implementations.

  • A class can implement multiple interfaces, but it can only extend one abstract class.

  • Abstract classes can hav...read more

Add your answer
Q81. What is the difference between a clustered index and a non-clustered index?
Ans.

Clustered index physically reorders the data in the table, while non-clustered index does not.

  • Clustered index determines the physical order of data in the table, while non-clustered index does not.

  • A table can have only one clustered index, but multiple non-clustered indexes.

  • Clustered index is faster for retrieval of data, as it directly points to the actual data rows.

  • Non-clustered index is faster for retrieval of specific data, as it points to a separate list of pointers to t...read more

Add your answer

Q82. What is the difference between a micro controller and a micro processor?

Ans.

Microcontroller is a self-contained system with memory, peripherals and processor, while microprocessor only has a processor.

  • Microcontroller has on-chip memory and peripherals, while microprocessor requires external memory and peripherals.

  • Microcontroller is used in embedded systems, while microprocessor is used in general-purpose computing.

  • Examples of microcontrollers include Arduino, PIC, and AVR, while examples of microprocessors include Intel Pentium, AMD Ryzen, and ARM Co...read more

Add your answer

Q83. Given an array of strings, print all the possible combinations of strings created by picking one character from each string of the array. The individual strings do not contain any duplicates. Ex: {ABC, DE} Ans...

read more
Ans.

Print all possible combinations of strings by picking one character from each string in the array.

  • Iterate through each character of the first string and combine it with each character of the second string.

  • Repeat the process for all strings in the array to get all possible combinations.

  • Use nested loops to generate combinations efficiently.

Add your answer

Q84. Write a code for inserting two numbers in a text file given n2>n1 and the next entry should not be overlapping like if first was 4,6 next can't be 5,7.the second n1 has to be greater than first n2

Ans.

The code inserts two numbers in a text file, ensuring that the second number is greater than the first and there is no overlap between entries.

  • Read the existing entries from the text file

  • Check if the new numbers satisfy the conditions

  • If conditions are met, insert the new numbers into the file

  • Otherwise, display an error message

Add your answer

Q85. 10. Write a program to separate even and odd numbers using Java 8.

Ans.

Program to separate even and odd numbers using Java 8.

  • Use Java 8 Stream API to filter even and odd numbers

  • Create two separate lists for even and odd numbers

  • Use lambda expressions to filter the numbers

  • Example: List evenNumbers = numbers.stream().filter(n -> n % 2 == 0).collect(Collectors.toList());

  • Example: List oddNumbers = numbers.stream().filter(n -> n % 2 != 0).collect(Collectors.toList());

View 1 answer
Q86. What is the difference between an Abstract Class and an Interface in Java?
Ans.

Abstract class can have both abstract and non-abstract methods, while interface can only have abstract methods.

  • Abstract class can have constructors, member variables, and methods, while interface cannot have any of these.

  • A class can extend only one abstract class but can implement multiple interfaces.

  • Abstract classes are used to provide a common base for subclasses, while interfaces are used to define a contract for classes to implement.

  • Example: Abstract class - Animal with a...read more

Add your answer

Q87. 3. How to remove sensitive information from serializable interface.

Ans.

Sensitive information can be removed from serializable interface by implementing custom serialization.

  • Create a custom serialization method that excludes sensitive information.

  • Use the transient keyword to mark sensitive fields as non-serializable.

  • Consider using encryption or hashing to protect sensitive data.

  • Test serialization and deserialization to ensure sensitive information is not included.

  • Examples: exclude passwords, credit card numbers, and personal identification inform...read more

Add your answer

Q88. Can an array have elements of different data types?

Ans.

Yes, an array can have elements of different data types.

  • An array can have elements of different data types, but it's not recommended.

  • It can make the code harder to read and maintain.

  • For example, an array can have both strings and numbers: ['apple', 5, 'banana']

View 1 answer

Q89. Subset sum variant, find missing number using single loop, difference between two dates, , Core Java concept , Sql, finding duplicate number in list, finding loop in linkedlist, finding node where cycle starts...

read more
Ans.

Interview questions for Application Engineer role covering various topics.

  • Subset sum variant - finding a subset of numbers that add up to a given sum

  • Single loop missing number - finding a missing number in an array using a single loop

  • Difference between two dates - calculating the difference between two dates in Java

  • Core Java concepts - knowledge of basic Java concepts such as inheritance, polymorphism, etc.

  • SQL - knowledge of SQL queries and database management

  • Finding duplicat...read more

Add your answer

Q90. Describe in steps how you downloaded any software recently

Ans.

I recently downloaded VLC media player.

  • Visited the official website of VLC media player

  • Clicked on the download button

  • Selected the appropriate version for my operating system

  • Waited for the download to complete

  • Opened the downloaded file and followed the installation wizard

Add your answer

Q91. What is overloading and what is overriding. Explain each with example

Ans.

Overloading is when multiple methods have the same name but different parameters. Overriding is when a subclass provides a different implementation of a method inherited from its superclass.

  • Overloading allows a class to have multiple methods with the same name but different parameters.

  • Overriding occurs when a subclass provides a different implementation of a method inherited from its superclass.

  • Overloading is resolved at compile-time based on the method signature.

  • Overriding i...read more

Add your answer
Q92. What is the major difference between 32-bit and 64-bit processors?
Ans.

The major difference between 32-bit and 64-bit processors is the amount of memory they can access and process.

  • 32-bit processors can access up to 4GB of RAM, while 64-bit processors can access much more, typically 16 exabytes (16 billion GB) of RAM.

  • 64-bit processors can handle larger chunks of data at once, leading to improved performance in tasks that require intensive calculations or large datasets.

  • Software designed for 64-bit processors may not be compatible with 32-bit pro...read more

Add your answer

Q93. Given a date in string format, write a java program to return the date n days after the given date. Solve the question without using DateTimeFormatter or any similar Date parsing libraries.

Ans.

Java program to calculate date n days after given date without using Date parsing libraries.

  • Parse the input date string to extract day, month, and year components.

  • Calculate the total number of days represented by the input date.

  • Add the specified number of days to the total days calculated.

  • Convert the final total days back to day, month, and year components to get the new date.

Add your answer
Q94. What are the differences between a mutex and a semaphore?
Ans.

Mutex is used for exclusive access to a resource, while semaphore is used for controlling access to a resource by multiple threads.

  • Mutex is binary and allows only one thread to access the resource at a time.

  • Semaphore can have a count greater than one, allowing multiple threads to access the resource simultaneously.

  • Mutex is used for protecting critical sections of code, while semaphore is used for synchronization between threads.

  • Example: Mutex is like a key to a room that only...read more

Add your answer
Q95. Can you explain the concepts of multitasking and multiprogramming?
Ans.

Multitasking involves executing multiple tasks simultaneously, while multiprogramming involves running multiple programs on a single processor.

  • Multitasking allows multiple tasks to run concurrently, switching between them quickly.

  • Multiprogramming involves loading multiple programs into memory and executing them concurrently.

  • Examples of multitasking include running multiple applications on a computer or a smartphone.

  • Examples of multiprogramming include running multiple instanc...read more

Add your answer

Q96. Given a social networking graph find the density of a person. Density is how many friends he had interaction with him and the person by the total number of friends for that person

Ans.

Density of a person in a social networking graph is the ratio of friends who interacted with the person to the total number of friends.

  • Calculate the number of friends who interacted with the person.

  • Calculate the total number of friends for that person.

  • Divide the number of interacting friends by the total number of friends to get the density.

  • Density = (Number of interacting friends) / (Total number of friends)

Add your answer

Q97. How is undo operation (ctrl + z) implemented internally?

Ans.

Undo operation (ctrl + z) is implemented by maintaining a stack of previous states.

  • When a change is made, the current state is pushed onto the stack

  • When undo is called, the top state is popped and applied

  • Redo is implemented by maintaining a stack of undone states

  • Some applications may also implement a limit on the number of undo/redo steps

  • Undo/redo can be implemented at different levels (e.g. character, word, paragraph)

Add your answer
Q98. What is the main difference between UNION and UNION ALL?
Ans.

UNION removes duplicates while UNION ALL does not

  • UNION combines result sets and removes duplicates

  • UNION ALL combines result sets without removing duplicates

  • UNION is slower than UNION ALL as it involves removing duplicates

  • Use UNION when you want to remove duplicates, use UNION ALL when duplicates are acceptable

Add your answer

Q99. 3. How map works internally in Java

Ans.

Java Map is an interface that maps unique keys to values. It works internally using hash table data structure.

  • Map interface is implemented by HashMap, TreeMap, LinkedHashMap, etc.

  • Keys in a map must be unique and values can be duplicated.

  • Hash table data structure is used to store key-value pairs internally.

  • Hashing is used to convert keys into indices of an array where values are stored.

  • Collision resolution techniques like chaining and open addressing are used to handle collisi...read more

Add your answer

Q100. What is rotational shifts. What is web service flow. How will you check ports on Unix or Solaris machine.

Ans.

Rotational shifts refer to working in different shifts at different times. Web service flow is the sequence of steps involved in a web service request. Checking ports on Unix or Solaris machine involves using the netstat command.

  • Rotational shifts involve working in different shifts at different times, such as day shift, night shift, and swing shift.

  • Web service flow involves a sequence of steps, such as sending a request, receiving a response, and processing the data.

  • To check ...read more

Add your answer
1
2
3
4
5
6
7

More about working at Oracle

#22 Best Mega Company - 2022
#3 Best Internet/Product Company - 2022
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at Comvision

based on 619 interviews
Interview experience
4.1
Good
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Interview Questions from Similar Companies

3.5
 • 1.8k Interview Questions
4.0
 • 700 Interview Questions
3.9
 • 537 Interview Questions
3.6
 • 260 Interview Questions
4.0
 • 193 Interview Questions
4.1
 • 140 Interview Questions
View all
Top Oracle Interview Questions And Answers
Share an Interview
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
70 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter