Thursday, 13 August 2015

         MINIMUM DRAWS-HACKERRANK SOLUTION


Problem Statement
Jim is off to a party and is searching for a matching pair of socks. His drawer is filled with socks, each pair of a different color. In its worst case scenario, how many socks (x) should Jim remove from his drawer in the worst case scenario after which he finds a matching pair?
Input Format
The first line contains the number of test cases T.
Next T lines contains an integer N which indicates the total pairs of socks present in the drawer.
Output Format
Print the number of Draws (x) Jim makes in the worst case scenario.
Constraints
1T1000
0<N<106
Sample Input
2
1
2
Sample Output
2
3
 

SOLUTION : 

#include<iostream>
using namespace std;
int main()
{
int t,n,k;
cin>>t;
while(t--)
{
cin>>n;
k=n+1;
cout<<k<<endl;
}
return 0;
}

Monday, 23 March 2015

Lonely Integer : hacker rank

Hallo Readers!!!
i 've attached my code for the hackerrank problem the lonley integer from algorithm section
the following code was compiled under jre8 environment.


import java.util.*;
import java.io.*;

public class cli {

public static void main(String[] args) {
int[] x = new int[100];
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
   int result = 0;
   if(n%2==1)
   {
   for (int i=0;i<n;i++) {
    x[i]=sc.nextInt();
       result ^= x[i];
   }
   System.out.println("result:"+result);
   }

}

}