Posts

Showing posts with the label interview

Interview questions

1) What are constraints? These are used to constraint(limit) the data that can go into SQL tables There are generally six types of constraints in SQL: NOT NULL Constraint - Check Constraint - Default Constarint - Primary Key Constraint - Unique Key Constraint - Foreign Key Constraint - 2) What are ACID properties? ACID stands for Atomicity, Consistency, Isolation and Durability. Database professionals when evaluating the database, looks at these features of database. Atomicity: Each transaction is said to be atomic. If one part of the transaction fails, entire transaction should fail. Its all or none rule. Consistency: Only valid data should be written into database. If a transaction is executed that violates the Database consistency rules then entire transaction should be rolled back. Database should not leave your transaction in half finished state. Isolation: Database should isolate two concurrent transactions until they are finished. Durability: Any transac...

Sorting - Bubble Sort

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AsscendingOrder { class Program { static void Main(string[] args) { int[] a = { 2,1,2,1,2,13,19,31,6}; for (int j = a.Length - 1; j > 0; j--) { for (int i = 0; i < j; i++) { if (a[i] > a[i + 1]) { int temp = a[i]; a[i] = a[i + 1]; a[i + 1] = temp; } } } for (int i = 0; i < a.Length; i++ ) Console.WriteLine(a[i]); Console.ReadLine(); } } }

Hex to Decimal

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HexToDec { class Program { static void Main(string[] args) { string hex = Console.ReadLine(); int Total = 0; //TBD: Need to check for other characters are entered for (int i = 0; i <= hex.Length - 1; i++) { switch (Convert.ToChar(hex[i].ToString().ToUpper())) { case 'A': Total = Total + 10*((Int32)Math.Pow(16,hex.Length-1-i)); break; case 'B': Total = Total + 11 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'C': Total = Total + 12 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'D': Total = Total + 13 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'E': Total = Total + 14 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; case 'F': Total = Total + 15 * ((Int32)Math.Pow(16, hex.Length - 1 - i)); break; default: Total = Total + Convert.ToInt32(hex[i].ToString()) * ((Int...

C# - Reference Example

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace reference { class Program { static void Main(string[] args) { int i = 5; Method(ref i); Console.WriteLine(i.ToString()); Console.ReadLine(); } static void Method(ref int j) { j = j + 7; } } }

string reverse

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace stringreverse { class Program { static void Main(string[] args) { string first; int j=0; Console.WriteLine("Enter the first string"); first = Console.ReadLine(); char[] firstArr = first.ToCharArray(); char[] secondArr = first.ToCharArray(); for (int i = first.Length - 1; i >= 0; i--) { secondArr[j] = firstArr[i]; j++; } Console.WriteLine(secondArr); Console.ReadLine(); } } }

First repeated character

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace FirstRepeatedCharacter1 { class Program { static void Main(string[] args) { Console.WriteLine("Enter the string"); string str = Console.ReadLine(); if (str == "") { Console.WriteLine("string is empty"); Console.ReadLine(); return; } bool repeated = false; Hashtable strhash = new Hashtable(); foreach (char ch in str) { if (strhash.ContainsValue(ch)) { Console.WriteLine("First non repeated character: " + ch); repeated = true; break; } else { strhash.Add((int)ch, ch); } } if (repeated == false) { Console.WriteLine("No repeated characters"); } Console.ReadLine(); } } }

Two strings are given, remove all occurrences or the characters in the second string from the first string

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace RemoveRepeatedCharacters { class Program { static void Main(string[] args) { Console.WriteLine("Enter the orirginal string"); string str = Console.ReadLine(); Console.WriteLine("Enter the characters to be removed string"); string rem = Console.ReadLine(); Hashtable remhash = new Hashtable(); foreach (char ch in rem) { if (!remhash.ContainsValue(ch)) { remhash.Add((int)ch, ch); } } string final = ""; foreach (char ch in str) { if (!remhash.ContainsValue(ch)) { final = final + ch; } } Console.WriteLine(final); Console.ReadLine(); } } }