Categories of Questions

## Factset Array Questions

**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. Count pair with Given Sum** In problem “count pair with given sum” we have given an integer array[] and another number say ‘sum’, you have to determine whether any of the two elements in a given array has a sum equal to “sum”. Example Input: arr []={1,3,4,6,7} and sum = 9. Output: “ Elements found ...

**Question 3. Minimum Delete Operations to make all Elements of Array Same** Suppose we have an input of array with “x” number of elements. We have given a problem that we have to find the deletions operations, which should be the minimum that is required to make an equal array i.e., the array will consist of equal elements. Example Input: [1, 1, ...

**Question 4. Maximum Distance Between two Occurrences of Same Element in Array** Suppose you are given an array with some repeated numbers. We have to find the maximum distance between the two same occurrences of a number with different index, present in an array. Example Input: array = [1, 2, 3, 6, 2, 7] Output: 3 Explanation: Because elements at array [1] ...

**Question 5. 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 6. 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 7. Minimum swaps required to bring all elements less than or equal to k together** The problem “Minimum swaps required to bring all elements less than or equal to k together” states that you have an integer array. The problem statement asks to find out the smallest count of swaps that will be required to get the elements together which are less than or equal ...

**Question 8. Sorting using trivial hash function** The problem “Sorting using trivial hash function” states that you are given an integer array. An array can be containing both negative and positive numbers. The problem statement asks to sort the array using Trivial Hash Function. Example arr[] = {5,2,1,3,6} {1, 2, 3, 5, 6} arr[] = {-3, -1, ...

**Question 9. Find duplicates in a given array when elements are not limited to a range** The problem “Find duplicates in a given array when elements are not limited to a range” states that you have an array consisting of n integers. The problem statement it to find out the duplicate elements if present in the array. If no such element exists return -1. Example [ ...

**Question 10. Find elements which are present in first array and not in second** The problem “Find elements which are present in first array and not in second” states that you are given two arrays. Arrays consist of all the integers. You have to find out the numbers which will not be present in the second array but present in the first array. Example ...

**Question 11. Longest subsequence such that difference between adjacents is one** The problem “Longest subsequence such that difference between adjacents is one” states that you are given an integer array. Now you need to find the length of longest subsequence such that the difference of adjacent elements is 1. Example 1 2 3 4 7 5 9 4 6 Explanation As ...

**Question 12. k-th missing element in increasing sequence which is not present in a given sequence** The problem “k-th missing element in increasing sequence which is not present in a given sequence” states that you are given two arrays. One of them is arranged in ascending order and another normal unsorted array with number k. Find the kth missing element which is not present in normal ...

**Question 13. How to check if two given sets are disjoint?** The problem “How to check if two given sets are disjoint?” states that suppose you are given two sets in the form of array say set1[] and set2[]. Your task is to find out whether the two sets are Disjoint Sets or not. Example inputSet1[] = {1, 15, 8, 9, ...

**Question 14. Find whether a subarray is in form of a mountain or not** Problem Statement The problem “Find whether a subarray is in form of a mountain or not” states that you are given an integer array and a range. The problem statement asks to find out whether the sub-array formed between the given range is in form of a mountain form or ...

**Question 15. Delete consecutive same words in a sequence** Problem Statement the problem “Delete consecutive same words in a sequence” states that you are given a list of n strings. If there are two same words present consecutively, delete both of them. Print the total number of words/strings left in the list after the deletion of all such pairs. ...

**Question 16. First missing positive** Problem Statement “First missing positive” problem states that you are given an array a[ ] (sorted or unsorted) of size n. Find the first positive number that is missing in this array. Example a[ ] = {1, 3, -1, 8} 2 Explanation: If we sort the array we get {-1, ...

**Question 17. Numbers with prime frequencies greater than or equal to k** Problem Statement Problem “Numbers with prime frequencies greater than or equal to k” states that you are given an array of integers size n and an integer value k. All the numbers inside it are prime numbers. The problem statement asks to find out the numbers which appear in the ...

**Question 18. Maximum sum rectangle in a 2D matrix** Problem Statement Find the maximum sum rectangle in a 2D matrix i.e. to find a sub-matrix with maximum sum. A sub-matrix is nothing but a 2D array inside of the given 2D array. So, you have a matrix of signed integers, you need to calculate the sum of sub-matrices and ...

**Question 19. Largest Sum Contiguous Subarray** Problem Statement You are given an array of integers. The problem statement asks to find out the largest sum contiguous subarray. This means nothing but to find a subarray (continuous elements) which has the largest sum among all other subarrays in the given array. Example arr[] = {1, -3, 4, ...

**Question 20. Count Pairs With Given Sum** Given an integer array of size n, and an integer ‘K’, you need to count the number of pairs(need not to be unique) present in the array whose sum is equal to ‘K’. Example Input: Arr={1, 5, 7, 1} K=6 Output: 2 Brute force solution for Count Pairs With Given Sum Main idea ...

**Question 21. Most Frequent Element in an Array** You are given an array of integers. The problem statement says that you have to find out the most frequent element present in an array. If there are multiple values that occurs the maximum number of times, then we have to print any of them. Example Input [1, 4,5,3,1,4,16] Output ...

**Question 22. Maximum Product of Indexes of Next Greater on Left and Right** Given an array a[ ] of size n. For each element at position, i find the L[i] and R[i] where – L[i] = the closest index to i where L[closest index] > L[i] and closest index < i. R[i] = the closest index to i where R[closest index] > R[i] ...

**Question 23. Print Next Greater Number of Q queries** In Print Next Greater Number of Q queries problem we have given an array a[ ] of size n containing numbers and another array q[ ] of size m representing queries. Each query represents the index in array a[ ]. For each query, i print the number from the array ...

**Question 24. Postfix to Prefix Conversion** In this problem, we have given a string that denotes the postfix expression. We have to do postfix to prefix conversion. Prefix Notation In this notation, we write the operands after the operator. It is also known as Polish Notation. For instance: +AB is a prefix expression. Postfix Notation In ...

**Question 25. 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 26. Find the two Numbers with Odd Occurrences in an Unsorted Array** Problem Statement In the “Find the two Numbers with Odd Occurrences in an Unsorted Array” problem we have given an unsorted array. In this array other than two numbers all other numbers occur even number of times. Find the two numbers that occur an odd number of times. Note: The ...

**Question 27. First Circular Tour to Visit all the Petrol Bunks** In the first circular tour to visit all the petrol bunks problem the statement is such that there is a circle with n petrol pumps on the circle. Every petrol pump has a pair of data. The first value is the amount of petrol pump has and the second is ...

**Question 28. Find a Sorted Subsequence of size 3** Problem Statement In the given unsorted array of integers. We need to find a sorted subsequence of size 3. Let three elements be array[i], array[j], array[k] then, array[i] < array[j] < array[k] for i< j < k. If there are multiple triplets found in the array then print any one ...

**Question 29. Find a Fixed Point in a Given Array** Problem Statement Given an array of n distinct elements, find a fixed point in a given array, where a fixed point means the element value is the same as the index. Example Input 5 arr[] = {0,4,8,2,9} Output 0 is a fixed point in this array because value and index ...

**Question 30. Smallest Positive Number Missing in an Unsorted Array** Problem Statement In the given unsorted array find the smallest positive number missing in an unsorted array. A positive integer doesn’t include 0. We can modify the original array if needed. The array may contain positive and negative numbers. Example a. Input array : [3, 4, -1, 0, -2, 2, 1, ...

**Question 31. 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 ...

**Question 32. Print All Distinct Elements of the Array** Problem Statement We have an array of containing N integers which may be positive or negative. We have to print all distinct elements of the array. In other words, we can say that if a number occurs more than one time then we print only that number once. Example Input ...

## Factset String Questions

**Question 33. Delete consecutive same words in a sequence** Problem Statement the problem “Delete consecutive same words in a sequence” states that you are given a list of n strings. If there are two same words present consecutively, delete both of them. Print the total number of words/strings left in the list after the deletion of all such pairs. ...

**Question 34. Shortest Palindrome** In the shortest palindrome problem, we have given a string s of length l. Add characters in front of it to make it palindrome if it’s not. Print the smallest count of characters used to make the given string a palindrome. Example Input : s = abc Output: 2 (by ...

**Question 35. Find if an Expression has Duplicate Parenthesis or Not** Given a string containing balanced parenthesis. Find if the expression/string contains duplicate parenthesis or not. Duplicate Parenthesis When an expression is in the middle of or surrounded by the same type of balanced parenthesis i.e. enclosed between the same type of opening and closing parenthesis more than once it is ...

**Question 36. Postfix to Infix Conversion** In postfix to infix conversion problem, we have given expression in postfix notation. Write a program to convert the given notation in infix notation. Infix Notation In this notation, the operators are written between the operands. It is similar to how we generally write an expression. For instance: A + ...

**Question 37. Prefix to Postfix Conversion** In prefix to postfix conversion problem, we have given expression in prefix notation in string format. Write a program to convert the given notation in postfix notation. Prefix Notation In this notation, we write the operands after the operator. It is also known as Polish Notation. For instance: +AB is ...

**Question 38. Next Permutation** In the next permutation problem we have given a word, find the lexicographically greater_permutation of it. Example input : str = "tutorialcup" output : tutorialpcu input : str = "nmhdgfecba" output : nmheabcdfg input : str = "algorithms" output : algorithsm input : str = "spoonfeed" output : Next Permutation ...

**Question 39. Palindrome using Recursion** Problem Statement In the “Recursive Palindrome Check” or “Palindrome using Recursion” problem we have given a string “s”. We have to write a program to check if the given string is palindrome or not using recursion. A palindrome is a word, number, phrase, or other sequence of characters that reads ...

**Question 40. Minimum Characters to be Added at Front to Make String Palindrome** Problem Statement In the “Minimum Characters to be Added at Front to Make String Palindrome” problem we have given a string “s”. Write a program to find the minimum characters to be added at the front to make a string palindrome. Input Format The first and only one line containing ...

**Question 41. Change Gender of a given String** Problem Statement In the “Change Gender of a given String” problem we have given a string “s”. Write a program that will toggle all the gender-specific words in the input string. Input Format The first and only one line containing a sentence or string with spaces “s”. Output Format Print ...

**Question 42. Pangram Checking** Problem Statement In the “Pangram Checking” problem we have given a sentence “s”. Check if the given sentence/string is Pangram or not. A Pangram is a sentence/string containing every letter of the alphabet from a to z or No case sensitivity. Input Format The first and only one line containing ...

## Factset Tree Questions

**Question 43. Write Code to Determine if Two Trees are Identical** The problem “Write Code to Determine if Two Trees are Identical” states that you are given two binary trees. find out if they are identical or not? Here, identical tree means that both the binary trees have the same node value with the same arrangement of nodes. Example Both trees ...

**Question 44. Diagonal Traversal of Binary Tree** Problem Statement The problem “Diagonal Traversal of Binary Tree” states that you are given a binary tree and now you need to find the diagonal view for the given tree. When we see a tree from the top-right direction. The nodes which are visible to us is the diagonal view ...

**Question 45. Clone a Binary Tree with Random Pointers** Problem Statement You are given a complete binary tree with some random pointers. Random pointers are referred to nodes which every node points to other than its left and right child. So, this also changes the standard structure of a node in a simple binary tree. Now the node of ...

**Question 46. Iterative Postorder Traversal Using Two Stacks** Problem Statement The problem “Iterative Postorder Traversal Using Two Stacks” states that you are given a binary tree with n nodes. Write the program for it’s iterative postorder traversal using two stacks. Example Input 4 5 2 6 7 3 1 Input 4 2 3 1 Algorithm Create ...

**Question 47. A program to check if a binary tree is BST or not** Problem Statement “A program to check if a binary tree is BST or not” states that you are given a binary tree and you need to check if the binary tree satisfies the properties of the binary search tree. So, the binary tree has the following properties: The left subtree ...

**Question 48. Maximum Depth Of Binary Tree** Problem Statement “Maximum depth of binary tree” problem states that you are given a binary tree data structure. Print the maximum depth of the given binary tree. Example Input 2 Explanation: Maximum depth for the given tree is 2. Because there is only a single element below the root (i.e. ...

**Question 49. Binary Tree Data Structure** In this article, we will read about the Binary Tree Data Structure. Trees are hierarchical data structures where every node has a parent node except the root node. The nodes with no child are called leaves. Need for Trees? 1. Trees are used when we need to store data in ...

**Question 50. Insertion in a Binary Tree** In this article, we will learn the insertion in a binary tree. We have already seen the concept of BFS in the previous article, so here we will use the same concept to insert the data in a binary tree. The concept is traversing the tree in level order and ...

## Factset Graph Questions

**Question 51. Minimum Operations to convert X to Y** Problem Statement The problem “Minimum Operations to convert X to Y” states that you are given two numbers X and Y, it is needed to convert X into Y using following operations: Starting number is X. Following operations can be performed on X and on the numbers that are generated ...

**Question 52. Check if two nodes are on the same path in a Tree** Problem Statement The problem “Check if two nodes are on the same path in a Tree” states that you are given a n-ary tree (directed acyclic graph) rooted at root node with uni-directional edges between it’s vertices. You are also given a list of queries q. Each query in list ...

**Question 53. Iterative Depth First Traversal of Graph** In iterative depth first traversal of graph problem, we have given a graph data structure. Write the program to print the depth first traversal of the given graph using the iterative method. Example Input : 0 -> 1, 0 -> 2, 1 -> 2, 2 -> 0, 2 -> 3, 3 ...

**Question 54. Graph and its representation** A graph is an abstract data type representing relations or connections between objects(like cities are connected by rough road). In the graph and its representation, basically, the relation is denoted by edges and objects by vertices(nodes). A graph consists of a finite set of vertices and edges. A graph is ...

## Factset Stack Questions

**Question 55. Design a stack that supports getMin() in O(1) time and O(1) extra space** Design a stack that supports getMin() in O(1) time and O(1) extra space. Thus the special stack data structure must support all the operations of the stack like – void push() int pop() bool isFull() bool isEmpty() in constant time. Add an additional operation getMin() to return the minimum value ...

**Question 56. Delete consecutive same words in a sequence** Problem Statement the problem “Delete consecutive same words in a sequence” states that you are given a list of n strings. If there are two same words present consecutively, delete both of them. Print the total number of words/strings left in the list after the deletion of all such pairs. ...

**Question 57. Reverse a stack without using extra space in O(n)** Problem Statement The problem “Reverse a stack without using extra space in O(n)” states that you are given a stack data structure. Reverse the given stack without using extra O(n) space. Example 5 4 3 2 1 1 2 3 4 5 80 60 10 20 20 10 60 80 ...

**Question 58. Iterative Postorder Traversal Using Two Stacks** Problem Statement The problem “Iterative Postorder Traversal Using Two Stacks” states that you are given a binary tree with n nodes. Write the program for it’s iterative postorder traversal using two stacks. Example Input 4 5 2 6 7 3 1 Input 4 2 3 1 Algorithm Create ...

**Question 59. Tracking current Maximum Element in a Stack** Problem Statement “Tracking current Maximum Element in a Stack” states that you are given a stack data structure. Create a function to keep the track of the maximum value in the stack till the current index. Example 4 19 7 14 20 4 19 19 19 20 Explanation: The maximum ...

**Question 60. Check if stack elements are pairwise consecutive** Problem Statement “Check if stack elements are pairwise consecutive” problem states that you are given a stack data structure of integer type. Create a function to check if all the given elements are pairwise consecutive ( either in increasing or decreasing order ) or not. If the number of elements ...

**Question 61. Iterative Depth First Traversal of Graph** In iterative depth first traversal of graph problem, we have given a graph data structure. Write the program to print the depth first traversal of the given graph using the iterative method. Example Input : 0 -> 1, 0 -> 2, 1 -> 2, 2 -> 0, 2 -> 3, 3 ...

**Question 62. Reversing a Queue** In Reversing a Queue problem we have given a queue, write an algorithm to reverse the queue. Examples Input queue = 10 -> 8 -> 4 -> 23 Output queue = 23->4->8->10 Input queue = 11 -> 98 -> 31 -> 42 -> 73 -> 6 Output queue = 6 ...

**Question 63. Maximum Product of Indexes of Next Greater on Left and Right** Given an array a[ ] of size n. For each element at position, i find the L[i] and R[i] where – L[i] = the closest index to i where L[closest index] > L[i] and closest index < i. R[i] = the closest index to i where R[closest index] > R[i] ...

**Question 64. Reverse a Stack Using Recursion** In reverse a stack using recursion problem, we have given a stack data structure. Reverse its elements using recursion. Only the below-listed functions of the stack can be used – push(element) – to insert the element in the stack. pop() – to remove/delete the element at the top of the ...

**Question 65. Find if an Expression has Duplicate Parenthesis or Not** Given a string containing balanced parenthesis. Find if the expression/string contains duplicate parenthesis or not. Duplicate Parenthesis When an expression is in the middle of or surrounded by the same type of balanced parenthesis i.e. enclosed between the same type of opening and closing parenthesis more than once it is ...

**Question 66. How to Create Mergable Stack?** We have to design and create a stack that performs the operations in constant time. Here we have one problem which is how to create mergable stack? Here we perform the below operation for merge two stacks. push(element): Insert the element in the stack. pop(): Remove the top element in ...

**Question 67. Print Next Greater Number of Q queries** In Print Next Greater Number of Q queries problem we have given an array a[ ] of size n containing numbers and another array q[ ] of size m representing queries. Each query represents the index in array a[ ]. For each query, i print the number from the array ...

**Question 68. Tower Of Hanoi** Tower of Hanoi is a mathematical problem with the following conditions: There are three towers There may be n number of rings present The rings are of different sizes Only one disk can be moved at a time Any disk can only be moved on the top of a bigger ...

**Question 69. Postfix to Infix Conversion** In postfix to infix conversion problem, we have given expression in postfix notation. Write a program to convert the given notation in infix notation. Infix Notation In this notation, the operators are written between the operands. It is similar to how we generally write an expression. For instance: A + ...

**Question 70. Prefix to Postfix Conversion** In prefix to postfix conversion problem, we have given expression in prefix notation in string format. Write a program to convert the given notation in postfix notation. Prefix Notation In this notation, we write the operands after the operator. It is also known as Polish Notation. For instance: +AB is ...

**Question 71. Postfix to Prefix Conversion** In this problem, we have given a string that denotes the postfix expression. We have to do postfix to prefix conversion. Prefix Notation In this notation, we write the operands after the operator. It is also known as Polish Notation. For instance: +AB is a prefix expression. Postfix Notation In ...

## Factset Queue Questions

**Question 72. Implementation of Deque using Doubly Linked List** Problem Statement The problem “Implementation of Deque using Doubly Linked List” states that you need to implement the following functions of Deque or Doubly Ended Queue using a doubly linked list, insertFront(x) : Add element x at the starting of Deque insertEnd(x) : Add element x at the end of ...

**Question 73. Find the First Circular Tour that visits all the Petrol Pumps** Problem Statement The problem “Find the First Circular Tour that visits all the Petrol Pumps” states that there are N petrol pumps on a circular road. Given the petrol that every petrol pump has and the amount of petrol required to cover the distance between two petrol pumps. So you ...

**Question 74. Reversing a Queue** In Reversing a Queue problem we have given a queue, write an algorithm to reverse the queue. Examples Input queue = 10 -> 8 -> 4 -> 23 Output queue = 23->4->8->10 Input queue = 11 -> 98 -> 31 -> 42 -> 73 -> 6 Output queue = 6 ...

**Question 75. Insertion in a Binary Tree** In this article, we will learn the insertion in a binary tree. We have already seen the concept of BFS in the previous article, so here we will use the same concept to insert the data in a binary tree. The concept is traversing the tree in level order and ...

## Factset Matrix Questions

**Question 76. Maximum sum rectangle in a 2D matrix** Problem Statement Find the maximum sum rectangle in a 2D matrix i.e. to find a sub-matrix with maximum sum. A sub-matrix is nothing but a 2D array inside of the given 2D array. So, you have a matrix of signed integers, you need to calculate the sum of sub-matrices and ...

## Factset Other Questions

**Question 77. Minimum Moves to Equal Array Elements Leetcode Solution** Problem Statement In this problem, we are given an array of integers. Also, we are allowed to perform a certain set of operations on this array. In one operation, we can increment ” n – 1″ (all elements except any one) elements in the array by 1. We need to ...

**Question 78. Total Numbers With no Repeated Digits in a Range** You are given a range of numbers (start, end). The given task says to find out the total numbers of numbers with no repeated digits in a range. Example Input: 10 50 Output: 37 Explanation: 10 has no repeated digit. 11 has a repeated digit. 12 has no repeated digit. ...

**Question 79. Print n terms of Newman-Conway Sequence** Problem Statement The problem “Print n terms of Newman-Conway Sequence” states that you are given an integer “n”. Find the first n terms of Newman-Conway Sequence then print them. Example n = 6 1 1 2 2 3 4 Explanation All the terms which are printed follow the Newman-Conway Sequence ...

**Question 80. Write a function to get the intersection point of two Linked Lists** Problem Statement The problem “Write a function to get the intersection point of two Linked Lists” states that you are given two linked lists. But they are not independent linked lists. They are connected at some point. Now you need to find this point of intersection of these two lists. ...

**Question 81. Delete Nth node from the end of the given linked list** Problem Statement The problem “Delete Nth node from the end of the given linked list” states that you are given a linked list with some nodes. And now you need to remove nth node from the end of the linked list. Example 2->3->4->5->6->7 delete 3rd node from last 2->3->4->6->7 Explanation: ...

**Question 82. Print Fibonacci sequence using 2 variables** Problem Statement The problem “Print Fibonacci sequence using 2 variables” states that you need to print the Fibonacci sequence but there is a limitation of using only 2 variables. Example n = 5 0 1 1 2 3 5 Explanation The output sequence has the first five elements of the ...

**Question 83. Page Replacement Algorithms in Operating Systems** What is Page Replacement? The modern operating systems use paging for memory management and many times there is a need for page replacement. Page replacement is the process of replacing a page that is currently present in the memory with a page that is needed but is not present in ...

**Question 84. Word Wrap Problem** Problem Statement The word wrap problem states that given a sequence of words as input, we need to find the number of words that can be fitted in a single line at a time. So, for doing this we put breaks in the given sequence such that the printed document ...

**Question 85. Count items common to both the lists but with different prices** Problem Statement You are given two lists. Each of which index contains the name of the item and its price. The problem statement asks to count items common to both the lists but with different prices, which is to find out how many numbers of items are common in both ...

**Question 86. OSI Model** This model was developed in 1983 by the International Standards Organization (ISO). This was the first step taken to standardized the international protocols used in various layers. As it deals with connecting open systems, that is, systems that are open for communication with other systems, the model is called the ...

**Question 87. Find Nth Node** Problem Statement In the “Find Nth Node” problem we have given a linked list to find the nth node. The program should print the data value in the nth node. N is the input integer index. Example 3 1 2 3 4 5 6 3 Approach Given a linked list ...

**Question 88. Delete Last Occurrence** Problem Statement In the “Delete Last Occurrence” problem we have given a linked list. Write a program to delete the last occurrence of a given key from the linked list. The list can contain duplicates. Example 1 2 3 5 2 10 1 2 3 5 2 Approach Given a ...