Technical Trainee
100+ Technical Trainee Interview Questions and Answers

Asked in Oyo Rooms

Q. Minimum Cost to Destination
You are given an NxM matrix consisting of '0's and '1's. A '1' signifies that the cell is accessible, whereas a '0' indicates that the cell is blocked. Your task is to compute the mi...read more
Find the minimum cost to reach a destination in a matrix with specified rules.
Use Breadth First Search (BFS) algorithm to explore all possible paths from the starting point to the destination.
Keep track of the cost incurred at each cell and update it as you move through the matrix.
Return the minimum cost to reach the destination or -1 if it is unreachable.
Consider edge cases such as when the starting point is the destination or when the destination is blocked.

Asked in TO THE NEW

Q. Find Two Non-Repeating Elements Problem Statement
Given an array of integers ARR
with size N
, where exactly two elements appear only once and all others appear exactly twice, identify and return the two unique ...read more
Given an array where all elements appear twice except two, find and return the two unique elements.
Use XOR operation to find the XOR of all elements in the array, which will give the XOR of the two unique elements.
Find the rightmost set bit in the XOR result to divide the array into two groups based on that bit.
XOR each group separately to find the two unique elements.
Example: For input [2, 4, 6, 8, 4, 2], XOR result is 6^8=14. Rightmost set bit is at position 1. Group 1: [6,...read more
Technical Trainee Interview Questions and Answers for Freshers

Asked in Amazon

Q. Maximum of All Subarrays of Size k
Given an array of 'N' non-negative integers and an integer 'K', your task is to find the maximum elements for each subarray of size 'K'.
Input:
The first line contains an inte...read more
Find the maximum elements for each subarray of size 'K' in a given array of non-negative integers.
Iterate through the array and maintain a deque to store the indices of elements in decreasing order.
Pop elements from the deque if they are out of the current window of size 'K'.
The front of the deque will always have the index of the maximum element for the current window.

Asked in Amazon

Q. Sum Between Zeroes Problem Statement
Given a singly linked list containing a series of integers separated by the integer '0', modify the list by merging nodes between two '0's into a single node. This merged no...read more
Given a singly linked list with integers separated by '0', merge nodes between '0's into a single node with sum of included nodes.
Traverse the linked list and keep track of sum between zeroes
Merge nodes between zeroes by updating the sum in the merged node
Update the linked list by removing the nodes between zeroes
Handle edge cases like list starting and ending with '0'

Asked in Nagarro

Q. Nth Prime Number Problem Statement
Find the Nth prime number given a number N.
Explanation:
A prime number is greater than 1 and is not the product of two smaller natural numbers. A prime number has exactly two...read more
Find the Nth prime number given a number N.
A prime number is greater than 1 and is not the product of two smaller natural numbers
A prime number has exactly two distinct positive divisors: 1 and itself
Implement a function to find the Nth prime number based on the given input

Asked in Amazon

Q. Counting Derangements Problem
A derangement is a permutation of 'N' elements, where no element appears in its original position. For instance, a derangement of {0, 1, 2, 3} is {2, 3, 1, 0} because each element ...read more
Count the total number of derangements possible for a set of 'N' elements.
A derangement is a permutation where no element appears in its original position.
Use the formula for derangements: !n = n! * (1 - 1/1! + 1/2! - 1/3! + ... + (-1)^n/n!)
Return the answer modulo (10^9 + 7) to handle large results.
Technical Trainee Jobs




Asked in UBS

Q. Convert Min Heap to Max Heap Problem Statement
Given an array representation of a min-heap of size 'n', your task is to convert this array into a max-heap.
Input:
The first line of input contains an integer ‘T’...read more
Convert a given array representing a min-heap into a max-heap.
Iterate through the array and swap parent nodes with their children to convert min-heap to max-heap.
Maintain the heap property by comparing parent with its children and swapping if necessary.
Ensure the final array satisfies the max-heap property where parent nodes are greater than their children.

Asked in Nagarro

Q. Count Palindrome Words in a String
Given a string 'S' consisting of words, your task is to determine the number of palindrome words within 'S'. A word is considered a palindrome if it reads the same backward as...read more
Count the number of palindrome words in a given string.
Split the string into words using whitespace as delimiter.
Check each word if it is a palindrome by comparing it with its reverse.
Increment a counter for each palindrome word found.
Output the total count of palindrome words for each test case.
Share interview questions and help millions of jobseekers 🌟

Asked in MAQ Software

Q. Sort 0 1 2 Problem Statement
Given an integer array arr
of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.
Input:
The first line contains an integer 'T' representing the number of...read more
Sort an integer array containing only 0s, 1s, and 2s in-place using a single scan.
Iterate through the array and maintain three pointers for 0s, 1s, and 2s.
Swap elements based on the current element's value and the pointers.
Example: If current element is 0, swap with the 0s pointer and increment both pointers.

Asked in SAP

Q. Build Max Heap Problem Statement
Given an integer array with N elements, the task is to transform this array into a max binary heap structure.
Explanation:
A max-heap is a complete binary tree where each intern...read more
The task is to transform an integer array into a max binary heap structure.
Create a max heap from the given array by rearranging elements.
Check if each internal node has a value greater than or equal to its children.
Output '1' if the transformed array represents a max-heap, else output '0'.

Asked in Amdocs

Q. Swap Two Numbers Problem Statement
Given two integers a
and b
, your task is to swap these numbers and output the swapped values.
Input:
The first line contains a single integer 't', representing the number of t...read more
Swap two integers 'a' and 'b' and output the swapped values.
Create a temporary variable to store one of the integers before swapping
Assign the value of 'a' to 'b' and the temporary variable to 'a'
Output the swapped values as 'b' followed by 'a'

Asked in Hewlett Packard Enterprise

Q. Merge Sort Problem Statement
You are 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 algorit...read more
Implement Merge Sort algorithm to sort a sequence of numbers in non-descending order.
Divide the input array into two halves recursively until each array has only one element.
Merge the sorted halves to produce a completely sorted array.
Ensure the implementation handles the constraints specified in the problem statement.
Example: For input [3, 1, 4, 1, 5], the output should be [1, 1, 3, 4, 5].

Asked in Amazon

Q. Reverse Doubly Linked List Nodes in Groups
You are given a doubly linked list of integers along with a positive integer K
that represents the group size. Your task is to modify the linked list by reversing ever...read more
Reverse groups of K nodes in a doubly linked list.
Iterate through the linked list in groups of K nodes
Reverse each group of K nodes
Handle cases where the number of nodes is less than K
Update the pointers accordingly

Asked in Amazon

Q. Character Formation Check
Determine if the second string STR2
can be constructed using characters from the first string STR1
. Both strings may include any characters.
Input:
The first line contains an integer T...read more
Check if second string can be formed using characters from the first string.
Iterate through each character in STR2 and check if it exists in STR1.
Use a hashmap to store the frequency of characters in STR1 for efficient lookup.
Return 'YES' if all characters in STR2 are found in STR1, otherwise return 'NO'.

Asked in HashedIn by Deloitte

Q. 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
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 to find the start of the loop.
Adjust the pointers to remove the loop and return the modified linked list.

Asked in Amazon

Q. Trapping Rainwater Problem Statement
You are given an array ARR
of long type, which represents an elevation map where ARR[i]
denotes the elevation of the ith
bar. Calculate the total amount of rainwater that ca...read more
Calculate the total amount of rainwater that can be trapped within given elevation map.
Iterate through the array to find 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 elevation map.

Asked in Intuit

Q. Closest Distance Pair Problem Statement
Given an array containing 'N' points in a 2D plane, determine the minimum distance between the closest pair of points.
Note:
Distance between two points (x1, y1) and (x2,...read more
The task is to find the distance of the closest points among an array of N points in the plane.
Calculate the distance between each pair of points using the given formula
Keep track of the minimum distance found so far
Return the minimum distance

Asked in Nagarro

Q. Count Ways to Reach the N-th Stair Problem Statement
You are provided with a number of stairs, and initially, you are located at the 0th stair. You need to reach the Nth stair, and you can climb one or two step...read more
The problem involves determining the number of distinct ways to climb from the 0th to the Nth stair by climbing one or two steps at a time.
Use dynamic programming to solve this problem efficiently.
The number of ways to reach the Nth stair can be calculated by adding the number of ways to reach the (N-1)th stair and the (N-2)th stair.
Consider base cases where N=0 and N=1 separately.
Handle large values of N by using modulo arithmetic.
Example: For N=3, the number of distinct way...read more

Asked in Amazon

Q. Sorted Linked List to Balanced BST Problem Statement
Given a singly linked list where nodes contain values in increasing order, your task is to convert it into a Balanced Binary Search Tree (BST) using the same...read more
Convert a sorted linked list into a Balanced Binary Search Tree (BST) using the same data values.
Create a function to convert the linked list to a BST by recursively dividing the list into halves
Maintain a pointer to the middle element of the list as the root of the BST
Recursively set the left and right children of the root using the left and right halves of the list
Perform level order traversal to output the values of the BST nodes in the required format

Asked in Amazon

Q. Snake and Ladder Problem Statement
Given a 'Snake and Ladder' board with N rows and N columns, where positions are numbered from 1 to (N*N) starting from the bottom left, alternating direction each row, find th...read more
Find the minimum number of dice throws required to reach the last cell on a 'Snake and Ladder' board.
Create a graph representation of the board with snakes and ladders as edges.
Use Breadth First Search (BFS) to find the shortest path from the starting cell to the last cell.
Keep track of visited cells and the number of dice throws at each cell.
Handle cases where the last cell is unreachable by returning -1.
Consider the special cases where the last cell is reached through a lad...read more

Asked in Amazon

Q. 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
The task is to output the Spiral Order traversal of a binary tree given in level order.
Implement a function that returns the spiral order traversal as a list
Traverse the binary tree in a spiral order alternating between left to right and right to left
Use a queue to keep track of nodes at each level
Handle null nodes represented by -1 in the input

Asked in Daffodil Software

Q. Distribute N Candies Among K People
Explanation: Sanyam wishes to distribute 'N' candies among 'K' friends. The friends are arranged based on Sanyam's order of likeness. He initially distributes candies such th...read more
Distribute N candies among K people in Sanyam's order of likeness, incrementing distribution by K each round until all candies are distributed.
Distribute candies starting from 1st friend, incrementing by K each round
If remaining candies are fewer than what a friend is supposed to receive, stop distribution
Output the number of candies each friend ends up with at the end of distribution

Asked in Amazon

Q. 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
The task is to find all pairs of elements in an array that add up to a given target.
Iterate through the array and for each element, check if the target minus the element exists in a hash set.
If it exists, add the pair to the result. If not, add the element to the hash set.
Print the pairs found or (-1, -1) if no pair is found.

Asked in Nagarro

Q. Jumping Game Problem Statement
In this problem, you have ‘n’ carrots lined up and denoted by numbers 1 through ‘n’. There are ‘k’ rabbits, and each rabbit can jump to carrots that are multiples of its unique ju...read more
Calculate uneaten carrots after rabbits jump based on their unique factors.
Iterate through each rabbit's jumping factor and mark the carrots they land on as eaten
Calculate the remaining uneaten carrots by counting the ones not marked as eaten
Consider using a data structure like an array to keep track of eaten carrots efficiently

Asked in Samsung

Q. Reverse Linked List Problem Statement
Given a Singly Linked List of integers, your task is to reverse the Linked List by altering the links between the nodes.
Input:
The first line of input is an integer T, rep...read more
Reverse a singly linked list by altering the links between nodes.
Iterate through the linked list and reverse the links between nodes
Use three pointers to keep track of the current, previous, and next nodes
Update the links between nodes to reverse the list
Return the head of the reversed linked list

Asked in Amdocs

Q. Reverse Stack with Recursion
Reverse a given stack of integers using recursion. You must accomplish this without utilizing extra space beyond the internal stack space used by recursion. Additionally, you must r...read more
Reverse a given stack of integers using recursion without extra space or loop constructs.
Use recursion to pop all elements from the original stack and store them in function call stack.
Once the stack is empty, push the elements back in reverse order using recursion.
Ensure to handle base cases for empty stack or single element stack.
Example: If the input stack is [1, 2, 3], after reversal it should be [3, 2, 1].

Asked in Infosys

Q. String Compression Problem Statement
Ninja needs to perform basic string compression. For any character that repeats consecutively more than once, replace the repeated sequence with the character followed by th...read more
Implement a function to compress a string by replacing consecutive characters with the character followed by the count of repetitions.
Iterate through the input string and keep track of consecutive characters and their counts.
Replace consecutive characters with the character followed by the count of repetitions if count is greater than 1.
Return the compressed string for each test case.

Asked in Nagarro

Q. 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
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 at each bar by taking the minimum of the maximum heights on the left and right.
Sum up the trapped water at each bar to get the total trapped water for the entire array.

Asked in Nagarro

Q. Maximum Sum Path in a Binary Tree
Your task is to determine the maximum possible sum of a simple path between any two nodes (possibly the same) in a given binary tree of 'N' nodes with integer values.
Explanati...read more
Find the maximum sum of a simple path between any two nodes in a binary tree.
Use a recursive approach to traverse the binary tree and calculate the maximum sum path.
Keep track of the maximum sum path found so far while traversing the tree.
Consider negative values in the path sum calculation to handle cases where the path can start and end at different nodes.
Handle cases where the path can go through the root node or not.

Asked in TO THE NEW

Q. Word Occurrence Counting
Given a string 'S' of words, the goal is to determine the frequency of each word in the string. Consider a word as a sequence of one or more non-space characters. The string can have mu...read more
The goal is to determine the frequency of each word in a given string.
Split the input string into individual words
Create a dictionary to store word frequencies
Iterate through the words and update the frequency count in the dictionary
Print each unique word and its frequency
Interview Questions of Similar Designations
Interview Experiences of Popular Companies





Top Interview Questions for Technical Trainee Related Skills



Reviews
Interviews
Salaries
Users

