Add office photos
Employer?
Claim Account for FREE

Samsung

3.9
based on 7.2k Reviews
Video summary
Proud winner of ABECA 2024 - AmbitionBox Employee Choice Awards
Filter interviews by

80+ Gauranga Papers Interview Questions and Answers

Updated 19 Dec 2024
Popular Designations

Q1. Minimum Time in Wormhole Network

Determine the minimum time required to travel from a starting point to a destination point in a two-dimensional coordinate system, considering both direct movement and the use o...read more

Ans.

Find the minimum time to travel from a starting point to a destination point using direct movement and wormholes.

  • Calculate the time taken for direct movement from source to destination.

  • Consider using each wormhole to see if it reduces the total travel time.

  • Choose the path with the minimum total time to reach the destination.

Add your answer

Q2. 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 non-decreasing order to make it easier to calculate the minimum number of arrows needed.

  • Iterate through the sorted array and count the number of times the height decreases compared to the previous balloon.

  • The count of decreases + 1 will give the minimum number of arrows needed to burst all balloons.

  • Example: For input N = 5, ARR = [2, 3, 4, 5, 1], the minimum ...read more

Add your answer

Q3. Trapping Rain Water Problem Statement

You are given a long type array/list ARR of size N, representing an elevation map. The value ARR[i] denotes the elevation of the ith bar. Your task is to determine the tota...read more

Ans.

Calculate the total amount of rainwater that can be trapped between given elevations in an array.

  • Iterate through the array and calculate the maximum height on the left and right of each bar.

  • Calculate the amount of water that can be trapped above each bar by taking the minimum of the maximum heights on the left and right.

  • Sum up the trapped water above each bar to get the total trapped water for the entire array.

Add your answer

Q4. Shortest Path in a Binary Matrix Problem Statement

Given a binary matrix of size N * M where each element is either 0 or 1, find the shortest path from a source cell to a destination cell, consisting only of 1s...read more

Ans.

Find the shortest path in a binary matrix from a source cell to a destination cell consisting only of 1s.

  • Use Breadth First Search (BFS) algorithm to find the shortest path.

  • Initialize a queue with the source cell and keep track of visited cells.

  • Explore all 4 directions from each cell and update the path length accordingly.

  • Return the shortest path length or -1 if no valid path exists.

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

Q5. Maximum Gold Collection from Gold Mine

Imagine a gold mine represented by a 2D matrix with dimensions 'N' by 'M', where 'N' is the number of rows and 'M' is the number of columns. Each cell in this matrix conta...read more

Ans.

Find the maximum amount of gold a miner can collect from a gold mine by moving right, up diagonally, or down diagonally.

  • Use dynamic programming to keep track of the maximum gold collected at each cell.

  • At each cell, consider the maximum gold collected from the cell above, below, and to the left.

  • Add the current cell's gold value to the maximum gold collected from the adjacent cells to determine the maximum gold at the current cell.

  • Repeat this process for each cell in the matrix...read more

Add your answer

Q6. 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 to find the missing and repeating numbers.

  • Use a set to identify the repeating number and calculate the missing number based on the sum of elements.

  • Example: For nums = [1, 2, 3, 4, 4, 5], the repeating number is 4 and the missing number is 6.

Add your answer
Are these interview questions helpful?

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

  • Traverse the tree in postorder fashion.

  • For each node, calculate the sum of its left and right subtrees and update the node value.

  • Set leaf nodes to zero.

  • Return the level order traversal of the modified tree.

Add your answer

Q8. Delete a Given Node from Doubly Linked List

Ninja is learning about doubly linked lists and wants to remove a specified element from the list. Can you assist Ninja in doing this and returning the modified linke...read more

Ans.

Remove a specified element from a doubly linked list and return the modified list.

  • Traverse the doubly linked list to find the specified element to be removed.

  • Update the pointers of the previous and next nodes to skip the node to be deleted.

  • Handle edge cases like removing the head or tail of the linked list.

  • Return the modified linked list after removing the specified element.

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

Q9. Gold Mine Problem Statement

You are provided with a gold mine, represented as a 2-dimensional matrix of size N x M with N rows and M columns. Each cell in this matrix contains a positive integer representing th...read more

Ans.

The task is to determine the maximum amount of gold a miner can collect by moving in allowed directions in a gold mine represented as a 2D matrix.

  • Create a 2D DP array to store the maximum gold collected at each cell

  • Iterate through the matrix from left to right and update the DP array based on the allowed directions

  • Return the maximum value in the last column of the DP array as the final result

Add your answer

Q10. Rod Cutting Problem Statement

Given a rod of a certain length, the rod can be divided into different sizes, each with an associated cost. Your task is to determine the maximum cost that can be obtained by cutti...read more

Ans.

The Rod Cutting Problem involves maximizing the profit obtained by cutting a rod into smaller pieces and selling them.

  • Use dynamic programming to solve this problem efficiently.

  • Create a table to store the maximum profit for each sub-length of the rod.

  • Iterate through the rod lengths and update the table with the maximum profit.

  • The final answer will be the maximum profit for the total length of the rod.

Add your answer

Q11. Minimum Operation Needed to Convert to the Given String

You are given two strings str1 and str2. Determine the minimum number of operations required to transform str1 into str2.

Explanation:

An operation is def...read more

Ans.

Determine the minimum number of operations needed to transform one string into another by moving characters to the end.

  • Iterate through each character in str1 and check if it matches the first character in str2.

  • If a match is found, calculate the number of operations needed to move the characters to the end.

  • Return the minimum number of operations needed for each test case, or -1 if transformation is not possible.

Add your answer

Q12. Binary Tree Diameter Problem Statement

You are given a Binary Tree, and you need to determine the length of the diameter of the tree.

The diameter of a binary tree is the length of the longest path between any ...read more

Ans.

Find the diameter of a binary tree, which is the longest path between any two end nodes.

  • Traverse the tree to find the longest path between two nodes.

  • Use recursion to calculate the diameter of the tree.

  • Keep track of the maximum diameter found during traversal.

  • Example: For input 1 2 3 4 -1 5 6 -1 7 -1 -1 -1 -1 -1 -1, the diameter is 6.

Add your answer

Q13. Count Pairs with Given Sum

Given an integer array/list arr and an integer 'Sum', determine the total number of unique pairs in the array whose elements sum up to the given 'Sum'.

Input:

The first line contains ...read more
Ans.

Count the total number of unique pairs in an array whose elements sum up to a given value.

  • Use a hashmap to store the frequency of each element in the array.

  • Iterate through the array and for each element, check if (Sum - current element) exists in the hashmap.

  • Increment the count of pairs if the complement exists in the hashmap.

  • Divide the count by 2 to avoid counting duplicates like (arr[i], arr[j]) and (arr[j], arr[i]) separately.

Add your answer

Q14. Count Subarrays with Given XOR Problem Statement

You are given an array of integers ARR and an integer X. Your task is to determine the number of subarrays of ARR whose bitwise XOR is equal to X.

Example:

Input...read more
Ans.

Count the number of subarrays in an array whose XOR is equal to a given value.

  • Iterate through the array and keep track of XOR values and their frequencies using a hashmap.

  • For each element, calculate the XOR value with all previous elements and check if the XOR value equals the given X.

  • Use the hashmap to count the number of subarrays with XOR equal to X.

  • Time complexity can be optimized to O(N) using a hashmap to store XOR values and their frequencies.

Add your answer

Q15. Count Leaf Nodes in a Binary Tree

Count the number of leaf nodes present in a given binary tree. A binary tree is a data structure where each node has at most two children, known as the left child and the right...read more

Ans.

Count the number of leaf nodes in a binary tree.

  • Traverse the binary tree and count nodes with both children as NULL.

  • Use recursion to traverse the tree efficiently.

  • Handle base cases where the node is NULL or a leaf node.

  • Keep track of the count of leaf nodes as you traverse the tree.

Add your answer

Q16. Reverse Linked List Problem Statement

Given a singly linked list of integers, return the head of the reversed linked list.

Example:

Initial linked list: 1 -> 2 -> 3 -> 4 -> NULL
Reversed linked list: 4 -> 3 -> 2...read more
Ans.

Reverse a singly linked list of integers and return the head of the reversed linked list.

  • Iterate through the linked list and reverse the pointers to point to the previous node.

  • Use three pointers - prev, current, and next to reverse the linked list in O(N) time and O(1) space complexity.

  • Update the head of the reversed linked list as the last node encountered during reversal.

Add your answer

Q17. Rotate Matrix by 90 Degrees Problem Statement

Given a square matrix 'MATRIX' of non-negative integers, rotate the matrix by 90 degrees in an anti-clockwise direction using only constant extra space.

Input:

The ...read more
Ans.

Rotate a square matrix by 90 degrees in an anti-clockwise direction using constant extra space.

  • Iterate through each layer of the matrix and swap elements in groups of 4

  • Transpose the matrix and then reverse each row to achieve the rotation

  • Ensure to handle edge cases like odd-sized matrices

Add your answer

Q18. Reach the Destination Problem Statement

You are given a source point (sx, sy) and a destination point (dx, dy). Determine if it is possible to reach the destination point using only the following valid moves:

    ...read more
Ans.

The problem involves determining if it is possible to reach a destination point from a source point using specified moves.

  • Iterate through each test case and check if the destination point can be reached from the source point using the given moves.

  • Keep track of the current position and try all possible moves to reach the destination point.

  • Return true if the destination point is reachable, otherwise return false.

Add your answer

Q19. 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 the array and use nested loops to find all possible triplets.

  • Use a set to store unique triplets and check if the sum equals the target sum.

  • Handle edge cases like duplicate elements and no valid triplets.

  • Return the triplets found or '-1' if no valid triplet exists.

Add your answer

Q20. Power of Two Problem Statement

Determine whether a given integer N is a power of two. Return true if it is, otherwise return false.

Explanation

An integer 'N' is considered a power of two if it can be expressed...read more

Ans.

Check if a given integer is a power of two or not.

  • Check if the given integer is greater than 0.

  • Use bitwise operations to determine if the integer is a power of two.

  • Return true if the integer is a power of two, otherwise return false.

Add your answer

Q21. 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 into a single array.

  • Use a priority queue to efficiently merge the arrays.

  • Ensure the final array is sorted in ascending order.

Add your answer

Q22. Stack using Two Queues Problem Statement

Develop a Stack Data Structure to store integer values using two Queues internally.

Your stack implementation should provide these public functions:

Explanation:

1. Cons...read more
Ans.

Implement a stack using two queues to store integer values with specified operations.

  • Create a stack class with two queue data members.

  • Implement push(data) by enqueuing the data into one of the queues.

  • Implement pop() by dequeuing all elements from one queue to another until the last element is reached and return it.

  • Implement top() by dequeuing all elements from one queue to another until the last element is reached, return it, and then enqueue it back.

  • Implement size() by retur...read more

Add your answer

Q23. Spiral Order Traversal of a Binary Tree

Given a binary tree with N nodes, your task is to output the Spiral Order traversal of the binary tree.

Input:

The input consists of a single line containing elements of ...read more
Ans.

Implement a function to return the spiral order traversal of a binary tree.

  • Traverse the binary tree level by level, alternating between left to right and right to left.

  • Use a queue to keep track of nodes at each level.

  • Append nodes to the result list in the order they are visited.

  • Handle null nodes appropriately to maintain the spiral order.

  • Example: For input 1 2 3 -1 -1 4 5, the output should be 1 3 2 4 5.

Add your answer

Q24. Quick Sort Problem Statement

You are provided with an array of integers. The task is to sort the array in ascending order using the quick sort algorithm.

Quick sort is a divide-and-conquer algorithm. It involve...read more

Ans.

Yes, the quick sort algorithm can be enhanced to achieve NlogN complexity in the worst case by using a randomized version of the algorithm.

  • Randomized quick sort involves randomly selecting the pivot element to reduce the chances of worst-case scenarios.

  • By choosing a random pivot, the algorithm becomes less predictable and more likely to achieve the desired time complexity.

  • This enhancement helps in avoiding the worst-case scenarios where the pivot selection leads to unbalanced...read more

Add your answer

Q25. Next Greater Number Problem Statement

Given a string S which represents a number, determine the smallest number strictly greater than the original number composed of the same digits. Each digit's frequency from...read more

Ans.

Given a number represented as a string, find the smallest number greater than the original with the same set of digits.

  • Sort the digits in non-increasing order to find the next greater number.

  • Swap the last two digits to get the smallest greater number.

  • If no greater number exists, return -1.

Add your answer

Q26. Trie Data Structure Implementation

Design and implement a Trie (prefix tree) to perform the following operations:

  • insert(word): Add a string "word" to the Trie.
  • search(word): Verify if the string "word" exists...read more
Ans.

Implement a Trie data structure to insert, search, and check for prefixes in strings.

  • Create a TrieNode class with children and isEndOfWord attributes.

  • Implement insert, search, and startsWith methods in the Trie class.

  • Use a Trie to efficiently store and search for strings based on prefixes.

  • Example: insert 'apple', search 'apple' returns true, startsWith 'app' returns true, search 'app' returns false.

Add your answer

Q27. Triplets with Given Sum

Given an array ARR consisting of N integers, find all distinct triplets in the array that add up to a given number K.

Example:

Input:
T = 2
N = 5
ARR = [1, 2, 3, 4, 5]
K = 9
N = 4
ARR = [0, ...read more
Ans.

Find all distinct triplets in an array that add up to a given number.

  • Use three nested loops to iterate through all possible triplets.

  • Sort the array first to easily skip duplicates.

  • Use two-pointer technique to find the remaining element for each triplet.

  • Handle edge cases like empty list or no triplet summing up to K.

Add your answer

Q28. Cycle Detection in a Singly Linked List

Determine if a given singly linked list of integers forms a cycle or not.

A cycle in a linked list occurs when a node's next points back to a previous node in the list. T...read more

Ans.

Detect if a singly linked list forms a cycle by checking if a node's next pointer points back to a previous node.

  • Use Floyd's Cycle Detection Algorithm to determine if there is a cycle in the linked list.

  • Maintain two pointers, one moving at twice the speed of the other, if they meet at any point, there is a cycle.

  • Check if the next pointer of any node points to a previously visited node to detect a cycle.

Add your answer

Q29. Doctor Ninja's House Problem Statement

In a network of 'N' cities with 'M' paths connecting them, Doctor Ninja aims to purchase a house in a city 'X' such that it is possible to reach every other city from city...read more

Ans.

Find the city from which all other cities can be reached in a network of cities connected by paths.

  • Identify the city 'X' from which all other cities can be reached either directly or indirectly.

  • Use depth-first search (DFS) to traverse the graph and find the mother vertex.

  • If multiple options for city 'X' exist, select the city with the smallest number.

  • If no such city exists, return -1.

Add your answer

Q30. Implement a Stack Using Two Queues

You are tasked with implementing a Stack data structure specifically designed to store integer data using two Queues. Utilize the inbuilt Queue for this purpose.

Function Requ...read more

Ans.

Implement a Stack data structure using two Queues for integer data.

  • Use two Queues to simulate the Stack behavior.

  • Push elements by enqueueing them in one Queue.

  • Pop elements by dequeueing all elements from the first Queue to the second Queue, except the last one.

  • Top element can be retrieved by dequeuing all elements from the first Queue to the second Queue and then dequeuing the last element.

  • Size can be obtained by returning the size of the first Queue.

  • Check for isEmpty by chec...read more

Add your answer

Q31. Rotting Oranges Problem Statement

You are given a grid containing oranges where each cell of the grid can contain one of the three integer values:

  • 0 - representing an empty cell
  • 1 - representing a fresh orange...read more
Ans.

Find the minimum time required to rot all fresh oranges in a grid.

  • Use Breadth First Search (BFS) to simulate the rotting process of oranges.

  • Keep track of the time taken to rot all oranges and the count of fresh oranges remaining.

  • If all fresh oranges are not rotten after simulation, return -1.

  • Handle edge cases like empty grid or no fresh oranges present.

  • Example: For the given grid, the minimum time required is 4 seconds.

Add your answer

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

Ans.

Detect and remove loop in a singly linked list in place with O(n) time complexity and O(1) space complexity.

  • Use Floyd's Cycle Detection Algorithm to identify the loop in the linked list.

  • Once the loop is detected, use two pointers approach to find the start of the loop.

  • Adjust the pointers to remove the loop and return the modified linked list.

  • Example: For input 5 2 and 1 2 3 4 5, return 1 2 3 4 5 without the loop.

Add your answer

Q33. Most Stones Removed with Same Row or Column

On a 2-D plane, there are ‘N’ stones placed at some integer coordinate points. Each coordinate point can have at most one stone. A stone can be removed if it shares t...read more

Ans.

Given a 2-D plane with stones at integer coordinate points, find the maximum number of stones that can be removed by sharing the same row or column.

  • Iterate through the stones and create a graph where stones in the same row or column are connected.

  • Use depth-first search (DFS) to find connected components in the graph.

  • The maximum number of stones that can be removed is the total number of stones minus the number of connected components.

Add your answer

Q34. All Possible Balanced Parentheses Problem Statement

Given a positive integer N, generate all possible sequences of balanced parentheses using N pairs of parentheses.

A sequence of brackets is called balanced if...read more

Ans.

Generate all possible sequences of balanced parentheses using N pairs of parentheses.

  • Use backtracking to generate all possible combinations of balanced parentheses.

  • Keep track of the number of opening and closing parentheses used.

  • Add opening parentheses if there are remaining, and add closing parentheses only if there are more opening parentheses than closing.

  • Recursively generate all valid combinations.

  • Return the list of valid combinations for each test case.

Add your answer

Q35. Substrings Differ by One Problem Statement

Ninja needs help in a battle against the string man. Given two strings, 'S' and 'T', the task is to find the number of substrings in 'S' that differ from some substrin...read more

Ans.

The task is to find the number of substrings in 'S' that differ from some substrings of 'T' by exactly one character.

  • Iterate through all substrings of 'S' and 'T' and compare them character by character to find the ones that differ by exactly one character.

  • Use nested loops to generate all possible substrings of 'S' and 'T'.

  • Count the number of substrings that differ by exactly one character and return the total count.

Add your answer

Q36. Cycle Detection in Undirected Graph Problem Statement

You are provided with an undirected graph containing 'N' vertices and 'M' edges. The vertices are numbered from 1 to 'N'. Your objective is to determine whe...read more

Ans.

Detect cycles in an undirected graph.

  • Use Depth First Search (DFS) to detect cycles in the graph.

  • Maintain a visited array to keep track of visited vertices.

  • If a visited vertex is encountered again during DFS, a cycle exists.

  • Check for cycles in each connected component of the graph.

  • Example: For input N=3, Edges=[[1, 2], [2, 3], [1, 3]], output is Yes.

Add your answer

Q37. M - Coloring Problem Statement

Given an undirected graph with 'N' nodes in the form of an adjacency matrix and an integer 'M', determine if it is possible to color the vertices of the graph using at most 'M' co...read more

Ans.

The problem involves determining if a given graph can be colored with at most 'M' colors without adjacent vertices sharing the same color.

  • Create a function that takes the adjacency matrix, number of nodes 'N', and maximum number of colors 'M' as input.

  • Implement a graph coloring algorithm such as backtracking or greedy coloring to check if the graph can be colored with at most 'M' colors.

  • Check if adjacent vertices have the same color while coloring the graph.

  • Return 'Yes' if th...read more

Add your answer

Q38. Circle of Words Problem Statement

Given an array or list of words, determine whether the words can be rearranged to form a circle where the last character of one word matches the first character of the next.

In...read more

Ans.

Check if given words can be rearranged to form a circle where the last character of one word matches the first character of the next.

  • Create a graph where each word is a node and there is an edge between two nodes if the last character of one word matches the first character of the next.

  • Check if the graph is strongly connected, meaning there is a path between every pair of nodes.

  • If the graph is strongly connected, return true; otherwise, return false.

Add your answer

Q39. Longest Palindromic Substring Problem Statement

You are provided with a string STR of length N. The task is to find the longest palindromic substring within STR. If there are several palindromic substrings of t...read more

Ans.

Given a string, find the longest palindromic substring within it.

  • Iterate through the string and expand around each character to find palindromes

  • Keep track of the longest palindrome found so far

  • Return the longest palindromic substring

Add your answer

Q40. Check if Two Trees are Mirror

Given two arbitrary binary trees consisting of 'N' and 'M' number of nodes respectively, your task is to check whether the two trees are mirror images of each other or not.

Definit...read more

Ans.

Check if two binary trees are mirror images of each other.

  • Compare the left subtree of the first tree with the right subtree of the second tree.

  • Compare the right subtree of the first tree with the left subtree of the second tree.

  • Check if the roots of both trees are the same.

Add your answer

Q41. Rat in a Maze Problem Statement

You need to determine all possible paths for a rat starting at position (0, 0) in a square maze to reach its destination at (N-1, N-1). The maze is represented as an N*N matrix w...read more

Ans.

Find all possible paths for a rat in a maze from source to destination.

  • Use backtracking to explore all possible paths in the maze.

  • Keep track of visited cells to avoid revisiting them.

  • Explore all possible directions ('U', 'D', 'L', 'R') from each cell.

  • Return the list of valid paths sorted in alphabetical order.

Add your answer

Q42. Implement a Stack using Queues

Create a Stack data structure designed specifically to store integer data using two queues.

Explanation:

You need to implement a stack using two internal queues. You can utilize a...read more

Ans.

Implement a Stack using Queues to store integer data with push, pop, top, size, and isEmpty functions.

  • Use two queues to simulate a stack, with one queue acting as the main stack and the other for temporary storage.

  • For push operation, enqueue the new element to the temporary queue, then dequeue all elements from the main queue to the temporary queue, and finally swap the queues.

  • For pop operation, dequeue the top element from the main queue.

  • For top operation, return the front e...read more

Add your answer

Q43. Rain Water Trapping Problem Statement

Given an array/list ARR of size N, representing an elevation map where each element ARR[i] denotes the elevation of the i-th bar. Your task is to calculate and print the to...read more

Ans.

Calculate the total amount of rainwater that can be trapped between given elevations in an array.

  • Use two-pointer approach to keep track of left and right boundaries.

  • Calculate the trapped water by finding the minimum of maximum heights on left and right sides for each bar.

  • Sum up the trapped water for all bars to get the total amount of rainwater trapped.

Add your answer

Q44. Count Diagonal Paths

You are given a binary tree. Your task is to return the count of the diagonal paths to the leaf of the given binary tree such that all the values of the nodes on the diagonal are equal.

Inp...read more

Ans.

Count the number of diagonal paths in a binary tree where all nodes on the diagonal have equal values.

  • Traverse the binary tree in a diagonal manner and keep track of nodes with equal values.

  • Use recursion to explore all possible diagonal paths in the tree.

  • Count the number of paths where all nodes on the diagonal have the same value.

Add your answer
Q45. The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence such that all elements of the subsequence are sorted in increasing order.
Ans.

The Longest Increasing Subsequence (LIS) problem is to find the length of the longest subsequence of a given sequence with increasing order.

  • Use dynamic programming to solve the LIS problem efficiently.

  • Maintain an array to store the length of the LIS ending at each element.

  • Iterate through the array and update the LIS length based on previous elements.

  • Example: For input [10, 22, 9, 33, 21, 50, 41, 60, 80], the LIS is [10, 22, 33, 50, 60, 80] with length 6.

Add your answer
Q46. How do you perform a spiral order traversal of a binary tree? Please provide an explanation or code to print the binary tree in spiral order.
Ans.

Spiral order traversal of a binary tree involves printing nodes level by level alternating between left to right and right to left.

  • Start by pushing the root node into a queue.

  • While the queue is not empty, pop a node, print its value, and push its children into the queue.

  • For each level, alternate between printing nodes from left to right and right to left.

  • Repeat until all nodes are printed in spiral order.

Add your answer
Q47. You have two wires of different lengths that are both capable of burning for exactly one hour when ignited at both ends. How can you measure a time interval of 45 minutes using these two wires?
Ans.

Use one wire to measure 30 minutes, then ignite the other wire at one end to measure the remaining 15 minutes.

  • Ignite one wire at both ends and the other wire at one end simultaneously

  • After 30 minutes, the first wire will burn out completely

  • At this point, ignite the other end of the second wire

  • The second wire will burn for another 15 minutes before burning out completely

Add your answer
Q48. What is the difference between a structure and a union, and what are the pros and cons of both?
Ans.

Structure and union are both used to group different data types, but structure allocates memory for each member separately while union shares the same memory space for all members.

  • Structure allocates memory for each member separately, while union shares the same memory space for all members.

  • Structures are used when each member needs its own memory space and unions are used when only one member is accessed at a time.

  • Structures are typically larger in size compared to unions be...read more

Add your answer
Q49. What is the difference between a structure and a union, and what are the pros and cons of each?
Ans.

Structure and union are both used to group different data types, but structure allocates memory for each member separately while union shares the same memory location for all members.

  • Structure allocates memory for each member separately, while union shares the same memory location for all members.

  • Structures are used when each member needs its own memory space, while unions are used when only one member is accessed at a time.

  • Structures are typically larger in size compared to ...read more

Add your answer

Q50. Consider we have large amount of physical memory.Do we still need virtual memory? What is the use of paging in that situation

Ans.

Virtual memory is still needed even with large physical memory. Paging helps manage memory efficiently.

  • Virtual memory allows for larger programs to run than physical memory can handle

  • Paging helps manage memory efficiently by swapping out unused pages to disk

  • Virtual memory also allows for memory protection and sharing between processes

  • Examples of programs that require virtual memory include video editing software and large databases

Add your answer

Q51. You are given a string and a number.Count the no of ‘-’ characters in the string and return 1 if the count is equal to the number given or else return 0

Ans.

Count the number of '-' characters in a string and return 1 if it matches the given number, else return 0.

  • Use a loop to iterate through each character in the string and count the number of '-' characters.

  • Compare the count with the given number and return 1 if they match, else return 0.

  • Handle edge cases such as empty string or negative number input.

Add your answer
Q52. What is meant by multitasking and multithreading in operating systems?
Ans.

Multitasking refers to the ability of an operating system to run multiple tasks concurrently, while multithreading involves executing multiple threads within a single process.

  • Multitasking allows multiple processes to run simultaneously on a single processor, switching between them quickly.

  • Multithreading enables a single process to execute multiple threads concurrently, sharing resources like memory and CPU.

  • Multitasking improves system efficiency by utilizing idle CPU time, wh...read more

Add your answer

Q53. Differences between Mutex and Semaphore. Why do we need Mutex if we have Semaphores

Ans.

Mutex and Semaphore are synchronization primitives used in multi-threaded environments.

  • Mutex is used to provide mutual exclusion to a shared resource, allowing only one thread to access it at a time.

  • Semaphore is used to control access to a shared resource, allowing multiple threads to access it at a time.

  • Mutex is binary, meaning it has only two states - locked and unlocked, while Semaphore can have multiple states.

  • Mutex is typically faster and simpler to use than Semaphore.

  • We...read more

Add your answer
Q54. What is the difference between Early Binding and Late Binding in C++?
Ans.

Early binding is resolved at compile time while late binding is resolved at runtime in C++.

  • Early binding is also known as static binding, where the function call is resolved at compile time based on the type of the object.

  • Late binding is also known as dynamic binding, where the function call is resolved at runtime based on the actual type of the object.

  • Early binding is faster as the function call is directly linked to the function address during compilation.

  • Late binding allow...read more

Add your answer
Q55. What is the Diamond Problem in C++ and how can it be resolved?
Ans.

Diamond Problem is a multiple inheritance issue in C++ where a class inherits from two classes that have a common base class.

  • Diamond Problem occurs when a class inherits from two classes that have a common base class, leading to ambiguity in accessing members.

  • It can be resolved in C++ using virtual inheritance, where the common base class is inherited virtually to avoid duplicate copies of base class members.

  • Example: class A is inherited by classes B and C, and class D inheri...read more

Add your answer
Q56. Implement the Depth First Search (DFS) algorithm for a graph.
Ans.

DFS is a graph traversal algorithm that explores as far as possible along each branch before backtracking.

  • Start at a node and explore as far as possible along each branch before backtracking

  • Use a stack to keep track of nodes to visit

  • Mark visited nodes to avoid revisiting them

  • Recursive implementation is common

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

Mutex is used for exclusive access to a resource by only one thread at a time, while semaphore can allow multiple threads to access a resource simultaneously.

  • Mutex is binary semaphore with ownership, used for mutual exclusion.

  • Mutex is typically used to protect critical sections of code.

  • Semaphore is a signaling mechanism, used for synchronization between multiple threads.

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

  • Example: Mutex is...read more

Add your answer

Q58. Which is the best sorting algorithm ( considering all the aspects of time as well as space) ?

Ans.

It depends on the specific use case and input size.

  • For small input sizes, simple algorithms like insertion sort or selection sort may be sufficient.

  • For larger input sizes, more complex algorithms like merge sort or quicksort may be more efficient.

  • For nearly sorted input, insertion sort may be the fastest.

  • For input with many duplicates, counting sort or radix sort may be the best choice.

  • For input with a known range, bucket sort may be the most efficient.

  • Overall, there is no on...read more

Add your answer

Q59. Explain the concept of virtual addressing and the allocation of virtual addresses during the execution of program

Ans.

Virtual addressing is a memory management technique that allows a process to use a range of memory addresses independent of physical memory.

  • Virtual addresses are mapped to physical addresses by the memory management unit (MMU)

  • Virtual addresses are allocated to a process during its execution

  • Virtual addressing allows for efficient use of physical memory by allowing multiple processes to share the same physical memory

  • Examples of virtual addressing include paging and segmentation

Add your answer

Q60. Can constant and volatile both be used at same time?

Ans.

Yes, constant and volatile can be used together.

  • Constant variables are read-only and cannot be modified.

  • Volatile variables are used to indicate that the value may change unexpectedly.

  • Using both together can be useful in multi-threaded environments.

  • For example, a constant pointer to a volatile variable can be used to ensure thread safety.

Add your answer

Q61. Write a program to find the duplicate in the array(only one duplicate is present in the array)?

Ans.

Program to find the only duplicate in an array

  • Create a hash set to store elements as they are encountered

  • If an element is already in the hash set, it is a duplicate

  • Return the duplicate element

Add your answer

Q62. Write the functions to create a stack and to delete a node from the stack

Ans.

Functions to create and delete nodes in a stack

  • To create a stack, initialize a top pointer to null

  • To push a node, create a new node and set its next to the current top, then set top to the new node

  • To pop a node, set top to its next and return the popped node

  • To delete the stack, pop all nodes until top is null

Add your answer

Q63. What are the basic role of JAVA in the development of software?

Ans.

JAVA is a versatile programming language used for developing various software applications.

  • JAVA is platform-independent and can run on any operating system

  • It is object-oriented and supports multithreading

  • JAVA is widely used for developing web applications, mobile applications, and enterprise software

  • It provides a vast library of pre-built classes and APIs for developers to use

  • JAVA is also used for developing games, scientific applications, and financial applications

Add your answer

Q64. How do you find the middle of the linked list?

Ans.

To find the middle of a linked list, use two pointers - one moving at twice the speed of the other.

  • Initialize two pointers - slow and fast

  • Move the slow pointer one step at a time and the fast pointer two steps at a time

  • When the fast pointer reaches the end of the list, the slow pointer will be at the middle

Add your answer
Q65. How does C++ support polymorphism?
Ans.

C++ supports polymorphism through virtual functions and inheritance.

  • C++ supports polymorphism through virtual functions and inheritance

  • Virtual functions allow a function to be overridden in a derived class

  • Base class pointers can point to derived class objects, allowing for dynamic binding

  • Example: class Animal { virtual void speak() { cout << 'Animal speaks'; } }; class Dog : public Animal { void speak() { cout << 'Dog barks'; } };

  • Example: Animal* a = new Dog(); a->speak(); //...read more

Add your answer

Q66. Time complexity of building a heap using linked list and arrays

Ans.

Time complexity of building a heap using linked list and arrays

  • Building a heap using linked list takes O(nlogn) time complexity

  • Building a heap using arrays takes O(n) time complexity

  • Linked list implementation is slower than array implementation

Add your answer

Q67. What is deadlock? how to prevent deadlock?

Ans.

Deadlock is a situation where two or more processes are unable to proceed because they are waiting for each other to release resources.

  • Prevent deadlock by using a proper resource allocation strategy

  • Avoid holding onto resources for too long

  • Use timeouts to release resources if they are not being used

  • Implement a deadlock detection and recovery mechanism

  • Avoid circular wait by imposing a total ordering of all resource types

Add your answer

Q68. Different properties of OOPs ,examples of each, with application of each?

Ans.

OOPs properties and examples with applications

  • Encapsulation: bundling of data and methods within a class. Example: Java class. Application: data hiding and security.

  • Inheritance: creating a new class from an existing class. Example: subclass. Application: code reusability and extensibility.

  • Polymorphism: ability of an object to take on many forms. Example: method overloading. Application: flexibility and modularity.

  • Abstraction: hiding implementation details and showing only nec...read more

Add your answer
Q69. What are friend functions in C++?
Ans.

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 for implementing operators that are not part of the class.

  • Example: friend int add(const MyClass& obj1, ...read more

Add your answer
Q70. What is thrashing in operating systems?
Ans.

Thrashing in operating systems occurs when the system is spending more time swapping data between memory and disk than actually executing tasks.

  • Occurs when the system is constantly swapping data between memory and disk

  • Causes a decrease in system performance as it spends more time on swapping than executing tasks

  • Usually happens when the system does not have enough physical memory to handle the workload efficiently

Add your answer

Q71. Can static variable be defined in the header file?

Ans.

Yes, static variables can be defined in header files.

  • Static variables defined in header files have global scope within the file.

  • They can be accessed by any function within the file.

  • However, if the header file is included in multiple source files, each file will have its own copy of the static variable.

  • This can lead to unexpected behavior if the variable is modified in one file and then accessed in another.

  • It is generally recommended to define static variables in source files ...read more

Add your answer

Q72. Write the code for producer-consumer problem using mutex

Ans.

Code for producer-consumer problem using mutex

  • Create a shared buffer with a fixed size

  • Create a mutex to control access to the buffer

  • Create a semaphore to keep track of the number of items in the buffer

  • Create a producer thread that adds items to the buffer

  • Create a consumer thread that removes items from the buffer

  • Use mutex to lock the buffer while adding or removing items

  • Use semaphore to signal when the buffer is full or empty

Add your answer

Q73. Implementation and the use of Bi-direction Linked-list?

Ans.

Bi-directional linked list allows traversal in both directions, making it useful for certain algorithms.

  • Each node in the list has a reference to both the previous and next nodes.

  • Insertion and deletion operations are more complex than in a singly linked list.

  • Examples of use include implementing a browser's back and forward buttons or a text editor's undo and redo functionality.

Add your answer
Q74. What is Android?
Ans.

Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen devices.

  • Developed by Google

  • Based on Linux kernel

  • Designed for touchscreen devices

Add your answer

Q75. Check if a string is palindrome or not ?

Ans.

Check if a string is palindrome or not

  • Reverse the string and compare with original

  • Compare first and last characters and move towards center

  • Use recursion to check if first and last characters are equal

Add your answer

Q76. List all the permutations of the array?

Ans.

Permutations of an array

  • Permutations are all possible arrangements of elements in an array

  • Number of permutations for an array of length n is n!

  • Use recursion to generate all permutations

  • Swap elements to generate different permutations

Add your answer

Q77. When are double pointers used?

Ans.

Double pointers are used to store the address of a pointer variable.

  • Double pointers are useful in dynamic memory allocation.

  • They are used to modify the value of a pointer passed to a function.

  • They can be used to create linked lists and trees.

  • Example: int **ptr; //declares a double pointer to an integer

Add your answer

Q78. Difference between DFS and BFS?

Ans.

DFS and BFS are two popular graph traversal algorithms used in computer science.

  • DFS stands for Depth First Search and explores as far as possible along each branch before backtracking.

  • BFS stands for Breadth First Search and explores all the vertices at the present depth before moving on to the next level.

  • DFS uses a stack data structure to keep track of visited nodes while BFS uses a queue.

  • DFS is useful for finding paths between two nodes while BFS is useful for finding the sh...read more

Add your answer

Q79. sum of elements close to target

Ans.

Calculate the sum of elements in an array that are closest to a given target value.

  • Iterate through the array and calculate the absolute difference between each element and the target value.

  • Keep track of the element with the smallest difference and update the sum accordingly.

  • Return the sum of elements closest to the target value.

Add your answer

Q80. Insert a node in a N - array tree

Ans.

Insert a node in a N-array tree

  • Traverse the tree to find the parent node where the new node will be inserted

  • Add the new node as a child of the parent node

  • Update the parent node's child array to include the new node

Add your answer

Q81. second largest salary in DBMS

Ans.

The second largest salary in a database management system (DBMS) can be found by using the ORDER BY and LIMIT clauses in a SQL query.

  • Use the ORDER BY clause to sort the salaries in descending order

  • Use the LIMIT clause to retrieve the second row in the sorted result set

  • Example: SELECT salary FROM employees ORDER BY salary DESC LIMIT 1,1

Add your answer

More about working at Samsung

Top Rated Mega Company - 2024
Top Rated Consumer Electronics Company - 2024
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at Gauranga Papers

based on 10 interviews
5 Interview rounds
Coding Test Round
HR Round
Aptitude Test Round - 1
Aptitude Test Round - 2
Personal Interview1 Round
View more
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top Software Developer Interview Questions from Similar Companies

3.3
 • 46 Interview Questions
3.8
 • 16 Interview Questions
3.7
 • 15 Interview Questions
3.8
 • 11 Interview Questions
3.7
 • 10 Interview Questions
3.7
 • 10 Interview Questions
View all
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
75 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