All Medium Articles

## Josephus problem | Set 1 (A O(n) Solution) 3.5

In computer science and mathematics, the Josephus Problem (or Josephus permutation) is a theoretical problem. Following is the problem statement: There are n people standing… Read More »

## Find the two numbers with odd occurrences in an unsorted array 3.4

Given an unsorted array that contains even number of occurrences for all numbers except two numbers. Find the two numbers which have odd occurrences in… Read More »

## Find the smallest positive number missing from an unsorted array | Set 1 3.5

My Personal Notes arrow_drop_up Save

## Cutting a Rod | DP-13 3.1

Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the… Read More »

## Longest Palindromic Subsequence | DP-12 3.4

Given a sequence, find the length of the longest palindromic subsequence in it. As another example, if the given sequence is “BBABCBCAB”, then the output… Read More »

## Hamiltonian Cycle | Backtracking-6 3.7

Hamiltonian Path in an undirected graph is a path that visits each vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a Hamiltonian Path… Read More »

## m Coloring Problem | Backtracking-5 3.5

Given an undirected graph and a number m, determine if the graph can be colored with at most m colors such that no two adjacent… Read More »

## Swap bits in a given number 3.8

Given a number x and two positions (from the right side) in the binary representation of x, write a function that swaps n bits at… Read More »

## Merge Two Balanced Binary Search Trees 3.3

You are given two balanced binary search trees e.g., AVL or Red Black Tree. Write a function that merges the two given balanced BSTs into… Read More »

## 0-1 Knapsack Problem | DP-10 3.3

Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.… Read More »

## Add two numbers without using arithmetic operators 3.6

Write a function Add() that returns sum of two integers. The function should not use any of the arithmetic operators (+, ++, –, -, ..… Read More »

## Operating Systems | Set 5 3

Following questions have been asked in GATE 2012 exam. 1. A process executes the code fork (); fork (); fork (); The total number of… Read More »

## AVL Tree | Set 2 (Deletion) 3.7

We have discussed AVL insertion in the previous post. In this post, we will follow a similar approach for deletion. Steps to follow for deletion.… Read More »

## Vertical Sum in a given Binary Tree | Set 1 3

Given a Binary Tree, find the vertical sum of the nodes that are in the same vertical line. Print all sums through different vertical lines.… Read More »

## AVL Tree | Set 1 (Insertion) 3.7

AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for… Read More »

## Complicated declarations in C 3.8

Most of the times declarations are simple to read, but it is hard to read some declarations which involve pointer to functions. For example, consider… Read More »

## Print all interleavings of given two strings 3.3

Given two strings str1 and str2, write a function that prints all interleavings of the given two strings. You may assume that all characters in… Read More »

## Print all permutations with repetition of characters 3.5

Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order… Read More »

## In-place conversion of Sorted DLL to Balanced BST 3.9

Given a Doubly Linked List which has data members sorted in ascending order. Construct a Balanced Binary Search Tree which has same data members as… Read More »

## Python Program for Matrix Chain Multiplication | DP-8 3

Given a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is not actually to perform the multiplications, but… Read More »