# Category: Beginner

## Euclidean algorithm – Greatest Common Divisor(GCD)

The greatest common divisor (GCD) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the...

## Delete X Nodes After Y Nodes In a Linked List

Objective: Given a Linked List and x and y. Delete x number of nodes after y nodes from the start. Example: ->10->20->30->40->50->60->70->80->90->100->110->120 Deleted 4 Nodes after 5 Nodes ->10->20->30->40->50->100->110->120 Approach: We need two pointers....

## Depth First Search/Traversal in Binary Tree

Objective: – Given a Binary Search Tree, Do the Depth First Search/Traversal . Appraoch: Approach is quite simple, use Stack. First add the add root to the Stack. Pop out an element from Stack...

## Check if Array is Consecutive Integers

Objective: Given a array of unsorted numbers, check if all the numbers in the array are consecutive numbers. Examples: int [] arrA = {21,24,22,26,23,25}; – True (All the integers are consecutive from 21 to...

## Find intersection between Two Sorted Arrays.

Objective: Given two sorted arrays, Find intersection point between them. Examples: int[] a = { 1, 2, 3, 6, 8, 10 }; int[] b = { 4, 5, 6, 11, 15, 20 }; Output:...

## Given a binary tree, Convert it into its Mirror Tree

Objective: Given a binary tree, Convert it into its Mirror Tree Mirror Tree: Mirror Tree of a binary tree is where left and right child of every node of given binary tree is interexchanged....

## Given a binary tree, Print All the Nodes that don’t have Siblings.

Objective: Given a binary tree, Print All the Nodes that don’t have siblings. Note: sibling node is the node which has the same parent, so you need to print the nodes who is a...

## Check if Two BST’s are Identical

Objective: Given Two binary Search Trees, Check if both are identical. Input: Two binary Search Trees Approach:

## Find all common numbers in given three sorted arrays.

Objective: Given three sorted(ascending order) arrays of integers, find out all the common elements in them. Input: Three sorted arrays. Output: All the common elements. Examples : Array A = {1,2,3,4,5,6,7,8,9,10}; Array B =...

## Minimum number that cannot be formed by any subset of an array

Objective: Given a sorted array of positive integers, find out the smallest integer which cannot be represented as the sum of any subset of the array Input: A Sorted Array Output: The smallest number...

## Find the Size of the Binary Tree

Objective: Given a Binary tree, Find the size of the tree. Note : Size of the tree is number of nodes in the tree Input: A Binary Tree. Output: Size of the tree. Example...

## Find the Maximum Depth OR Height of a Binary Tree

Objective: Given a binary tree, find the height of it Input: A Binary Tree Output: Height of a binary tree Example: Approach:

## Binary Search Tree (BST) Complete Implementation.

Binary Tree : A data structure in which we have nodes containing data and two references to other nodes, one on the left and one on the right. Binary Tree consist of Nodes Nodes...

## Reverse a Linked List – Part 2

This post is the extension of our earlier post Reverse a linked list. Here We have provided the better recursive solution in which we start reversing the list from the end. Objective: Reverse the...

## Delete a Node in the Middle of a linked list, Given only access to that Node

Objective: Write a program to Delete a Node in the Middle of a linked list, Given only access to that Node Example: Original List : ->1->2->8->3->7->0->4 After Deleting the mid node (say 7) :...