Thursday, 9 May 2013

How to check if two strings are ANAGRAM's or not?

An Anagram is the rearrangement of the letters of a word into another word. 
For Ex: LISTEN and SILENT are Anagrams



SOLUTION 1;


sort both the Strings and compare them. if equal then they are said to be anagrams otherwise not.

sample code snippet in java:

.......
.......

String inputString1 = "SILENT";
String inputString2 = "LISTEN";

boolean checkWhetherAnagramorNot(String inputString1,String inputString2)

{


        char[] chars = inputString1.toCharArray();
        Arrays.sort(chars);
        String sorted1 = new String(chars);
        //System.out.println(sorted1);
        chars = inputString2.toCharArray();
        Arrays.sort(chars);
        String sorted2 = new String(chars);
        //System.out.println(sorted2);
      
         if(sorted1.equals(sorted2))
               return true;
         else
              return false;


}
.........

.........


SOLUTION 2:









Wednesday, 13 March 2013

difference between stored procedures and functions ?

-> Procedure can return zero or n values whereas function can return one datatype value.
-> Returning a value is optional in Stored Procedure where as it is mandatory w.r.to a function.
-> Functions can be called from  procedure whereas procedures cannot be called from function.
-> Procedures can have both input/output parameters for it whereas functions can have only input parameters.
-> Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
-> We can go for transaction management in procedure whereas we can't go in function.
-> Procedure allows select as well as DML(insert,delete,update) statement in it whereas function allows only select statement in it.

Monday, 11 March 2013

difference between truncate, delete and drop command in sql?

this is one of the most frequently asked question in interviews

The DELETE command is used to remove rows from a table and DELETE operation is temporary you need to either COMMIT or ROLLBACK the transaction to make the change permanent or to undo it. By using DELETE we can delete only selected rows as per our requirement.

TRUNCATE removes all rows from a table. The operation cannot be rolled back. TRUNCATE is faster and doesn't use as much undo space as a DELETE.
The DROP command removes a table and its related indexes and privileges from the database.The operation cannot be rolled back.
DELETE and TRUNCATE both are DML commands where as DROP is a DDL command.

Wednesday, 19 December 2012

What is the major difference b/w 32-bit and 64-bit processor ??

At any time processor can execute only one machine instruction, and that instruction length is 32 bits in 32-bit processor and 64 bits in 64-bit processor.

The memory addresses represented by a 32-bit processor is 2power32(2^32) where as 2power64(2^64) in case of 64-bit processor.since 64-bit processor has more memory address, it can even load entire program into memory and executes the program by reducing the overhead of Disk I/O cycles, thereby increasing the performance.

(if not entire program, 64-bit processor will have large "frame" size compared to 32-bit. so it can execute the program in less Disk I/O cycles) 

Cards Game Puzzle

Puzzle:- This puzzle is a game related one. Consider a game contains two participants(let is say player,comp) there are 21 cards in total and each participant can pick either 1 or 2 or 3 or 4 cards at a time. In every game first chance of picking cards is given to player and whoever takes the last card(here 21st card) will be the looser. solve the puzzle such that always comp should win the game.

Solution
if player picks x cards then computer should pick 5-x cards each round.
after four rounds 5*4 = 20 cards will be picked up then the player turn will come, as rule says he should pick atleast one card, so picks up the last card and looses the game.
this is the algorithm for which always computer will win the game.