# Fourkites Interview Questions

## Fourkites Array Questions

Question 1. 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 2. Group Multiple Occurrence of Array Elements Ordered by first Occurrence You are given a question in which you have given an unsorted array with multiple occurrences of numbers. The task is to group all the multiple occurrences of array elements ordered by first occurrence. Meanwhile, the order should be the same as the number comes. Example Input: [ 2, 3,4,3,1,3,2,4] ...

Question 3. 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 4. 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 5. Find Largest d in Array such that a + b + c = d Problem Statement Suppose you have an array of integers. Input values are all distinct elements. The problem “Find largest d in array such that a + b + c = d” asks to find out the largest element ‘d’ in the set such that a + b + c = ...

Question 6. 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 7. Maximum Consecutive Numbers Present in an Array Problem Statement Suppose you have an array of integers of size N. The problem “Maximum consecutive numbers present in an array” asks to find out the maximum count of consecutive numbers that could be scattered in an array. Example arr[] = {2, 24, 30, 26, 99, 25} 3 Explanation: The ...

Question 8. Maximize Elements Using Another Array Suppose, we have given two integers array of same size n. Both of the arrays contain positive numbers. The problem statement asks to maximize the first array by using the second array element keeping the second array as a priority (elements of the second array should appear first in output). ...

Question 9. 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 10. Maximum sum of pairs with specific difference The problem “Maximum sum of pairs with specific difference” states that you are given an array of integers and an integer K. Then we are asked to find out the maximum sum of independent pairs. We can pair two integers if they have an absolute difference of less than K. ...

Question 11. Difference between highest and least frequencies in an array The problem “Difference between highest and least frequencies in an array” states that suppose that you have an integer array. The problem statement asks to find out the maximum difference between the highest frequency and lowest frequency of two distinct numbers in an array. Example arr[] = {1, 2, 3, ...

Question 12. 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 13. Find maximum difference between nearest left and right smaller elements Problem Statement Given an array a[ ] of size n. The problem “Find maximum difference between nearest left and right smaller elements” asks us to create a function. Such that it creates two arrays left[ ] and right[ ] representing nearest smaller element to the left and nearest smaller element ...

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. Rearrange array such that even index elements are smaller and odd index elements are greater Problem Statement You have given an array of integers. The problem “Rearrange array such that even index elements are smaller and odd index elements are greater” asks to rearrange the array in such a manner that the even index elements should be smaller than the odd index elements in a ...

Question 16. 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 17. Maximum sum bitonic subarray Problem Statement An array having n integers is given to us. We need to find the maximum sum bitonic subarray. A bitonic subarray is nothing but just a subarray where the elements are arranged in a specific order. Such that the first elements are in increasing order and then in ...

Question 18. Find minimum number of merge operations to make an array palindrome Problem Statement You are given an array of integers. The problem statement asks to find minimum number of merge operations to make an array palindrome, i.e. find out the minimum number of merging operations to be done on the array to make it a palindrome. Merging operation simply means that ...

Question 19. 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 20. 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 21. How to Efficiently Implement k Stacks in a Single Array? Design and implement a new data structure that Implement k Stacks in a Single Array. The new data structure must support these two operations – push (element, stack_number): that pushes the element in a given number of the stack. pop (stack_number): that pop out the top element from a given ...

Question 22. Number of NGEs to the Right In the Number of NGEs to the right problem we have given an array a[ ] of size n and q number of queries representing the index of the array. For each query, i print the total number of next greater elements to it’s right. Example Input a[ ] = ...

Question 23. Change the Array into Permutation of Numbers From 1 to N In this problem, we have given an array A of n elements. We need to change the array into a permutation of numbers from 1 to n using minimum replacements in the array. Example Input: 2 2 3 3 Output: 2 1 3 4 Input : 3 2 1 7 ...

Question 24. 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 ...

## Fourkites String Questions

Question 25. Remove brackets from an algebraic string containing + and – operators Problem Statement You are given a string s of size n representing an arithmetic expression with parenthesis. The problem “Remove brackets from an algebraic string containing + and – operators” asks us to create a function that can simplify the given expression. Example s = "a-(b+c)" a-b-c  s = a-(b-c-(d+e))-f a-b+c+d+e-f ...

Question 26. Reverse a String using Stack We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input  s = “TutorialCup” Output  puClairotuT Input s = “Stack” Output kcatS Using Stack ...

Question 27. Check length of a String is Equal to the Number Appended at its Last Problem Statement In the “Check length of a string is Equal to the Number Appended at its Last” problem we have given a string that is appended with a number at last. Write a program that checks whether the length of the string excluding the number is the same as ...

Question 28. Minimum Characters to be Removed to Make a Binary String Alternate Problem Statement Given a binary string, write a program that will find the minimum number of characters that can be removed from this string so that it becomes alternate. A binary string is said to be alternate if there are no consecutive 0’s or 1’s Input Format The first line ...

## Fourkites Tree Questions

Question 29. Morris Traversal Morris traversal is a method to traverse the nodes in a binary tree without using stack and recursion. Thus reducing the space complexity to linear. Inorder Traversal Example 9 7 1 6 4 5 3 1           /    \         2    ...

Question 30. 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 31. Iterative Method to find Height of Binary Tree Problem Statement The problem “Iterative Method to find Height of Binary Tree” states that you are given a binary tree, find the height of the tree using the iterative method. Examples Input 3 Input 4 Algorithm for Iterative Method to find Height of Binary Tree The height of a tree ...

Question 32. Check if all levels of two Binary Tree are anagrams or not Problem Statement The problem “Check if all levels of two Binary Tree are anagrams or not” says that you are given two Binary Trees, check if all the levels of the two trees are anagrams or not. Examples Input true Input false Algorithm to Check if all levels of two ...

Question 33. 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 34. Iterative method to find ancestors of a given binary tree Problem Statement “Iterative method to find ancestors of a given binary tree” problem states that you are given a binary tree and an integer representing a key. Create a function to print all the ancestors of the given key using iteration. Example Input  key = 6 5 2 1 Explanation: ...

Question 35. Check for Identical BSTs without building the trees Problem Statement “Check for identical BSTs without building the trees” problem states that you are given two arrays that represent some nodes. So we create BSTs from both of the arrays now we need to tell if the BSTs created from these arrays will be identical or not? The catch ...

Question 36. Print Ancestors of a Given Binary Tree Node Without Recursion Given a binary tree and a specific node or key. Print ancestors of a given binary tree node without recursion. Example Input : key = 7 Output : 3 1 Input : key = 4 Output : 2 1 Algorithm for Ancestors of a Given Binary Tree Node Create a class Node ...

Question 37. Binary Search Tree A binary search tree is a Binary tree with some rules that allows us to maintain the data in a sorted fashion. As it is a binary tree hence, a node can have at max 2 children. Structure of a Binary Search Tree node   Rules for Binary tree to ...

## Fourkites Graph Questions

Question 38. Find the smallest binary digit multiple of given number Problem Statement The problem “Find the smallest binary digit multiple of given number” states that you are given a decimal number N. So find the smallest multiple of N that contains only the binary digits ‘0’ and ‘1’. Example 37 111 A detailed explanation can be found below in the ...

Question 39. 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 40. 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 ...

## Fourkites Stack Questions

Question 41. Find maximum difference between nearest left and right smaller elements Problem Statement Given an array a[ ] of size n. The problem “Find maximum difference between nearest left and right smaller elements” asks us to create a function. Such that it creates two arrays left[ ] and right[ ] representing nearest smaller element to the left and nearest smaller element ...

Question 42. Remove brackets from an algebraic string containing + and – operators Problem Statement You are given a string s of size n representing an arithmetic expression with parenthesis. The problem “Remove brackets from an algebraic string containing + and – operators” asks us to create a function that can simplify the given expression. Example s = "a-(b+c)" a-b-c  s = a-(b-c-(d+e))-f a-b+c+d+e-f ...

Question 43. Implement a stack using single queue Problem Statement The problem “Implement a stack using single queue” asks us to implement a stack (LIFO) data structure using a queue (FIFO) data structure. Here LIFO means Last In First Out while FIFO means First In First Out. Example push(10) push(20) top() pop() push(30) pop() top() Top : 20 ...

Question 44. 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 45. Stack Permutations (Check if an array is stack permutation of other) Problem Statement The problem “Stack Permutations (Check if an array is stack permutation of other)” states that you are given two arrays a[ ] and b[ ] of size n. All the elements of the array are unique. Create a function to check if the given array b[ ] is ...

Question 46. 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 47. Iterative method to find ancestors of a given binary tree Problem Statement “Iterative method to find ancestors of a given binary tree” problem states that you are given a binary tree and an integer representing a key. Create a function to print all the ancestors of the given key using iteration. Example Input  key = 6 5 2 1 Explanation: ...

Question 48. 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 49. Print Ancestors of a Given Binary Tree Node Without Recursion Given a binary tree and a specific node or key. Print ancestors of a given binary tree node without recursion. Example Input : key = 7 Output : 3 1 Input : key = 4 Output : 2 1 Algorithm for Ancestors of a Given Binary Tree Node Create a class Node ...

Question 50. 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 51. 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 52. How to Implement Stack Using Priority Queue or Heap? Implement a stack with the help of a priority queue or a heap. Priority Queue : Priority queue data structure is similar to the queue or stack data structure with an addition of priority. Every element is given a priority number. In conclusion, the elements with high priority are prefered ...

Question 53. How to Efficiently Implement k Stacks in a Single Array? Design and implement a new data structure that Implement k Stacks in a Single Array. The new data structure must support these two operations – push (element, stack_number): that pushes the element in a given number of the stack. pop (stack_number): that pop out the top element from a given ...

Question 54. Find Maximum Sum Possible Equal Sum of Three Stacks Given 3 arrays stack1[ ], stack2[ ] and stack3[ ] representing stacks and the starting index of these arrays are treated as their top. Find the common maximum sum possible in all the three stacks i.e. the sum of elements of stack1, stack2 and stack3 are equal. Removal of the ...

Question 55. Reverse a String using Stack We have given a string s of length n which contains lower case letters, upper case letters, integers, and some special symbol. Reverse the given string using stack. Let’s see some examples for better understanding. Example Input  s = “TutorialCup” Output  puClairotuT Input s = “Stack” Output kcatS Using Stack ...

Question 56. Number of NGEs to the Right In the Number of NGEs to the right problem we have given an array a[ ] of size n and q number of queries representing the index of the array. For each query, i print the total number of next greater elements to it’s right. Example Input a[ ] = ...

Question 57. 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 ...

## Fourkites Queue Questions

Question 58. 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 59. Iterative Method to find Height of Binary Tree Problem Statement The problem “Iterative Method to find Height of Binary Tree” states that you are given a binary tree, find the height of the tree using the iterative method. Examples Input 3 Input 4 Algorithm for Iterative Method to find Height of Binary Tree The height of a tree ...

Question 60. Implement a stack using single queue Problem Statement The problem “Implement a stack using single queue” asks us to implement a stack (LIFO) data structure using a queue (FIFO) data structure. Here LIFO means Last In First Out while FIFO means First In First Out. Example push(10) push(20) top() pop() push(30) pop() top() Top : 20 ...

Question 61. Check if all levels of two Binary Tree are anagrams or not Problem Statement The problem “Check if all levels of two Binary Tree are anagrams or not” says that you are given two Binary Trees, check if all the levels of the two trees are anagrams or not. Examples Input true Input false Algorithm to Check if all levels of two ...

Question 62. Stack Permutations (Check if an array is stack permutation of other) Problem Statement The problem “Stack Permutations (Check if an array is stack permutation of other)” states that you are given two arrays a[ ] and b[ ] of size n. All the elements of the array are unique. Create a function to check if the given array b[ ] is ...

Question 63. How to Implement Stack Using Priority Queue or Heap? Implement a stack with the help of a priority queue or a heap. Priority Queue : Priority queue data structure is similar to the queue or stack data structure with an addition of priority. Every element is given a priority number. In conclusion, the elements with high priority are prefered ...

Question 64. Priority Queue in C++ FIFO manner is used to implement a queue. In a queue, insertions are done at one end (rear) and deletion takes place at another end (front). Basically, the element enters first is deleted first. We implement a priority queue using c++ inbuilt functions. Characteristics of Priority Queue A priority queue ...

## Fourkites Other Questions

Question 65. Find postorder traversal of BST from preorder traversal Problem Statement The problem “Find postorder traversal of BST from preorder traversal” states that you are given preorder traversal of a binary search tree. Then using the given input find the postorder traversal. Example preorder traversal sequence: 5 2 1 3 4 7 6 8 9 1 4 3 2 ...

Question 66. 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 67. Data Structure Designing Listening to Data Structure Designing, A lot of people might want to run away looking at the title itself. Those who know me know that I am not leaving until I explain the concept entirely. Embark with me on a journey to learn a problem and a few ideas on ...

Question 68. Top K Frequent Words In top K frequent words problem, we have given a list of words and an integer k. Print k most frequently used strings in the list. Example Input : list = {“code”, “sky”, “pen”, “sky”, “sky”, “blue”, “code”} k = 2 Output :  sky code Input : list = {“yes”, ...

Translate »