Close

## Minimum coin change problem

Given a set of denominations and an amount, how do we minimize the number of coins to make up the given amount? Let us consider the set of denominations {1,3,4}. Also assume that we have infinite supply of coins for each denomination. To make change for 6, we can have three combinations {1,1,4} {1,1,1,3} {3,3}…

## Valera and Plates – Code forces (Round #216) problem

In this post, we discuss a simple implementation problem from the recently concluded Code forces programming round. The problem description is given below. Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat…

## Maximum numbers in a sliding window

Given an array of N values and a value K, Write a program to print the maximum of all the sliding windows (sub-array) of size K. For example let us consider the following array as input  [4, 5, 3, 2, 6, 1, 2, 3, 8, 4] Let as take the sliding window of size 3.…

## Inserting an element into sorted linked list

Given a sorted linked list write a program to insert data into it’s correct position.  For example consider the following linked list 1 -> 3 -> 4 -> 5  Inserting 2 should change the list to 1 -> 2 -> 3 -> 4 -> 5 Inserting 0 should change it to 0 -> 1 ->…

## Finding K-size sub array with minimum sum

Given an array of size N and a number K. We have to find the sub-array of size K such that the sum of it’s elements is minimum among all K-size sub arrays. For example Let us consider the following array of size 10.  {1, 2, 1, 3, 1, 1, 1, 4, 2, 3} The…

## Number of bits to change from one number to other

Given two numbers, calculate the number of bits required to change from one number to the other. For example 12 in binary can be represented as 1100. 15 is represented as 1111. We need to change two bits to convert one number from the other as the last two bits are different. We can find…

## Pair swapping in a linked list

Given a singly linked list, we have to swap the adjacent nodes in it. For example some input/output samples are given below Input                              output ————————————————- 1->2->3->4->X                      2->1->4->3->X 1->2->3->4->5->X      …

## Printing the prime factorization of a given number

How do we write a program to find the prime factorization of a given number? For example prime factorization for 18 can written as 2 * 3 * 3 or 2 * 3 ^ 2. For any number there is only one possible prime factorization.  An efficient algorithm can be given as follows. we run…

## constant pointers and pointer to constant

In this post we talk a little bit about the constant pointers and pointer to a constant and the difference between them. In C programming, pointer is a crucial concept and it is always good to have a clear understanding of the fundamentals. Constant pointers: Constant pointer as the name indicates is a pointer whose…

## Reverse a single linked list

Given a singly linked list, how do we reverse it by re-arranging the links? For example if the given linked list is  1 -> 2 -> 3 -> NULL. The output of reverse method should be 3 -> 2 -> 1 -> NULL. The following diagram shows the simple steps to perform the reversal. And…