Reverse Linked List

Reverse a singly linked list. Example: Input: 1->2->3->4->5 Output: 5->4->3->2->1 Implementation: // C# program for reversing the linked list class ReverseLinkedlist { static void Main(string[] args) { LinkedList list = new LinkedList(); list.AddNode(new LinkedList.Node(80)); list.AddNode(new LinkedList.Node(50)); list.AddNode(new LinkedList.Node(40)); list.AddNode(new LinkedList.Node(20)); list.AddNode(new LinkedList.Node(100)); // List before reversal Console.WriteLine(“Given linked list:”); list.PrintList(); // Reverse the list list.ReverseList(); […]

Read More

Longest Common Prefix

Write a program to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string ” “. Example 1: Input: [“geeksblood”, “geeks”, “geek”] Output: “geek” Example 2: Input: [“abc”,”xyz”,”pqr”] Output: “” Explanation: There is no common prefix among the input strings. Implementation: class Program { […]

Read More

Balanced Brackets

Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered […]

Read More

Differentaite between Hashtable and Dictionary

Hashtable and Dictionary are collection of data structures to hold data as key-value pairs. Dictionary is generic type, hash table is not a generic type. The Hashtable is a weakly typed data structure, so you can add keys and values of any Object Type to the Hashtable. The Dictionary class is a strongly types < […]

Read More