Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Print a new line after each string or number.

Here is C and C++ solutions [Read more…]

## Convert Decimal to Roman numbers / Romanizer HackerEarth Code

Set of Numbers are given to you.

convert them to Roman numbers.

Solution is in Hacker Earth style [Read more…]

## ‘N’ Story Building, with 1,2,3 steps how many ways can a person reach top of building.

A building has n steps. A person can take 1,2 or 3 steps. In how many ways can a person reach top of building.

In order to build logic, lets think from first step

If N=1 and Steps=1. There is only 1 way to reach with 1 step.

F(1)=1

If N=2 and Steps=1. There 1 way to reach with 1+1 step.

F(2)=1

if N=2 and Steps=1,2 . There are 2 ways to reach, with 1+1 & 0+2 steps.

F(2)=2

if N=3 and Steps=1,2 . There are 3 ways to reach, with 1+1+1 , 1+2 & 2+1 steps.

F(3)=3.

## The Magic HackerEarth Nirvana solutions Hiring Challenge

## Count Possible Decodings of a given Digit Sequence

1 2 3 = A B C

1 23 = A X

12 3 = L C

[Read more…]

## Find the number ABCD such that when multipled by 4 gives DCBA.

These problems can be tricky and/or tedious, but this one isn’t too bad.

**Method 1 ) Forming Equations and Solving them**

[Read more…]

## Puzzle : 100 doors in a row Visit and Toggle the door. What state the door will be after nth pass ?

## Possible sizes of bus to carry n groups of friends

## Find if two rectangles overlap

Note that a rectangle can be represented by two coordinates, top left and bottom right. So mainly we are given following four coordinates.

l1: Top Left coordinate of first rectangle.

r1: Bottom Right coordinate of first rectangle.

l2: Top Left coordinate of second rectangle.

r2: Bottom Right coordinate of second rectangle

Two rectangles do not overlap if one of the following conditions is true.

1) if l1.x > r2.x OR l2.x > r1.x // If one rectangle is on left side of other Case (3)

2) if l1.y < r2.y OR l2.y < r1.y // If one rectangle is above other Case(4) not presented here.

Case 1) and 2) are Overlapping.

hence here it should return false.

Code : Following code returns true if two rectangles overlap.

struct Coord

{

int x, y;

};

bool RectOverlap(Coord l1, Coord r1, Coord l2, Coord r2)

{

if (l1.x > r2.x || l2.x > r1.x) return false;

if (l1.y < r2.y || l2.y < r1.y) return false;

return true; //else in all condition

}

## Add Sub Multiply very large number stored as string

You need to add, subtract and multiply two numbers and store number in character array only.

Logic

1) First way to create a “long long”number from String and add/multiply/subtract.

And convert this result in to character array.2) keep numbers in Character array only and try to add/sub/multiply index wise.

See code for Add+Multiply

You can create for Subtract.

Thanks to Dhaval for suggesting this approach and Article

#include<stdio.h>

#include<math.h>

#include<stdlib.h>

#include<string.h>

#define MAX 10000

char * addition(char a[],char b[]){

static char add[MAX];

char c[MAX];

int temp;

int la,lb;

int i,j,k=0,x=0,y;

long int car=0;

long sum = 0;

la=strlen(a)-1;

lb=strlen(b)-1;

//printf(“n la=%d lb=%d “,la,lb);

for(i=0;i<=la;i++){ a[i] = a[i] – 48; }

for(i=0;i<=lb;i++){ b[i] = b[i] – 48; }

if(la>lb){

y=0;

k=la;

}

else{

k=lb;

y=1;

}

//printf(“nAddition called “);

for(i=la,j=lb;i>=0,j>=0;i–,j–){

//printf(“Addition called “);

c[k–]=(car+a[i]+b[j])%10;

car=(car+a[i]+b[j])/10;

}//for

printf(“nWithout carry %s”,c);

if(y=0){

j=0;

for(i=0;i<la+1;i++){

add[j++]=c[i] + 48;

}

add[j]=”;

}

else{

j=0;

for(i=0;i<lb+1;i++){

add[j++]=c[i] + 48;

}

add[j]=”;

}

return add;

}

char * multiply(char a[],char b[]){

static char mul[MAX];

char c[MAX];

char temp[MAX];

int la,lb;

int i,j,k=0,x=0,y;

long int r=0;

long sum = 0;

la=strlen(a)-1;

lb=strlen(b)-1;

for(i=0;i<=la;i++){

a[i] = a[i] – 48;

}

for(i=0;i<=lb;i++){

b[i] = b[i] – 48;

}

for(i=lb;i>=0;i–){

r=0;

for(j=la;j>=0;j–){

temp[k++] = (b[i]*a[j] + r)%10;

r = (b[i]*a[j]+r)/10;

}

temp[k++] = r;

x++;

for(y = 0;y<x;y++){

temp[k++] = 0;

}

}

k=0;

r=0;

for(i=0;i<la+lb+2;i++){

sum =0;

y=0;

for(j=1;j<=lb+1;j++){

if(i <= la+j){

sum = sum + temp[y+i];

}

y += j + la + 1;

}

c[k++] = (sum+r) %10;

r = (sum+r)/10;

}

c[k] = r;

j=0;

for(i=k-1;i>=0;i–){

mul[j++]=c[i] + 48;

}

mul[j]=”;

return mul;

}

int main(){

char a[MAX]={‘9′,’5′,’5′,’5′,’5’ };

char b[MAX]={‘3′,’3′,’3′,’3′,’3′,’3′,’3′,’3′,’3′,’3’};

char *c;

int la,lb;

//int i = 0;

int i = 1;

//int i = 2;

printf(“Answer of two numbers : “);

switch(i){

case 0: c = multiply(a,b); break;

case 1: c = addition(a,b); break;

//case 2: c = sub(a,b); break;

default: break;

}

//c = multiply(a,b);

printf(“%s”,c);

return 0;

}

You can view code at http://ideone.com/Kd2Rv1