Monthly Archives: November 2012

Diameter of a binary tree

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { public class Node { private Node left; private Node right; private int value; public Node(Node left, Node right, int value) { this.left = left; this.right = right; … Continue reading

Posted in Information Technology | Leave a comment

Distance between two given nodes in a binary tree

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { public class Node { private Node left; private Node right; private int value; public Node(Node left, Node right, int value) { this.left = left; this.right = right; … Continue reading

Posted in Information Technology | Leave a comment

Transforming a matrix to 0 through clicks on non-zero elements

There will be a 1000×1000 matrix containing numbers 1,2,3,4 in random positions. A user can click on a cell with a non-zero number. On clicking the cells containing that number, all the cells adjacent to that cell containing that number … Continue reading

Posted in Information Technology | Leave a comment

Printing nodes at a specified distance from a given node in a generic tree

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { public class Node { private Node left; private Node right; private int value; public Node(Node left, Node right, int value) { this.left = left; this.right = right; … Continue reading

Posted in Information Technology | Leave a comment

Printing nodes at a specified distance from a given node in a generic tree matrix

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string sourceNode = "a"; int distance = 2; string[] digits = { "a", "b", "c", "d", "e", "f", "g" … Continue reading

Posted in Information Technology | Leave a comment

Maximum circular subarray sum

Given n numbers (both +ve and -ve), arranged in a circle, fnd the maximum sum of consecutive number. Examples: Input: a[] = {8, -8, 9, -9, 10, -11, 12} Output: 22 (12 + 8 – 8 + 9 – 9 … Continue reading

Posted in Information Technology | Leave a comment

Merging unsorted overlapping intervals

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] numArray = {6, 9, 10, 12, 8, 10, 0, 5 }; //Sort the array based on starting point … Continue reading

Posted in Information Technology | Leave a comment