Monday, August 17, 2015

Hackerrank : Caeser Cipher in C#

//caeser cipher
int n = Convert.ToInt32(Console.ReadLine());

string s = Console.ReadLine();

int offset = Convert.ToInt32(Console.ReadLine());

char[] final = new char[n];

for (int i = 0; i < n; i++)

//bool ischar = false;

bool isSmall = false;

int curchar = (int)s[i];

if(curchar >= 97 && curchar <= 122)

isSmall = true;

curchar = curchar - 32;

if (curchar >= 65 && curchar <= 90)

int newChar = curchar + offset;

while(newChar >90)

{ newChar = newChar - 26; }
final[i] = isSmall ? (char)(newChar + 32) : (char)(newChar);




final[i] = s[i];



Find if 2 strings are anagram or not

/* find if 2 strings are anagram or not like silent and listen*/
string str1 = Console.ReadLine();
string str2 = Console.ReadLine();
bool isAnagram = true;
int strLen = str1.Length;
int[] arr = new int[256];
if(strLen == str2.Length)
for (int i = 0; i < strLen; i++)
foreach (int i in arr)
if (i > 0)
isAnagram = false;
isAnagram = false;

Linked list: Pairwise swap

private static void SwapEveryTwoNodes(LinkedList l)
            if (l == null || l.head == null)
            Node cur = l.head;
            Node next =;
            Node pre = null;
            if (cur == null || next == null)
            l.head =;
            //in every iteration, there should be minimum 3 pointer change. Before next iteration begins,
            //ensure that the pointer to previos node is saved.           
            while (cur != null && next != null)
                // cur =1, next = 2
       =; //
       = cur; //
                if(pre!=null) // this check is only for first iteration
           = next; //connect the left side of the LL with the swapped nodes
                pre = cur; //Save previous step
                cur =; //next odd numbered node
                next = cur!=null?; //next even numbered node              

Monday, April 8, 2013

Unrecognized configuration section system.web.extensions when upgrading to ASP.NET 4.0

Recently I upgraded my solution to VS 2010. My solution contained almost 30 projects. After upgrading when I ran the solution for the first time I got following error:

Unrecognized configuration section system.web.extensions when upgrading to ASP.NET 4.0

After some googling it was certain that the error was due to upgrade but I could not find exact solution. Then I opened my machine.config file (located at C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Config).
It had the "system.web.extensions" section. Suddenly I noticed that the entire text in the machine.config was in small letters(system.web.extensions) whereas in my projects' we.config, the first letter of every word was in capital letters. (System.Web.Extensions). When I changed my web.config to small case, the solution worked.

One complete day wasted on such small silly thing!!!!

Thursday, May 31, 2012

Find if backup file is complete or not

Frequently we get back up files from our clients to resolve their issues. But sometimes by the time the backup file reaches us, it gets corrupted either while creating the back up or while compressing or while uploading to ftp site or while downloading from the ftp site.
When we try to restore such file, we may get different error messages.

One message that I got recently was: Specified cast is not valid. (SqlManagerUI)

One very good way to find out if the backup file is incomplete is to execute following command


It will show something like the below message which implies that the backup is not complete:

Monday, December 12, 2011

How to Archive SQL error Logs

To create a new error log, execute following:

1. Restart the sql server service. It will create a new error log
2. Execute following:
Exec ('DBCC ErrorLog')
3. Execute following:
Exec Sp_Cycle_Errorlog

Tuesday, April 19, 2011

To find what caused a postback

Sometimes there could be multiple controls on UI and it may be difficult to figure out which control caused the postback while debugging.

1. On aspx/ascx page use following:


2. on a class file use following: