Add office photos
Engaged Employer

Nagarro

4.0
based on 4.1k Reviews
Video summary
Filter interviews by

100+ Intelli Search Interview Questions and Answers

Updated 20 Jan 2025
Popular Designations

Q1. Crazy Numbers Pattern Challenge

Ninja enjoys arranging numbers in a sequence. He plans to arrange them in 'N' rows such that:

  • The first row contains 1 number.
  • The second row contains 2 numbers.
  • The third row c...read more
Ans.

Arrange numbers in a sequence in 'N' rows with increasing order and repeating after 9.

  • Iterate through each test case and for each row, print numbers in increasing order with a loop.

  • Keep track of the current number to print and reset to 1 after reaching 9.

  • Handle formatting to align numbers correctly in each row.

  • Ensure to print the correct number of rows based on the input 'N'.

View 1 answer

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

Ans.

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 as output.

View 1 answer

Q3. Ninja and the New Year Guests Problem

Ninja has organized a new year party and wants to verify if the guests are programmers by challenging them with a coding task. As an invited programmer, you're tasked to so...read more

Ans.

Compute the number of valid permutations of integers from 0 to N-1 such that at least K positions satisfy ARR[I] = I.

  • Use dynamic programming to solve the problem efficiently.

  • Consider the cases where K is equal to N or N-1 separately.

  • Modulo the result by 10^9 + 7 to avoid overflow issues.

Add your answer

Q4. Fibonacci Membership Check

Given an integer N, determine if it is a member of the Fibonacci series. Return true if the number is a member of the Fibonacci series, otherwise return false.

Fibonacci Series Defini...read more

Ans.

Check if a given integer is a member of the Fibonacci series.

  • Implement a function to check if the given number is a perfect square.

  • Check if 5*N^2 + 4 or 5*N^2 - 4 is a perfect square to determine Fibonacci membership.

  • Return true if the number is a perfect square of 5*N^2 + 4 or 5*N^2 - 4, otherwise false.

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

Q5. Maximum Meetings Problem Statement

Given the schedule of N meetings with their start time Start[i] and end time End[i], you need to determine which meetings can be organized in a single meeting room such that t...read more

Ans.

Given N meetings with start and end times, find the maximum number of meetings that can be organized in a single room without overlap.

  • Sort the meetings based on their end times.

  • Iterate through the sorted meetings and select the next meeting that does not overlap with the current meeting.

  • Keep track of the selected meetings and return their indices in the order they are organized.

Add your answer

Q6. Count Pairs with Difference K

Given an array of integers and an integer K, determine and print the count of all pairs in the array that have an absolute difference of K.

Input:
The first line of the input conta...read more
Ans.

Count pairs in an array with a specific absolute difference.

  • Iterate through the array and for each element, check if the element + K or element - K exists in the array.

  • Use a hash set to store elements for constant time lookups.

  • Keep track of the count of valid pairs found.

Add your answer
Are these interview questions helpful?

Q7. Next Permutation Problem Statement

You are given a permutation of 'N' integers. A sequence of 'N' integers is considered a permutation if it includes all integers from 1 to 'N' exactly once. Your task is to rea...read more

Ans.

Given a permutation of 'N' integers, rearrange the numbers to form the lexicographically next greater permutation.

  • Iterate from right to left to find the first element that is smaller than the element to its right.

  • Swap this element with the smallest element to its right that is greater than it.

  • Reverse the elements to the right of the swapped element to get the lexicographically next greater permutation.

  • If no such element is found in step 1, then the permutation is already the ...read more

Add your answer

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

Ans.

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 in linear time complexity.

  • Initialize two variables: maxEndingHere and maxSoFar to keep track of the current subarray sum and the maximum subarray sum found so far.

  • Iterate through the array and update the variables accordingly.

  • Return the maxSoFar as the result.

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

Q9. Coin Game Winner Problem Statement

Two players 'X' and 'Y' are participating in a coin game. Starting with 'N' coins, players alternate turns, with 'X' starting first. On each turn, a player has three choices: ...read more

Ans.

Determine the winner of a coin game where players take turns picking coins optimally.

  • Players take turns picking 'A', 'B', or 1 coin each turn

  • The player unable to make a move loses

  • Implement a function to determine the winner based on the given inputs

Add your answer

Q10. Problem: Sort an Array of 0s, 1s, and 2s

Given an array/list ARR consisting of integers where each element is either 0, 1, or 2, your task is to sort this array in increasing order.

Input:

The input starts with...read more
Ans.

Sort an array of 0s, 1s, and 2s in increasing order.

  • Use a three-pointer approach to partition the array into sections of 0s, 1s, and 2s.

  • Iterate through the array and swap elements based on their values and the pointers.

  • After sorting, the array will have 0s on the left, 1s in the middle, and 2s on the right.

Add your answer

Q11. Ways To Make Coin Change

Given an infinite supply of coins of varying denominations, determine the total number of ways to make change for a specified value using these coins. If it's not possible to make the c...read more

Ans.

The task is to find the total number of ways to make change for a specified value using given denominations.

  • Use dynamic programming to solve this problem efficiently.

  • Create a 1D array to store the number of ways to make change for each value from 0 to the target value.

  • Iterate through the denominations and update the array based on the current denomination.

  • The final answer will be the value at the target index of the array.

Add your answer

Q12. Complete String Problem Statement

Given an array of strings A of size N, determine the longest complete string. A string is deemed complete if every prefix of the string also appears in the array. If multiple s...read more

Ans.

Given an array of strings, find the longest complete string where every prefix of the string also appears in the array.

  • Iterate through each string in the array and check if all its prefixes exist in the array.

  • Keep track of the longest complete string found so far, and return the lexicographically smallest one if multiple exist.

  • If no complete string is found, return 'None'.

Add your answer

Q13. K - Sum Path In A Binary Tree

Given a binary tree where each node contains an integer value, and a value 'K', your task is to find all the paths in the binary tree such that the sum of the node values in each p...read more

Ans.

Find all paths in a binary tree with nodes summing up to a given value K.

  • Traverse the binary tree and keep track of the current path and its sum.

  • At each node, check if the sum equals K and store the path if true.

  • Recursively explore left and right subtrees while updating the path and sum.

  • Return the list of paths that sum up to K in the binary tree.

Add your answer

Q14. Convert Sentence Problem Statement

Convert a given string 'S' into its equivalent representation based on a mobile numeric keypad sequence. Using the keypad layout shown in the reference, output the sequence of...read more

Ans.

Convert a given string into its equivalent representation based on a mobile numeric keypad sequence.

  • Iterate through each character in the input string and map it to its corresponding numeric keypad sequence.

  • Use a dictionary to store the mapping of characters to numeric sequences.

  • Handle lowercase characters only and ignore special characters, capital letters, and spaces.

Add your answer

Q15. Subsequences of String Problem Statement

You are provided with a string 'STR' that consists of lowercase English letters ranging from 'a' to 'z'. Your task is to determine all non-empty possible subsequences of...read more

Ans.

Generate all possible subsequences of a given string.

  • Use recursion to generate all possible subsequences by including or excluding each character in the string.

  • Maintain a current index to keep track of the characters being considered.

  • Append the current character to each subsequence generated so far.

  • Recursively call the function with the next index to include the next character in subsequences.

Add your answer

Q16. Find the Longest Palindromic Substring

Given a string ‘S’ composed of lowercase English letters, your task is to identify the longest palindromic substring within ‘S’.

If there are multiple longest palindromic ...read more

Ans.

Find the longest palindromic substring in a given string, returning the rightmost one if multiple exist.

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

  • Keep track of the longest palindrome found and its starting index

  • Return the substring starting from the index of the longest palindrome found

Add your answer

Q17. K Subsets with Equal Sum Problem Statement

Determine whether it is possible to partition an array ARR into K subsets, each having an equal sum.

Example:

Input:
ARR = [3, 5, 2, 4, 4], K = 2
Output:
true
Explanat...read more
Ans.

Yes, it is possible to partition an array into K subsets with equal sum.

  • Check if the total sum of the array is divisible by K.

  • Use backtracking to try all possible combinations of subsets.

  • Keep track of visited elements to avoid repetition.

  • Example: ARR = [3, 5, 2, 4, 4], K = 2. Possible subsets: [4, 5] and [2, 3, 4].

Add your answer

Q18. Find Duplicates in an Array

Given an array ARR of size 'N', where each integer is in the range from 0 to N - 1, identify all elements that appear more than once.

Return the duplicate elements in any order. If n...read more

Ans.

Find duplicates in an array of integers within a specified range.

  • Iterate through the array and keep track of the count of each element using a hashmap.

  • Return elements with count greater than 1 as duplicates.

  • Time complexity can be optimized to O(N) using a HashSet to store seen elements.

Add your answer

Q19. 0/1 Knapsack Problem Statement

A thief is planning to rob a store and can carry a maximum weight of 'W' in his knapsack. The store contains 'N' items where the ith item has a weight of 'wi' and a value of 'vi'....read more

Ans.

Yes, the 0/1 Knapsack problem can be solved using dynamic programming with a space complexity of not more than O(W).

  • Use a 1D array to store the maximum value that can be stolen for each weight from 0 to W.

  • Iterate through the items and update the array based on whether including the current item would increase the total value.

  • The final element of the array will contain the maximum value that can be stolen within the weight limit.

Add your answer

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

Ans.

The problem involves finding the number of distinct ways to climb to the Nth stair by climbing one or two steps at a time.

  • Use dynamic programming to solve the problem efficiently.

  • The number of ways to reach the Nth stair is the sum of the number of ways to reach the (N-1)th stair and the (N-2)th stair.

  • Handle base cases for N=0 and N=1 separately.

  • Implement modulo operation to avoid overflow while calculating the result.

  • Consider using memoization to optimize the solution by sto...read more

Add your answer

Q21. Equilibrium Index Problem Statement

Given an array Arr consisting of N integers, your task is to find the equilibrium index of the array.

An index is considered as an equilibrium index if the sum of elements of...read more

Ans.

Find the equilibrium index of an array where sum of elements on left equals sum on right.

  • Iterate through array to calculate prefix and suffix sums

  • Compare prefix and suffix sums to find equilibrium index

  • Return -1 if no equilibrium index is found

Add your answer

Q22. Longest Increasing Subsequence Problem Statement

Given an array of integers with 'N' elements, determine the length of the longest subsequence where each element is greater than the previous element. This subse...read more

Ans.

Find the length of the longest strictly increasing subsequence in an array of integers.

  • Use dynamic programming to solve this problem efficiently.

  • Initialize an array to store the length of the longest increasing subsequence ending at each index.

  • Iterate through the array and update the length of the longest increasing subsequence for each element.

  • Return the maximum value in the array as the result.

Add your answer

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

Add your answer

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

Given an array of integers and a target, find all pairs of elements that add up to the 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.

  • Handle cases where the same element is used twice to form a pair.

  • Return (-1, -1) if no pair is found.

Add your answer

Q25. Letter Combinations of a Phone Number Problem Statement

You are given a string S containing digits from 2 to 9 inclusive. Your task is to find all possible letter combinations that the number could represent, b...read more

Ans.

Given a string of digits, find all possible letter combinations based on phone keypad mapping.

  • Use a recursive approach to generate all possible combinations of letters for each digit in the input string.

  • Create a mapping of digits to corresponding letters on a phone keypad.

  • Iterate through the input string and generate combinations by combining letters for each digit.

  • Return the list of all possible letter combinations as an array of strings.

Add your answer

Q26. Closest Perfect Square Problem Statement

Given a positive integer 'N', determine the perfect square number closest to 'N' and the number of steps required to reach that perfect square.

Example:

Input:
N = 21
Ou...read more
Ans.

Given a positive integer 'N', find the closest perfect square number and the steps required to reach it.

  • Find the square root of N and round it to the nearest integer to get the closest perfect square.

  • Calculate the difference between the closest perfect square and N to get the number of steps required.

  • Return the closest perfect square and the number of steps as output.

Add your answer

Q27. Missing Number Statement

Given an array ARR of integers with size N, where all elements appear an even number of times except for one element which appears an odd number of times, identify the element that appe...read more

Ans.

Identify the element that appears an odd number of times in an array of integers where all other elements appear an even number of times.

  • Iterate through the array and use XOR operation to find the element that appears an odd number of times.

  • XOR of a number with itself is 0, so XOR of all elements will give the odd occurring element.

  • Return the result after XORing all elements in the array.

Add your answer

Q28. 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 given strings containing only parentheses are balanced or not.

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

  • If a closing parenthesis is encountered, check if the stack is empty or if the top of the stack matches the corresponding opening parenthesis.

  • If all parentheses are balanced, the stack should be empty at the end.

  • Return 'Balanced' if the stack is empty, otherwise return 'Not Balanced'.

Add your answer

Q29. Duplicate Subtrees Problem Statement

Given a binary tree, return the root values of all duplicate subtrees. Two subtrees are considered duplicate if they have the same structure with identical node values. For ...read more

Ans.

Find root values of duplicate subtrees in a binary tree.

  • Traverse the tree in a bottom-up manner to identify duplicate subtrees.

  • Use a hashmap to store the subtree structure and count occurrences.

  • Return the root values of duplicate subtrees found.

  • Handle null nodes by using -1 in the input sequence.

Add your answer

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

Ans.

Check if one string can be transformed into another by cyclically rotating it to the right.

  • Iterate through all possible rotations of string P and check if any of them match string Q.

  • Use string concatenation and substring operations to simulate the rotation.

  • Optimize the solution to O(N) time complexity by checking if string Q is a substring of P concatenated with itself.

Add your answer

Q31. 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
Ans.

The problem requires identifying and outputting common strings present in two 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.

Add your answer

Q32. Merge k Sorted Linked Lists

You are provided with 'K' sorted linked lists, each sorted in increasing order. Your task is to merge all these lists into one single sorted linked list and return the head of the re...read more

Ans.

Merge k sorted linked lists into one single sorted linked list.

  • Create a min-heap to store the heads of all k linked lists.

  • Pop the smallest element from the heap and add it to the result list.

  • If the popped element has a next element, push it back to the heap.

  • Repeat until the heap is empty and return the merged sorted list.

Add your answer

Q33. 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 problem involves determining 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 keep track of overlapping schedules.

  • Increment platform count when a train arrives and decrement when it departs.

  • Return the maximum platform count needed.

Add your answer

Q34. Pair Sum Problem Statement

You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to find and return a list of all pairs of elements where each sum of a pair equals 'S'.

Note:

Each pa...read more

Ans.

Find pairs of elements in an array that sum up to a given value, sorted in a specific order.

  • Iterate through the array and use a hashmap to store the difference between the target sum and each element.

  • Check if the current element's complement exists in the hashmap, if so, add the pair to the result list.

  • Sort the pairs based on the criteria mentioned in the question.

  • Return the list of pairs as the final output.

Add your answer

Q35. 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 the direction of traversal.

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

  • Append nodes to the result list based on the traversal direction.

  • Handle null nodes appropriately to maintain the spiral order.

  • Example: Input: 1 2 3 -1 -1 4 5, Output: 1 3 2 4 5

Add your answer

Q36. Palindrome String Validation

Determine if a given string 'S' is a palindrome, considering only alphanumeric characters and ignoring spaces and symbols.

Note:
The string 'S' should be evaluated in a case-insensi...read more
Ans.

Check if a given string is a palindrome after removing special characters, spaces, and converting to lowercase.

  • Remove special characters and spaces from the input string

  • Convert the string to lowercase

  • Check if the modified string is a palindrome by comparing characters from start and end

Add your answer

Q37. 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 given binary tree is a Binary Search Tree (BST) or not.

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

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

  • Recursively check if both the left and right subtrees are also binary search trees.

  • Use level order traversal to construct the binary tree from input data.

Add your answer

Q38. Nearest Numbers with the Same Number of Set Bits

Given a positive integer n, your task is to determine the next smallest integer and the previous largest integer that have the same number of '1' bits in their b...read more

Ans.

Given a positive integer, find the next smallest and previous largest integers with the same number of set bits in their binary representation.

  • Count the number of set bits in the binary representation of the given integer 'n'.

  • Find the next smallest integer by iterating from 'n+1' onwards and checking for the same number of set bits.

  • Find the previous largest integer by iterating from 'n-1' downwards and checking for the same number of set bits.

Add your answer

Q39. Code Optimization Problem

Ninja encountered an issue with a practice problem where certain test cases could not be passed due to high time complexity. You are provided with a snippet of pseudocode, and your tas...read more

Ans.

Optimize pseudocode to compute XOR operations in a given range and return sum modulo 1000000007.

  • Use bitwise XOR properties to optimize the computation.

  • Avoid unnecessary nested loops by simplifying the logic.

  • Consider using modular arithmetic to handle large numbers efficiently.

Add your answer

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

Ans.

Count the number of islands in a 2D matrix of 1s and 0s.

  • Use depth-first search (DFS) to traverse the matrix and identify connected groups of 1s.

  • Maintain a visited array to keep track of visited cells to avoid redundant traversal.

  • Increment the island count each time a new island is encountered.

  • Consider all eight possible directions for connectivity while traversing the matrix.

  • Handle edge cases such as out of bounds indices and already visited cells.

Add your answer

Q41. Zigzag Binary Tree Traversal Problem

Given a binary tree, compute the zigzag level order traversal of the node values in the tree. The zigzag traversal requires traversing levels from left to right, then right ...read more

Ans.

Zigzag level order traversal of a binary tree is computed by alternating between left to right and right to left traversal at each level.

  • Use a queue to perform level order traversal of the binary tree.

  • Maintain a flag to switch between left to right and right to left traversal at each level.

  • Store the node values in a list while traversing and alternate the order based on the flag.

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

Add your answer

Q42. Reverse Alternate K Nodes Problem Statement

You are given a singly linked list of integers along with a positive integer 'K'. The task is to modify the linked list by reversing every alternate 'K' nodes of the ...read more

Ans.

Reverse every alternate K nodes in a singly linked list

  • Traverse the linked list and reverse every alternate K nodes

  • Handle cases where the number of nodes left is less than K

  • Ensure to properly link the reversed nodes back to the original list

Add your answer

Q43. Count Derangements Problem Statement

You are tasked with finding the total number of derangements for a given set of elements. Specifically, for an integer N, determine how many ways there are to permute a set ...read more

Ans.

Count the total number of derangements for a given set of 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!).

  • Calculate the derangements modulo 10^9 + 7 to handle large numbers efficiently.

Add your answer

Q44. Sort a "K" Sorted Doubly Linked List Problem Statement

You are given a doubly linked list with 'N' nodes, where each node can deviate at most 'K' positions from its actual position in the sorted list. Your task...read more

Ans.

Sort a doubly linked list with nodes that can deviate at most K positions from their actual position in the sorted list.

  • Iterate through the doubly linked list and maintain a window of size K+1 to sort the elements within the window.

  • Use insertion sort within the window to sort the elements efficiently.

  • Repeat the process until the entire list is sorted.

  • Time complexity can be optimized to O(N*log(K)) using a priority queue.

Add your answer

Q45. Rearrange Array: Move Negative Numbers to the Beginning

Given an array ARR consisting of N integers, rearrange the elements such that all negative numbers are located before all positive numbers. The order of e...read more

Ans.

Yes, this can be achieved by using the two-pointer approach to rearrange the array in-place with O(1) auxiliary space.

  • Use two pointers, one starting from the beginning and one from the end of the array.

  • Swap elements at the two pointers if they are not in the correct order (negative before positive).

  • Continue this process until the two pointers meet in the middle of the array.

Add your answer

Q46. Print All Paths Problem Statement

In this problem, you are provided with a graph consisting of 'N' nodes and 'M' unidirectional edges. Additionally, two integers 'S' and 'D' are given, representing the source a...read more

Ans.

The task is to find all unique paths from a source node to a destination node in a graph.

  • Identify all unique paths from source node to destination node in a graph

  • Ensure all nodes in the path are unique

  • Output total number of valid paths and list nodes in each path in lexicographical order

Add your answer

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

Ans.

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 better efficiency

  • Optimize by only checking up to the square root of N for divisors

Add your answer

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

Ans.

Find 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 while calculating the height.

Add your answer

Q49. Stock Trading Maximum Profit Problem

Given the stock prices for 'N' days, your goal is to determine the maximum profit that can be achieved. You can buy and sell the stocks any number of times but can only hold...read more

Ans.

The goal is to determine the maximum profit that can be achieved by buying and selling stocks on different days.

  • Iterate through the stock prices and buy on days when the price is lower than the next day, and sell on days when the price is higher than the next day.

  • Calculate the profit by summing up the differences between buying and selling prices.

  • Repeat the process for each test case and output the maximum profit possible for each case.

Add your answer

Q50. Factorial Calculation Problem Statement

Develop a program to compute the factorial of a given integer 'n'.

The factorial of a non-negative integer 'n', denoted as n!, is the product of all positive integers les...read more

Ans.

Program to compute factorial of a given integer 'n', with error handling for negative values.

  • Create a function to calculate factorial using a loop or recursion

  • Check if input is negative, return 'Error' if true

  • Handle edge cases like 0 and 1 separately

  • Use long data type to handle large factorials

Add your answer

Q51. Minimum Steps for a Knight to Reach Target

Given a square chessboard of size N x N, you need to determine the minimum number of steps a Knight takes to reach a target position from its starting position.

Input:...read more

Ans.

Find the minimum number of steps a Knight takes to reach a target position on a chessboard.

  • Use BFS algorithm to find the shortest path from knight's starting position to target position.

  • Consider all possible moves of the knight on the chessboard.

  • Keep track of visited positions to avoid revisiting them.

  • Return the minimum number of steps required to reach the target position.

Add your answer

Q52. K Sum Subset Problem Statement

Given an array arr of size 'N' and an integer 'K', determine the maximum subset sum of the array that does not exceed 'K'.

Example:

Input:
arr = [1, 3, 5, 9], K = 16
Output:
15
Ex...read more
Ans.

Find the maximum subset sum of an array that does not exceed a given integer K.

  • Use dynamic programming to solve this problem efficiently.

  • Iterate through all possible subsets of the array and keep track of the maximum sum that does not exceed K.

  • Consider the choice of including or excluding each element in the subset.

  • Optimize the solution by using memoization to avoid redundant calculations.

Add your answer

Q53. Merge Sort Linked List Problem Statement

You are given a singly linked list of integers. Your task is to sort the linked list using the merge sort algorithm.

Explanation:

Merge Sort is a divide and conquer algo...read more

Ans.

Implement merge sort algorithm to sort a singly linked list of integers.

  • Divide the linked list into two halves using slow and fast pointers.

  • Recursively sort the two halves.

  • Merge the sorted halves using a merge function.

  • Handle base cases like empty list or single node list.

  • Ensure the termination of the linked list with -1 at the end.

Add your answer

Q54. Binary Palindrome Check

Given an integer N, determine whether its binary representation is a palindrome.

Input:

The first line contains an integer 'T' representing the number of test cases. 
The next 'T' lines e...read more
Ans.

Check if the binary representation of a given integer 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.

Add your answer

Q55. Maximum Path Sum Between Two Leaves

Given a non-empty binary tree where each node has a non-negative integer value, determine the maximum possible sum of the path between any two leaves of the given tree.

Expla...read more

Ans.

Find the maximum path sum between two leaf nodes in a binary tree.

  • Traverse the tree to find the maximum path sum between two leaf nodes

  • Keep track of the maximum sum as you traverse the tree

  • Consider all possible paths that pass through the root and those that do not

  • Handle cases where there is only one leaf node in the tree

Add your answer

Q56. First Non-Repeating Character Problem Statement

You are given a string consisting of English alphabet characters. Your task is to identify and return the first character in the string that does not repeat. If e...read more

Ans.

Identify and return the first non-repeating character in a string, or the first character if all characters repeat.

  • Iterate through the string to count the frequency of each character

  • Return the first character with a frequency of 1, or the first character if all characters repeat

  • Use a hashmap to store character frequencies efficiently

Add your answer

Q57. Most Frequent Word Problem Statement

You are given two strings 'A' and 'B' composed of words separated by spaces. Your task is to determine the most frequent and lexicographically smallest word in string 'A' th...read more

Ans.

Find the most frequent and lexicographically smallest word in string 'A' that is not present in string 'B'.

  • Split strings 'A' and 'B' into words

  • Count frequency of each word in 'A'

  • Check if word is not in 'B' and is the most frequent and lexicographically smallest

  • Return the word or -1 if no such word exists

Add your answer

Q58. Count Derangements

Determine the number of derangements possible for a set of 'N' elements. A derangement is a permutation where no element appears in its original position.

Input:

An integer 'T' representing t...read more
Ans.

Count the number of derangements possible for a set of 'N' elements.

  • Derangement is a permutation where no element appears in its original position.

  • Use dynamic programming to calculate derangements efficiently.

  • Apply the formula: D(n) = (n-1) * (D(n-1) + D(n-2)), with base cases D(1) = 0 and D(2) = 1.

Add your answer

Q59. Difference between High severity and low severity with example, what is important as QA point of view?

Ans.

High severity refers to critical defects that impact the core functionality of the software, while low severity refers to minor issues that have minimal impact on functionality.

  • High severity issues can cause the software to crash or result in data loss.

  • Low severity issues are cosmetic or minor usability problems.

  • From a QA point of view, high severity issues are more critical as they can significantly impact the user experience and the overall functionality of the software.

  • Low...read more

Add your answer
Q60. Can you explain the concept of keys in database management systems?
Ans.

Keys in database management systems are unique identifiers for rows in a table.

  • Keys are used to uniquely identify each record in a table.

  • Primary key is a unique identifier for a record in a table.

  • Foreign key is a field in one table that refers to the primary key in another table.

  • Composite key is a combination of multiple columns that uniquely identify a record.

  • Unique key ensures that all values in a column are unique.

Add your answer
Q61. 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 constructor, fields, and methods, while interface can only have constants and abstract methods.

  • 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 - Ani...read more

Add your answer
Q62. What is the difference between a constructor and a method in Object-Oriented Programming?
Ans.

Constructor is a special method used to initialize objects, while a method is a regular function that performs a specific task.

  • Constructors are called automatically when an object is created, while methods need to be called explicitly.

  • Constructors have the same name as the class, while methods have unique names.

  • Constructors do not have a return type, while methods have a return type.

  • Example: Constructor - public ClassName() { // initialization code } Method - public void meth...read more

Add your answer
Q63. What are the advantages of using views in a database management system?
Ans.

Views in a database management system provide security, simplify complex queries, and improve performance.

  • Enhanced security by restricting access to certain columns or rows

  • Simplify complex queries by pre-defining joins and filters

  • Improve performance by storing frequently used queries as views

  • Reduce redundancy by storing common logic in views

Add your answer

Q64. Make a 3*3 cube where you need to fill the numbers using 1-9, rows, columns and diagonal sum should be equal to 15

Ans.

Create a 3x3 cube with numbers 1-9, where the sum of rows, columns, and diagonals is 15.

  • Start with the number 5 in the center of the cube.

  • Place the numbers 1 and 9 in the corners.

  • Fill the remaining numbers in a way that each row, column, and diagonal adds up to 15.

Add your answer
Q65. Can you explain indexing in databases?
Ans.

Indexing in databases is a technique used to improve the speed of data retrieval by creating a data structure that allows for quick lookups.

  • Indexes are created on columns in a database table to speed up the retrieval of rows that match a certain condition.

  • Types of indexes include B-tree, hash, and bitmap indexes.

  • Indexes can improve the performance of SELECT queries but may slow down INSERT, UPDATE, and DELETE operations.

  • Examples of indexes include primary keys, unique constra...read more

Add your answer

Q66. An array contain 6 different numbers, only 1 number is repeated for 5 times. So now total 10 numbers in array, Find that duplicate number in 2 steps only?

Ans.

Find the duplicate number in an array of 10 numbers with only 2 steps.

  • Use a hash set to keep track of visited numbers.

  • Iterate through the array and check if the number is already in the set.

  • If it is, then it is the duplicate number.

  • If not, add it to the set.

  • At the end, the duplicate number will be found.

Add your answer

Q67. Input an array and then print the repeating characters?? Example: Input:1,3,23,11,44,3,23,2,3. Output:3,23

Ans.

The question asks to input an array and print the repeating characters.

  • Iterate through the array and store each element in a hash table or dictionary.

  • If an element already exists in the hash table, it is a repeating character.

  • Print all the repeating characters found.

Add your answer

Q68. What are the different access modifiers and what is there uses?

Ans.

Access modifiers control the visibility and accessibility of class members.

  • Public: accessible from anywhere

  • Private: accessible only within the class

  • Protected: accessible within the class and its subclasses

  • Default: accessible within the same package

  • Used to enforce encapsulation and prevent unauthorized access

Add your answer

Q69. Input a number and then find the next higher number such that for both the number (inputted and the next higher number) in binary representation contains equal number os ones. Example: Input:3(0000000000000011)...

read more
Ans.

Find the next higher number with equal number of ones in binary representation.

  • Convert input number to binary

  • Count number of ones in binary representation

  • Increment input number until binary representation has equal number of ones

  • Convert incremented number to decimal

Add your answer

Q70. Input an array and prints the second minimum in an array?? Example Input:34,45,21,12,54,67,15 Output:15

Ans.

Program to find the second minimum in an array.

  • Sort the array and return the second element.

  • Initialize two variables to store minimum and second minimum values.

  • Loop through the array and update the variables accordingly.

Add your answer

Q71. Write a program to print elements of a linked list in reverse order by using same single linked list?

Ans.

Program to print elements of a linked list in reverse order using same single linked list

  • Traverse the linked list and push each element onto a stack

  • Pop elements from the stack and print them in reverse order

Add your answer

Q72. Take an array, store the numbers and print the numbers using arrayList?

Ans.

To store and print numbers from an array using arrayList.

  • Create an arrayList object

  • Loop through the array and add each element to the arrayList using add() method

  • Print the arrayList using toString() method

  • Example: int[] arr = {1, 2, 3}; ArrayList list = new ArrayList<>(); for(int num : arr) { list.add(num); } System.out.println(list.toString());

Add your answer
Q73. What do you mean by FCFS?
Ans.

FCFS stands for First-Come, First-Served. It is a scheduling algorithm where tasks are executed in the order they arrive.

  • FCFS is a non-preemptive scheduling algorithm.

  • Tasks are executed in the order they arrive in the queue.

  • It is simple to understand and implement.

  • Example: Consider a printer queue where print jobs are processed in the order they are submitted.

Add your answer

Q74. Clone a FULL linked list given a pointer and a random pointer

Ans.

Clone a linked list with a random pointer.

  • Create a new node for each node in the original list.

  • Use a hash table to map the original nodes to their clones.

  • Iterate through the original list again and update the random pointers of the clone nodes.

Add your answer

Q75. What is a binary tree and implementation? what is the heap? Array and sorting? Coding Problem.

Ans.

Binary tree is a data structure where each node has at most two children. Heap is a specialized tree-based data structure. Array is a collection of elements stored in contiguous memory locations.

  • Binary tree can be implemented using linked lists or arrays.

  • Heap is used to efficiently implement priority queues.

  • Sorting algorithms like bubble sort, insertion sort, merge sort, quick sort can be used to sort arrays.

  • Coding problem can be related to traversing a binary tree, implement...read more

Add your answer

Q76. How and when API controller class instance generated in c#

Ans.

API controller class instance is generated when a request is made to the API endpoint.

  • API controller class is responsible for handling incoming requests and returning responses.

  • Instance of API controller class is generated by the ASP.NET Core framework when a request is made to the API endpoint.

  • API controller class instance is disposed of after the request has been processed.

  • API controller class can be customized and configured using attributes and middleware.

Add your answer

Q77. What is constructor and destructor and also explain its working

Ans.

Constructor and destructor are special member functions in a class that are used to initialize and destroy objects respectively.

  • Constructor is called when an object is created and is used to initialize the object's data members.

  • Destructor is called when an object is destroyed and is used to free up any resources that the object was using.

  • Constructor has the same name as the class and no return type, while destructor has the same name as the class preceded by a tilde (~) and n...read more

Add your answer

Q78. Write a program for given login scenario using defined automation architecture?

Ans.

A program for login scenario using defined automation architecture.

  • Identify the elements on the login page such as username, password, and login button

  • Use automation tools like Selenium to interact with the elements and input data

  • Verify successful login by checking for expected elements on the landing page

  • Implement error handling for incorrect login credentials

  • Use a modular and scalable architecture for maintainability

Add your answer

Q79. Write test scenario for download functionality of a songs website?

Ans.

Test scenario for download functionality of a songs website

  • Verify that the download button is visible and clickable

  • Check that the downloaded file is in the correct format

  • Ensure that the downloaded file is not corrupted

  • Test the download speed for different file sizes

  • Verify that the download progress is displayed to the user

Add your answer

Q80. Find the longest palendrom in a string? Example Input: abfgerccdedccfgfer Output: ccdedcc

Ans.

To find the longest palindrome in a given string.

  • Iterate through the string and check for palindromes of odd and even lengths.

  • Keep track of the longest palindrome found so far.

  • Use two pointers to check if the substring is a palindrome.

  • If the substring is a palindrome and its length is greater than the current longest palindrome, update the longest palindrome.

Add your answer
Q81. What is the static keyword in Java?
Ans.

The static keyword in Java is used to create class-level variables and methods that can be accessed without creating an instance of the class.

  • Static variables are shared among all instances of a class.

  • Static methods can be called without creating an object of the class.

  • Static blocks are used to initialize static variables.

  • Example: public static int count = 0;

Add your answer

Q82. What is polymorphism and explain in brief?

Ans.

Polymorphism is the ability of an object to take on many forms.

  • Polymorphism allows objects of different classes to be treated as if they are of the same class.

  • It is achieved through method overriding and method overloading.

  • Example: A parent class Animal can have child classes like Dog, Cat, and Cow. All these child classes can have a method called 'makeSound', but each class can have a different implementation of the method.

  • Polymorphism makes code more flexible and reusable.

Add your answer

Q83. Reverse a linked list (iterative AND Recursive)

Ans.

Reverse a linked list using iterative and recursive methods.

  • Iterative method involves traversing the list and changing the pointers to reverse the order.

  • Recursive method involves calling the function recursively on the next node and changing the pointers.

  • Both methods have O(n) time complexity and O(1) space complexity.

  • Example: 1->2->3->4->5 becomes 5->4->3->2->1.

Add your answer
Q84. What are constraints in SQL?
Ans.

Constraints in SQL are rules and restrictions applied to columns in a table to enforce data integrity.

  • Constraints ensure data accuracy and consistency in a database.

  • Common constraints include NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY, and CHECK constraints.

  • NOT NULL constraint ensures a column cannot have a NULL value.

  • UNIQUE constraint ensures all values in a column are unique.

  • PRIMARY KEY constraint uniquely identifies each record in a table.

  • FOREIGN KEY constraint establishes...read more

Add your answer

Q85. what is theConcept of oops language

Ans.

OOPs is a programming paradigm based on the concept of objects, which can contain data and code.

  • OOPs stands for Object-Oriented Programming.

  • It focuses on creating objects that interact with each other to solve a problem.

  • It uses concepts like inheritance, encapsulation, and polymorphism.

  • Inheritance allows a class to inherit properties and methods from another class.

  • Encapsulation is the practice of hiding data and methods within a class.

  • Polymorphism allows objects to take on mu...read more

Add your answer

Q86. Difference between interface and abstract?

Ans.

Interface defines only method signatures while abstract class can have both method signatures and implementations.

  • An interface can be implemented by multiple classes while an abstract class can only be extended by one class.

  • An abstract class can have constructors while an interface cannot.

  • An abstract class can have instance variables while an interface cannot.

  • An abstract class can provide default implementations for some methods while an interface cannot.

  • An abstract class can...read more

Add your answer

Q87. What is static keyword?

Ans.

Static keyword is used to declare a variable or method that belongs to the class rather than an instance of the class.

  • Static variables are shared among all instances of a class

  • Static methods can be called without creating an instance of the class

  • Static blocks are used to initialize static variables

  • Static keyword can also be used to create nested classes

  • Example: public static int count;

Add your answer

Q88. Output of coding example based on interval functions in javascript

Ans.

Output of interval functions in JavaScript

  • Interval functions are used to execute a block of code repeatedly at a specified time interval

  • The output of the coding example will depend on the specific implementation of the interval function

  • Common interval functions in JavaScript include setInterval() and setTimeout()

Add your answer

Q89. Difference between cache and cookies?

Ans.

Cache stores data temporarily to reduce server load while cookies store user information for website personalization.

  • Cache stores frequently accessed data to reduce server load and improve website performance.

  • Cookies store user information such as login credentials, preferences, and shopping cart items.

  • Cache is temporary and can be cleared at any time, while cookies can have an expiration date.

  • Cache is stored on the user's device, while cookies are stored on the server.

  • Exampl...read more

Add your answer

Q90. Introduction Mind checking Ready to relocate?

Ans.

Yes, I am open to relocation for the right opportunity.

  • I am willing to relocate for a position that aligns with my career goals and offers growth opportunities.

  • I am open to considering relocation packages and assistance.

  • I am excited about the prospect of exploring new cities and cultures.

  • Examples: I have previously relocated for a job and found it to be a positive experience.

  • I am willing to discuss relocation during the interview process.

Add your answer

Q91. What is polymorphism?

Ans.

Polymorphism is the ability of a single function or method to operate on different types of data.

  • Polymorphism allows objects of different classes to be treated as objects of a common superclass.

  • There are two types of polymorphism: compile-time (method overloading) and runtime (method overriding).

  • Example: Inheritance in object-oriented programming languages like Java allows for polymorphism.

Add your answer

Q92. Difference between class and interface?

Ans.

Class is a blueprint for creating objects while interface defines a contract for classes to implement.

  • A class can have attributes and methods while an interface only has method signatures.

  • A class can be instantiated while an interface cannot.

  • A class can only inherit from one class while it can implement multiple interfaces.

  • Example: Class - Animal, Interface - Flyable

  • Animal can have attributes like name, age, etc. and methods like eat(), sleep(), etc.

  • Flyable interface only has...read more

Add your answer

Q93. Define Automation framework?

Ans.

Automation framework is a set of guidelines, standards, and coding practices used to create automated test scripts.

  • It provides a structured way to develop and maintain automated tests

  • It includes tools, libraries, and reusable components

  • It helps in reducing the time and effort required for testing

  • Examples include Selenium, Appium, and Robot Framework

Add your answer

Q94. What is event driven architecture

Ans.

Event driven architecture is a design pattern where the flow of the system is determined by events.

  • Events are generated by various components and can trigger actions in other components.

  • It allows for loosely coupled systems, as components can communicate without direct dependencies.

  • Common examples include message queues, pub/sub systems, and webhooks.

Add your answer

Q95. Dual logging in Spring Mvc architecture.

Ans.

Dual logging in Spring MVC architecture involves configuring two different logging frameworks to log messages in parallel.

  • Configure both Logback and Log4j in the Spring MVC application

  • Use different log levels for each framework to control the verbosity of logs

  • Specify separate log files for each framework to store the log messages

Add your answer

Q96. What is memory segmentation?

Ans.

Memory segmentation is a memory management technique where memory is divided into segments to improve efficiency and organization.

  • Memory segmentation divides memory into segments of different sizes for better organization.

  • Each segment is assigned a base address and a limit to control access.

  • Segments can be used to store different types of data or code, such as stack, heap, and code segments.

  • Segmentation can help prevent memory fragmentation and improve memory utilization.

  • Exam...read more

Add your answer

Q97. Middle of linked list

Ans.

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

  • Initialize two pointers, slow and fast, at the head of the linked list.

  • Move slow pointer by one node and fast pointer by two nodes until fast pointer reaches the end of the list.

  • The node pointed to by the slow pointer at this point is the middle element of the linked list.

Add your answer

Q98. Interfaces in oops

Ans.

Interfaces define a contract for classes to implement certain methods and properties.

  • Interfaces allow for polymorphism and loose coupling.

  • Classes can implement multiple interfaces.

  • Interfaces cannot be instantiated on their own.

  • Interfaces can have default method implementations.

  • Interfaces can be used to enforce design patterns like the adapter pattern.

Add your answer

Q99. Inheritance in java and keywords

Ans.

Inheritance in Java allows a class to inherit attributes and methods from another class. Keywords like 'extends' and 'super' are used.

  • Inheritance allows a class to inherit attributes and methods from another class

  • The 'extends' keyword is used to create a subclass that inherits from a superclass

  • The 'super' keyword is used to access the superclass constructor or methods

  • Example: class Animal {} class Dog extends Animal {}

Add your answer

Q100. Kafka and how to implement

Ans.

Kafka is a distributed streaming platform used for building real-time data pipelines and streaming applications.

  • Kafka is used for building real-time data pipelines and streaming applications

  • It provides high-throughput, fault-tolerant, and scalable messaging system

  • Kafka uses topics to categorize messages and consumers subscribe to topics to receive messages

  • Producers publish messages to topics and consumers consume messages from topics

Add your answer
1
2

More about working at Nagarro

#2 Best Large Company - 2022
#1 Best IT/ITES Company - 2022
Contribute & help others!
Write a review
Share interview
Contribute salary
Add office photos

Interview Process at Intelli Search

based on 40 interviews
5 Interview rounds
Technical Round - 1
Technical Round - 2
HR Round - 1
HR 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

4.1
 • 50 Interview Questions
4.0
 • 39 Interview Questions
1.9
 • 22 Interview Questions
3.8
 • 17 Interview Questions
4.2
 • 14 Interview Questions
3.8
 • 11 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