Nagarro
10+ Singapore Marriott Tang Plaza Hotel Interview Questions and Answers
Q1. Check If Binary Representation of a Number is Palindrome
Given an integer N
, determine if its binary representation is a palindrome.
Input:
The first line contains a single integer ‘T’ representing the number o...read more
Check if the binary representation of a number is a palindrome.
Convert the integer to binary representation.
Check if the binary representation is a palindrome by comparing it with its reverse.
Return true if it is a palindrome, false otherwise.
Q2. Sort 0 and 1 Problem Statement
Given an integer array ARR
of size N
containing only integers 0 and 1, implement a function to sort this array. The solution should scan the array only once without using any addi...read more
Sort an array of 0s and 1s in linear time without using additional arrays.
Use two pointers approach to swap 0s to the left and 1s to the right.
Maintain two pointers, one for 0s and one for 1s, and iterate through the array.
Swap elements at the two pointers based on the values encountered.
Continue until the two pointers meet in the middle of the array.
Q3. String Rotation Problem Statement
You are given a string named str
and an integer D
. Your task is to perform both left (anticlockwise) and right (clockwise) rotations on the given string by D
units, starting fr...read more
Implement left and right string rotations by D units on a given string.
Implement leftRotate() function to return string after left rotation by D units.
Implement rightRotate() function to return string after right rotation by D units.
Consider handling edge cases like empty string or D exceeding string length.
Example: For input 'coding', D=2, leftRotate() should return 'dingco' and rightRotate() should return 'ngcodi'.
Q4. Word Break Problem Statement
You are given a list of N
strings called A
. Your task is to determine whether you can form a given target string by combining one or more strings from A
.
The strings from A
can be u...read more
Given a list of strings, determine if a target string can be formed by combining one or more strings from the list.
Iterate through all possible combinations of strings from the list to check if they can form the target string.
Use recursion to try different combinations of strings.
Keep track of the current position in the target string and the strings used so far.
Return true if the target string can be formed, false otherwise.
Q5. Maximum Subarray Sum Problem Statement
Given an array arr
of length N
consisting of integers, find the sum of the subarray (including empty subarray) with the maximum sum among all subarrays.
Explanation:
A sub...read more
Find the sum of the subarray with the maximum sum among all subarrays in an array of integers.
Use Kadane's algorithm to find the maximum subarray sum efficiently.
Initialize two variables, one for current sum and one for maximum sum.
Iterate through the array and update the current sum and maximum sum accordingly.
Return the maximum sum as the result.
Q6. Height of Binary Tree
You are provided with the Inorder and Level Order traversals of a Binary Tree composed of integers. Your goal is to determine the height of this Binary Tree without actually constructing i...read more
Calculate the height of a Binary Tree given its Inorder and Level Order traversals without constructing it.
Use the properties of Inorder and Level Order traversals to determine the height of the Binary Tree.
The height of a Binary Tree is the number of edges on the longest path from the root to a leaf node.
Consider edge cases like a single node tree or empty tree when calculating the height.
Q7. 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
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 (arr[i], arr[j]) and (arr[j], arr[i]) separately.
Q8. Common Elements Problem Statement
Identify and output the common strings present in both given arrays of lowercase alphabets for each test case.
Input:
The first line contains an integer 'T' representing the nu...read more
The task is to find and output the common strings present in both given arrays of lowercase alphabets for each test case.
Iterate through the elements of the second array and check if they are present in the first array.
Use a hash set or map to efficiently check for common elements.
Return the common strings in the order they appear in the second array.
Q9. Median of Two Sorted Arrays
Given two sorted arrays A
and B
of sizes N
and M
, find the median of the merged array formed by combining arrays A
and B
. If the total number of elements, N + M
, is even, the median ...read more
Find the median of two sorted arrays by merging them and calculating the middle element(s).
Merge the two sorted arrays into one sorted array.
Calculate the median based on the total number of elements in the merged array.
If the total number of elements is even, take the mean of the two middle elements as the median.
Q10. Prime Numbers Identification
Given a positive integer N
, your task is to identify all prime numbers less than or equal to N
.
Explanation:
A prime number is a natural number greater than 1 that has no positive d...read more
Identify all prime numbers less than or equal to a given positive integer N.
Iterate from 2 to N and check if each number is prime
Use the Sieve of Eratosthenes algorithm for efficient prime number identification
Optimize by only checking up to the square root of N for divisors
Q11. DFS Traversal Problem Statement
Given an undirected and disconnected graph G(V, E)
, where V
is the number of vertices and E
is the number of edges, the connections between vertices are provided in the 'GRAPH' m...read more
DFS traversal to find connected components in an undirected and disconnected graph.
Use Depth First Search (DFS) algorithm to traverse the graph and find connected components.
Maintain a visited array to keep track of visited vertices.
For each unvisited vertex, perform DFS to explore all connected vertices and form a connected component.
More about working at Nagarro
Interview Process at Singapore Marriott Tang Plaza Hotel
Top Software Developer Intern Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month