Categories of Questions

## Array Questions Accenture

**Question 1. Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i** Suppose you have an integer array. The problem statement asks to rearrange the array in such a way that the elements at even position in an array should be greater than all elements before it and the elements at odd positions should be less than the elements before it. Example ...

**Question 2. Maximum difference between frequency of two elements such that element having greater frequency is also greater** Suppose, you have an integer array. The problem statement asks to find out the maximum difference between the frequency of any two distinct elements of a given array, but the element with the greater frequency should also be greater in value than the other integer. Example Input: arr[] = {2,4,4,4,3,2} ...

**Question 3. Longest Subarray Having Count of 1s One More than Count of 0s** We have given an array of integers. An array contains 1’s and 0’s only. The problem statement asks to find out the length of the longest Sub-Array which having the quantity of 1’s digit is just one more than the count of 0’s in a sub-array. Example Input: arr[] = ...

**Question 4. Maximum Array from Two given Arrays Keeping Order Same** Suppose we have two integers array of same size n. Both of the arrays can contain common numbers as well. The problem statement asks to form the resultant array that contains the ‘n’ maximum values from both of the arrays. The first array should be prioritized (elements of the first ...

**Question 5. Count Subarrays with Same Even and Odd Elements** Suppose you have given an integer array of N size. As there are numbers, numbers are odd or even. The problem statement is count subarray with the same even and odd elements or finds out the count of sub-arrays that has an equal number of even and odd integers. Example ...

**Question 6. Rearrange an Array Such that arr[i] is equal to i** “Rearrange an array such that arr[i]=i” problem states that you are given an array of integers ranging from 0 to n-1. Since all the elements may not be present in the array, then in place of them -1 is there. The problem statement asks to rearrange the array in such ...

**Question 7. Maximum Number of Chocolates to be Distributed Equally Among k Students** “The maximum number of chocolates to be distributed equally among k students” states that you are given n boxes that have some chocolates in it. Suppose there are k students. The task is to distribute the maximum number of chocolates among k students equally, by selecting consecutive boxes. We can ...

**Question 8. Maximum subsequence sum such that no three are consecutive** The problem “Maximum subsequence sum such that no three are consecutive ” states that you are given an array of integers. Now you need to find a subsequence that has the maximum sum given that you cannot consider three consecutive elements. To recall, a subsequence is nothing but an array ...

**Question 9. Check if Array Contains Contiguous Integers With Duplicates Allowed** You are given an array of integers which can contain duplicate elements as well. The problem statement asks to find out if it is a set of contiguous integers, print “Yes” if it is, print “No” if it is not. Example Sample Input: [2, 3, 4, 1, 7, 9] Sample ...

**Question 10. Print all triplets in sorted array that form AP** The problem “Print all triplets in sorted array that form AP” states that we have given a sorted integer array. The task is to find out all the possible triplets that can form an Arithmetic Progression. Example arr[] = {1,3,5,7,8,12,15,16,20,30} (1, 3, 5), (3, 5, 7), (1, 8, 15), (8, ...

**Question 11. Minimum sum of multiplications of n numbers** The problem “Minimum sum of multiplications of n numbers” states that you are given n integers and you need to minimize the sum of multiplication of all the numbers by taking two elements that are adjacent at a time and putting back their sum mod 100 until a single number ...

**Question 12. Check if two arrays are equal or not** The problem “Check if two arrays are equal or not” states that you are given two arrays. The problem statement says that you have to determine if given arrays are equal or not. Example arr1[] = { 1, 4, 2, 5, 2 }; arr2[] = { 2, 1, 5, 4, ...

**Question 13. Replace two consecutive equal values with one greater** Problem Statement Suppose you have an integer array. The problem “Replace two consecutive equal values with one greater” asks to replace all those pair values say ‘a’ which comes consecutively with a number “a+1” 1 greater than them (two consecutive numbers), such that even after the modification or repetition there ...

**Question 14. Convert array into Zig-Zag fashion** Problem Statement The problem “Convert array into Zig-Zag fashion” states that you are given an – of integers. The problem statement asks to sort the array in a zig-zag manner such that the elements in the array will look like à a < b > c < d > e ...

**Question 15. Distance of nearest cell having 1 in a binary matrix** Problem Statement The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix(containing only 0s and 1s) with at least one 1. Find the distance of the nearest cell having 1 in the binary matrix for all the elements of the ...

**Question 16. Find all permuted rows of a given row in a matrix** Problem Statement Find all permuted rows of a given row in a matrix states that you are given a matrix of size m*n and a matrix row number says ‘row’. The problem statement asks to find out all the possible rows which are permutation to the given row. This is ...

**Question 17. Longest Span with same Sum in two Binary arrays** Problem Statement You are given two arrays of which each contains binary number. The problem statement asks to find longest span with same sum in two binary arrays, that is to find out the maximum length common sub-array from (i, j) in such a way that j is greater than ...

**Question 18. Largest area rectangular sub-matrix with equal number of 1’s and 0’s** Problem Statement Given a binary matrix of size n x m. The problem is to find the largest area rectangular sub-matrix with equal number of 1’s and 0’s. Example Dimensions = 4 x 4 Matrix: 1 1 1 1 0 1 0 1 1 0 1 0 1 0 0 ...

**Question 19. Check if an Array is Stack Sortable** In check if an array is stack sortable problem we have given an array a[ ] of size n containing elements from 1 to n in random order. Sort the array in ascending order using a temporary stack following only these two operations – Remove the element at the starting ...

**Question 20. Next Greater Frequency Element** In the next greater frequency element problem, we have given an array a[ ] of size n containing numbers. For each number in the array print, the number to it’s right in an array with a frequency greater than that of the current number. Example Input a[] = {1, 1, ...

**Question 21. Insertion Sort** Sort a given unsorted array using the insertion sort algorithm. Input: {9,5,1,6,11,8,4} Output: {1,4,5,6,8,9,11} Theory Insertion Sort sorts numbers in the same way as we humans sort a set of numbered objects (ex cards) A number is taken from an unsorted array (right subarray) to a position in the sorted ...

**Question 22. Longest Span with same Sum in two Binary Arrays II** Problem Statement In the “Longest Span with same Sum in two Binary Arrays II” problem, we have given two binary arrays “a” and “b” with the same size. Write a program to print the longest span with the same sum in two arrays. This can be clearly explained in the ...

**Question 23. Find the Subarray of given length with Least Average** Problem Statement In the “Find the Subarray of given length with Least Average” problem we have given an array and an input integer X. Write a program to find the subarray of length X with least/minimum average. Prints the starting and ending indexes of the subarray which has the least ...

**Question 24. Multiplication of Previous and Next** Problem Statement Multiplication of Previous and Next: In the given array replace every element with the product of next and previous elements to it. And for the first element(a[0]) we need to replace it with the product of next and itself, for the last element(a[n-1]) we need to replace it ...

## String Questions Accenture

**Question 25. Check if Array Contains Contiguous Integers With Duplicates Allowed** You are given an array of integers which can contain duplicate elements as well. The problem statement asks to find out if it is a set of contiguous integers, print “Yes” if it is, print “No” if it is not. Example Sample Input: [2, 3, 4, 1, 7, 9] Sample ...

**Question 26. String comparison containing wildcards** In String comparison containing wildcards problem, we have given two strings second string contains small alphabets and the first contains small alphabets and some wildcard patterns. Wildcard patterns are: ?: we can replace this wildcard with any small alphabet. *: we can replace this wildcard with any string. An empty ...

**Question 27. Check if all Rows of a Matrix are Circular Rotations of Each Other** Problem Statement In the “Check if all Rows of a Matrix are Circular Rotations of Each Other” problem we have given a char matrix, write a program to find whether all rows are circular rotations of each other or not. If all rows are circular rotations of each other print ...

**Question 28. Sort a String According to Another String** Problem Statement Given two input strings, a pattern and a string. We need to sort the string according to the order defined by the pattern. Pattern string has no duplicates and it has all characters of the string. Input Format The first line containing a string s which we need ...

**Question 29. Split Four Distinct Strings** Problem Statement In the “Split Four Distinct Strings” problem we have to check if the given input string can split into 4 strings such that each string is non-empty and different from each others. Input Format The first and only one lone containing string “s”. Output Format Print “Yes” if ...

**Question 30. Convert a String that is Repetition of a Substring of Length K** Problem Statement In the “Convert a String that is Repetition of a Substring of Length K” problem we have given a string “s” and an integer “k”. Write a program to check whether is it possible to convert it to a string that is the repetition of a substring with ...

**Question 31. Longest Common Prefix using Divide and Conquer** Problem Statement In the “Longest Common Prefix using Divide and Conquer ” problem, we have given an integer n and n strings. Write a program that will print the longest common prefix. If there is no common prefix then print “-1”. Input Format The first line contains an integer n. ...

## Tree Questions Accenture

**Question 32. Check if each internal node of a BST has exactly one child** Problem Statement “Check if each internal node of a BST has exactly one child” problem states that you are given a preorder traversal of a binary search tree. And you need to find if all the non-leaf nodes contain only a single child. Here we also consider that all the ...

## Graph Questions Accenture

**Question 33. Distance of nearest cell having 1 in a binary matrix** Problem Statement The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix(containing only 0s and 1s) with at least one 1. Find the distance of the nearest cell having 1 in the binary matrix for all the elements of the ...

**Question 34. Transpose Graph** Problem Statement The problem “Transpose graph” states that you are given a graph and you need to find the transpose of the given graph. Transpose: Transpose of a directed graph produces another graph with same edge & node configurations but the direction of all the edges have been reversed. Example ...

## Stack Questions Accenture

**Question 35. Check if an Array is Stack Sortable** In check if an array is stack sortable problem we have given an array a[ ] of size n containing elements from 1 to n in random order. Sort the array in ascending order using a temporary stack following only these two operations – Remove the element at the starting ...

**Question 36. Next Greater Frequency Element** In the next greater frequency element problem, we have given an array a[ ] of size n containing numbers. For each number in the array print, the number to it’s right in an array with a frequency greater than that of the current number. Example Input a[] = {1, 1, ...

## Queue Questions Accenture

**Question 37. Distance of nearest cell having 1 in a binary matrix** Problem Statement The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix(containing only 0s and 1s) with at least one 1. Find the distance of the nearest cell having 1 in the binary matrix for all the elements of the ...

## Matrix Questions Accenture

**Question 38. Distance of nearest cell having 1 in a binary matrix** Problem Statement The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix(containing only 0s and 1s) with at least one 1. Find the distance of the nearest cell having 1 in the binary matrix for all the elements of the ...

**Question 39. Find all permuted rows of a given row in a matrix** Problem Statement Find all permuted rows of a given row in a matrix states that you are given a matrix of size m*n and a matrix row number says ‘row’. The problem statement asks to find out all the possible rows which are permutation to the given row. This is ...

**Question 40. Largest area rectangular sub-matrix with equal number of 1’s and 0’s** Problem Statement Given a binary matrix of size n x m. The problem is to find the largest area rectangular sub-matrix with equal number of 1’s and 0’s. Example Dimensions = 4 x 4 Matrix: 1 1 1 1 0 1 0 1 1 0 1 0 1 0 0 ...

**Question 41. Check if all Rows of a Matrix are Circular Rotations of Each Other** Problem Statement In the “Check if all Rows of a Matrix are Circular Rotations of Each Other” problem we have given a char matrix, write a program to find whether all rows are circular rotations of each other or not. If all rows are circular rotations of each other print ...

## Other Questions Accenture

**Question 42. Sequences of given length where every element is more than or equal to twice of previous** The problem “Sequences of given length where every element is more than or equal to twice of previous” provides us with two integers m and n. Here m is the largest number that can exist in the sequence and n is the number of elements that must be present in the ...

**Question 43. Print the Fibonacci numbers in reverse order** Problem Statement Given a number n, print the fibonacci numbers in reverse order. Example n = 5 3 2 1 1 0 Explanation: The Fibonacci numbers are 0, 1, 1, 2, 3 as per their ordering. But since we needed to print in reverse order. n = 7 8 5 ...

**Question 44. Compute nCr % p** Problem Statement The problem “Compute nCr % p” states that you are required to find binomial coefficient modulo p. So you first must know about the binomial coefficient. We have already discussed that in a previous post. You can check that here. Example n = 5, r = 2, p ...