Posts

Collecting Candies Problem

Image
  Problem Description Question:-  Krishna loves candies a lot, so whenever he gets them, he stores them so that he can eat them later whenever he wants to. He has recently received N boxes of candies each containing Ci candies where Ci represents the total number of candies in the ith box. Krishna wants to store them in a single box. The only constraint is that he can choose any two boxes and store their joint contents in an empty box only. Assume that there are an infinite number of empty boxes available. At a time he can pick up any two boxes for transferring and if both the boxes contain X and Y number of candies respectively, then it takes him exactly X+Y seconds of time. As he is too eager to collect all of them he has approached you to tell him the minimum time in which all the candies can be collected. Input Format: The first line of input is the number of test case T Each test case is comprised of two inputs The first input of a test case is the number of boxes N The s...

Stair case problem

Image
  Problem Description There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time. Count the number of ways, the person can reach the top.  Coding in c: #include  <stdio.h> int calc(int n);   int count(int x);   int main () {   int n ;   printf("Enter number of stairs : ");   scanf("%d", &n);   printf("Number of ways = %d", count(n));   getchar();   return 0; } int count(int x) { return calc(x + 1); } int calc(int n) {    if (n <= 1)   return n;    return calc(n-1) + calc(n-2); } Output: Enter number of stairs : 7 Number of ways = 21