Add sum of all previous elements in array (DPFCI_1.2)

This question is from exercise in my book Dynamic Programming for Coding Interviews (Question: 1.2, Page-5) Question: Given an array, arr of integers, write a […]

Merge two sorted arrays

Given two sorted arrays of size m and n respectively. Also given an empty third array of size (m+n). write code to merge the two […]

Convert a Binary Tree to a Doubly Linked List

The structure of Node of a Binary Tree and Doubly linked list are same. struct Node { int data; Node* left; Node* right; }  Structure […]

Maximum XOR value of two elements

Given an array of numbers find the maximum XOR value of two numbers in the array. Input Array = {12, 15, 5, 1, 7, 9, […]

Print all words in a Trie data structure

Given a collection of words stored in a Trie data structure, write a function that print all the words stored in it. For example, If […]

Trie data structure

String matching is a big research area and there are many data structure (eg. B-Tree, HashMap, Set) that help indexing of strings. There are also many algorithms […]

Longest consecutive path in a Binary tree

Given a Binary tree, write code to find the length of longest path such that value of node in that path are consecutive and in decreasing […]

Rectangles in a matrix

Given a character matrix in which some of the cells have alphabets written on them while other cells are empty (empty cells contains character ‘-‘ […]

Sum of rectangle region in a given matrix

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 […]

Putting blocks at largest distance from each other in a row

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 […]