Wednesday, 10 June 2015

If a method throws NullPointerException in super class, can we override it with a method which throws RuntimeException?

Sunday, 10 May 2015

Try to Convey for Palindrome! ! ! ! !

given a string, characters can be shuffled to make a palindrome. !
What is the minimum possible number of insertions to original string needed so that it will be a palindrome (after shuffling, if required).

Input

T -> number of test cases
T number of Strings in different lines

import java.util.Arrays;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Xsquare{
 public static void main (String[] args) throws Exception{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  int limit = Integer.parseInt(br.readLine());
  
  int [] alphabets = new int[26];
  
  while(limit-- >;0){
   String input = br.readLine();
   Arrays.fill(alphabets,0);
   char [] inpChar = input.toCharArray();
   int sum = 0;
   
   for (int i=0;i<input.length();i++){
     int pos = (int)inpChar[i] - (int)'a';
     alphabets[pos]+=1;
   }
   
   for(int i=0;i<;26;i++){
    if(alphabets[i]%2==0)
     sum+=0;
    else
     sum+=1; 
   }
   
   if(sum<=0)
    sum=0;
   else 
    sum-=1;
   System.out.println(sum);
  }
 }
}

Wednesday, 11 March 2015

MaxiMizing XOR

Problem Statement
Given two integers, L and R, find the maximal values of A xor B, where Aand B satisfy the following condition:
LABR
Input Format
The input contains two lines; L is present in the first line and R in the second line.
Constraints 
1LR103
Output Format
The maximal value as mentioned in the problem statement.
Sample Input
10
15
Sample Output
7
Explanation
The input tells us that L=10 and R=15. All the pairs which comply to above condition are the following: 
1010=0 
1011=1 
1012=6 
1013=7 
1014=4 
1015=5 
1111=0 
1112=7 
1113=6 
1114=5 
1115=4 
1212=0 
1213=1 
1214=2 
1215=3 
1313=0 
1314=3 
1315=2 
1414=0 
1415=1 
1515=0 
Here two pairs (10, 13) and (11, 12) have maximum xor value 7, and this is the answer.
/*code written by Sudhakar Pandey */
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>

int maxXor(int l, int r) {
    int i,j,max=0,p=0;
    for(i=l;i<=r;i++)
        {
         for(j=i;j<=r;j++)
             {
               p=i^j;
               if(p>max)
                 max=p;  
         }
    }

 return max;
}
int main() {
    int res;
    int l;
    scanf("%d", &l);
    
    int r;
    scanf("%d", &r);
    
    res = maxXor(l, r);
    printf("%d", res);
    
    return 0;
}