Print all possible root-to-leaf paths in a binary tree

Given a Binary Tree, write code to print all root-to-leaf paths possible in the tree. For Example, For the Binary Tree given on the right […]

Number of nodes in a binary tree

Write a function which will return the total number of nodes in a Binary tree. For example, the Binary tree on the right has 7 […]

Kadane's Algorithm to find maximum subarray sum

Given an array of n integers (both +ve and -ve). Find the contiguous sub-array whose sum is maximum (More than 1 sub-array may have same […]

check if all nodes of a tree has only one child

Given the PreOrder traversal of a binary search tree (in the form of a tree), check if all the nodes (except the last) of the […]

Detecting loop in a linked list

Given a Singly linked list which may contain a loop (link of last node pointing to some Node in the list). Write code to detect […]

Searching in a linked list

Given a singly linked list, write a function which will search for a value in the list. Signature of the function will be as shown […]

How to delete a node in a linked list if only pointer to node is given?

Given a pointer to Node in a Singly linked list. Is it possible to delete the same node ?

Comparison of sorting algoritms

Which sorting algorithm makes minimum number of memory write ?

Majority Element of an Array (Moore's Algorithm)

An integer x in array arr of n elements is the majority element if and only if x appears more than n/2 times in A. […]

Print array in the forward and backward direction recursively

Write a recursive function which will print an array in forward and backward order (depending on a parameter). The signature of the function should be […]