Nearest number with non-decreasing digits

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

8 queens problem

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

Flip all zeros to ones

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

Sum of all nodes at a vertical level

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

Vertical distance of a Node from root

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

Max value node between two elements of BST

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

Check if a subtree exist with a given sum

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

Reversing a linked list iteratively using only 2 pointers

Given a linked list, write the non-recursive function to reverse the list. If Input list is 1 -> 2 -> 3 -> 4 -> 5 Then […]

Rotten Oranges Problem

Given a Matrix of order M*N, where each cell can have zero or one orange. The orange in the cell (if present) can be either […]

Recursive function to add 5 to alternate nodes of the linked list

Write a recursive function that add 5 to the alternate nodes of the linked list. For example, if the list is 1 -> 2 -> […]