Given a character matrix in which some of the cells have alphabets written on them while other cells are empty (empty cells contains character ‘-‘ in them). For example consider the below matrix: A – – – B – – – C All characters are unique. Set character on all empty cells in such a […]

Given a matrix of integers of order M*N and coordinates of a rectangular region in the matrix, write code to find the sum of all the elements in that rectangular region. For example, if the input matrix is And co-ordinated given are (3,4) and (6, 8), then they represent the below rectangular region whose Sum […]

Given a row (linear), two blocks are placed at each end and there are n empty positions between then. If ‘B’ represent block and n = 9 then the row looks like below: B _ _ _ _ _ _ _ _ _ B One blocks can be placed on each empty position. k blocks […]

Given a number N given in the form of array, with each index storing one digit of the number. Write code to change the number to the greatest number less than N, such that digits of that number are in non-decreasing order. For example: INPUT ARRAY: {1, 4, 3} (representing number 143) OUTPUT : 139 […]

This problem is to place 8 queens on the chess board so that they do not check each other. It can be asked in two ways: Find one of the possible solutions to place 8-queens, so that no queen can attack any other. How many different ways are possible to place 8 queens such that no […]

Given a string of bits and a number k. In one flip, you can toggle k consecutive characters, how many flips are required to change the entire string to all ones. For example Input String: 0000110000 k: 3 OUTPUT: 4 Following are the four flips: FLIP-1: 1110110000 FLIP-2: 1110110111 FLIP-3: 1111000111 FLIP-4: 1111111111 If it is not possible […]

Given a binary tree and a number n representing the vertical level. Write code to compute the sum of all nodes which are at vertical level n. For example, if the binary tree given is as below: and n=-1, then the output should be 12. Because Nodes at level =1 are 7 and 5 and […]

Given a Binary Tree and a Node, Write a function that return the vertical distance of that node from root of the tree. The vertical distance of a node is computed as below: Then the vertical distance of root is 0. The vertical distance of right node is distance of root+1. The vertical distance of […]

Given an array of integers that represent values of nodes in a Binary Search Tree. For example, If the given array is {9, 4, 17, 6, 5, 3, 7, 22, 20} Then BST created from above array will be as below Two numbers are given (along with the array), find largest number in the path […]

Given a binary tree and a Number N, write code to check if there exist a subtree of the Binary tree with sum of all the nodes = N. For example, if the Binary tree is as given on the right: And N = 12, then the output should be ‘true’ because there exist a […]