# Category Archives: Data Structures

This category is for logical grouping only. It needn’t to be added directly. Instead, the sub-categories should be added.

## Minimum cost to colour a Tree with no 3 adjacent vertices having same colour

Given a tree with N nodes value from 0 to (N – 1) and a 2D array arr[][] of size dimensions 3xN, where arr[i][j] denotes… Read More »

## Build a DFA to accept Binary strings that starts or ends with “01”

Given a binary string str, the task is to build a DFA that accepts the string if the string either starts with “01” or ends… Read More »

## Maximum difference of count of black and white vertices in a path containing vertex V

Given a Tree with N vertices and N – 1 edges where the vertices are numbered from 0 to N – 1, and a vertex… Read More »

## Count of elements to be inserted to make Array sum twice the XOR of Array

Given an array arr[] of size N, the task is to find the minimum number of elements that need to be inserted into the array… Read More »

## Sort numbers based on count of letters required to represent them in words

Given an array arr[] containing N non-negative integers, the task is to sort these integers according to the sum of the number of letters required… Read More »

## How to validate MAC address using Regular Expression

Given a string str, the task is to check whether the given string is valid MAC address or not by using Regular Expression. A valid… Read More »

## How to validate GUID (Globally Unique Identifier) using Regular Expression

Given a string str, the task is to check whether the given string is valid GUID (Globally Unique Identifier) or not by using Regular Expression.… Read More »

## Find parent of given node in a Binary Tree with given postorder traversal

Given two integers N and K where N denotes the height of a binary tree, the task is to find the parent of the node… Read More »

## Sort permutation of N natural numbers using triple cyclic right swaps

Given an array arr[] of size N which contains the permutations of the N natural numbers, the task is to sort the permutations of N… Read More »

## Find GCD of each subtree of a given node in an N-ary Tree for Q queries

Given an N-ary Tree containing N nodes, values associated with each node and Q queries, where each query contains a single node. The task is… Read More »

## Maximum number of set bits count in a K-size substring of a Binary String

Given a binary string S of size N and an integer K. The task is to find the maximum number of set bit appears in… Read More »

## Minimum count of numbers required from given array to represent S

Given an integer S and an array arr[], the task is to find the minimum number of elements whose sum is S, such that any… Read More »

## Minimize the cost to make all the adjacent elements distinct in an Array

Given two integer arrays arr[] and cost[] of size N, the task is to make all adjacent elements distinct at minimum cost. cost[i] denotes the… Read More »

## Maximize product of same-indexed elements of same size subsequences

Given two integer arrays a[] and b[], the task is to find the maximum possible product of the same indexed elements of two equal length… Read More »

## Maximum absolute difference between any two level sum in a Binary Tree

Given a Binary Tree having positive and negative nodes, the task is to find the maximum absolute difference of level sum in it. Examples: Input:… Read More »