### metonym.in

Your friend for GRE words and Vocabulary. Find here

# C++

/C++

## Max Concatenate

By |October 15th, 2012|

Given 2 strings, return the max number that can be formed by joining them.
For example, if the strings are:
45 and 456
2 numbers are possible
45456
45645
The output should be
45645

Solution:
#include<stdio.h>
#include<string.h>
int main(int argc, char * argv[]){
int a, b,min,i;
char *st;

a= strlen(argv);
b= strlen(argv);
min= a < b ? a : b ;

for(i=0;i<min;i++){
if (argv < argv){
st=  strcat(argv,argv);

printf(“%s”,st);
return 0;

}
[…]

## Gravel

By |October 14th, 2012|

Bob has n heap(s) of gravel (initially there are exactly c piece(s) in each). He wants to do m operation(s) with that heaps, each maybe:

adding pieces of gravel onto the heaps from u to v, exactly k pieces for each,
or querying “how many pieces of gravel are there in the heap p now?”.

Request
Help Bob do […]

## Rectangles Counting

By |October 14th, 2012|

Given N separate integer points on the Cartesian plane satisfying: there is no any three of them sharing a same X-coordinate. Your task is to count the number of rectangles (whose edges parrallel to the axes) created from any four of given points.
Input
There are several test cases (ten at most), each formed as follows:

The first […]

## Number Game Revisited

By |October 14th, 2012|

Alice and Bob play the following game.They choose a number N to play with.The runs are as follows :

1.Bob plays first and the two players alternate.

2.In his/her turn ,a player can subtract from N any prime number(including 1) less than N.The number thus obtained is the new N.

3.The person who cannot make a move in […]

## Graphs in Euclidean Space

By |October 14th, 2012|

The Chef is a bit tired of graphs. He has spent far too many days calculating shortest paths, finding bipartite matchings, minimum cuts, and optimizing over NP-hard problems. He needs a break. Unfortunately for him, the food services industry doesn’t take breaks. Once again, the Chef has to navigate through an undirected graph to keep […]

## Generalized Independent Sets

By |October 14th, 2012|

Given a graph G on nodes V with undirected edges E, an independent set X is a subset of V such that no edge in E has both endpoints in X. Finding the size of the largest independent set in a graph is currently a very difficult problem.

Consider the following generalization of an independent set. […]

## Central Point (April 2011)

By |October 14th, 2012|

Given a set of N integer points on the Cartesian plane. Your task is to find an integer point satisfying its sum of distances to N given points (S) is minimum.
Input
There are several test cases (fifteen at most), each formed as follows:

The first line contains a positive integer N (N ≤ 2,000).
N lines follow, each […]

Gallery

## Call by address vs Call by reference in C++ (Most Relevant answer)

By |October 13th, 2012|

In call by address, instead of passing the actual values of the actual argument we pass addresses of actual values. Whenever we deal with addresses, we must know how to handle them. That’s why before discussing call by address, we will briefly discuss pointers that handle addresses.
Introduction to Pointers
We all know that the […]

## Pairs challenge in Interview street

By |October 7th, 2012|

Problem Statement

Given N numbers , we need to count the total pairs of numbers that have a difference of K.

Input Format:
1st line contains N & K (integers).
2nd line contains N numbers of the set. All the N numbers are assured

to be distinct.

Output Format:
One integer saying the no of pairs of numbers […]

## Median challenge in Interviewstreet

By |October 7th, 2012|

Problem Statement

The median of M numbers is defined as the middle number after sorting them in order, if M is odd or the average number of the middle 2 numbers (again after sorting) if M is even. Given an empty number list at first. Then you can add or remove some number from the list. […]

## String Similarity Interviewstreet

By |October 7th, 2012|

Problem Statement
String similarity of two strings is defined as length of longest prefix common to both strings. For example string similarity for abcd and abb is 2, length of ab. Calculate sum of similarities of a string with each of its suffixes.
Input: First line contains T, no of test cases and next T lines contain […]

## Flowers challenge interview street

By |October 7th, 2012|

Problem Statement

There are k friends who want to buy N flowers. Each flower has some cost ci. But there is condition that the price of flowers changes for customer who had bought flowers before. More precisely if a customer has already bought x flowers, he should pay (x+1)*ci dollars to buy flower number i. What […]