Example #1
0
        public void MergeIntervalsSuccess()
        {
            int[][] input = new int[][]
            {
                new int[] { 1, 3 },
                new int[] { 2, 6 },
                new int[] { 8, 10 },
                new int[] { 15, 18 }
            };

            int[][] expectedResult = new int[][]
            {
                new int[] { 1, 6 },
                new int[] { 8, 10 },
                new int[] { 15, 18 }
            };



            var result = new MergeIntervals().Merge(input);

            var isEqual = ArrayEquivalence.sequencesEqual(result, expectedResult);


            Assert.IsTrue(isEqual);
        }
        public void Merge_WhenGivenTwoOverlappingIntervalsLCTestCase2_ReturnsCorrectResult()
        {
            // Arrange
            MergeIntervals mergeIntervals = new MergeIntervals();

            int[][] testArray = new int[10][];
            testArray[0] = new int[] { 5, 5 };
            testArray[1] = new int[] { 1, 3 };
            testArray[2] = new int[] { 3, 5 };
            testArray[3] = new int[] { 4, 6 };
            testArray[4] = new int[] { 1, 1 };
            testArray[5] = new int[] { 3, 3 };
            testArray[6] = new int[] { 5, 6 };
            testArray[7] = new int[] { 3, 3 };
            testArray[8] = new int[] { 2, 4 };
            testArray[9] = new int[] { 0, 0 };

            int[][] expected = new int[2][];
            expected[0] = new int[] { 0, 0 };
            expected[1] = new int[] { 1, 6 };

            // Act
            int[][] actual = mergeIntervals.Merge(testArray);

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0][0], actual[0][0]);
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("----------------------START ALGORITHM TESTS----------------------");

            SelectionSort.RunTests();
            InsertionSort.RunTests();
            Factorial.RunTests();
            Palindrome.RunTests();
            Recursion.RunTests();
            MergeSort.RunTests();
            QuickSort.RunTests();
            BreadthFirstSearch.RunTests();

            Console.WriteLine("----------------------END ALGORITHM TESTS----------------------");
            Console.WriteLine("----------------------START PATTERN TESTS----------------------");

            BFS.RunTests();
            DFS.RunTests();
            SlidingWindow.RunTests();
            TwoPointers.RunTests();

            FastSlowPointers.RunTests();
            MergeIntervals.RunTests();

            Console.WriteLine("----------------------END PATTERN TESTS----------------------");
        }
Example #4
0
 static void Main(string[] args)
 {
     Question1.Test();
     EvaluateReversePolishNotation.Test();
     MedianTwoSortedArrays.Test();
     StringSum.Test();
     LongestSubstringWithoutRepeatingChar.Test();
     CustomSort.Test();
     MergeIntervals.Test();
     RegexMatch.Test();
     StringToInt.Test();
 }
Example #5
0
        public void TestRandom()
        {
            MergeIntervals impl = new MergeIntervals();

            impl.Add(1, 3);
            impl.Add(2, 6);
            impl.Add(8, 9);

            int c = impl.Compute();

            Console.WriteLine("TestTotalOverlap:{0}", impl.Compute());
            Assert.AreEqual(6, c);
        }
Example #6
0
        public void TestNoOverlap()
        {
            MergeIntervals impl = new MergeIntervals();

            impl.Add(1, 3);
            impl.Add(5, 6);
            impl.Add(7, 9);
            impl.Add(10, 20);

            int c = impl.Compute();

            Console.WriteLine("TestNoOverlap:{0}", impl.Compute());
            Assert.AreEqual(15, c);
        }
        public void mergeIntervalsTest()
        {
            IList <Interval> result = MergeIntervals.Merge(inputIntervals);

            Console.WriteLine("Actual result: ");
            foreach (Interval interval in result)
            {
                Console.WriteLine("Start: " + interval.start + ", " + "End: " + interval.end);
            }
            Console.WriteLine("Expected result: ");
            foreach (Interval interval in outputIntervals)
            {
                Console.WriteLine("Start: " + interval.start + ", " + "End: " + interval.end);
            }
        }
        public void Merge_WhenGivenTwoOverlappingIntervalsLCTestCase_ReturnsCorrectResult()
        {
            // Arrange
            MergeIntervals mergeIntervals = new MergeIntervals();

            int[][] testArray = new int[2][];
            testArray[0] = new int[] { 1, 4 };
            testArray[1] = new int[] { 0, 4 };

            int[][] expected = new int[1][];
            expected[0] = new int[] { 0, 4 };

            // Act
            int[][] actual = mergeIntervals.Merge(testArray);

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0][0], actual[0][0]);
        }
Example #9
0
        public void TestOverlap()
        {
            int            c    = 0;
            MergeIntervals impl = new MergeIntervals();

            impl.Add(1, 3);
            impl.Add(5, 6);
            c = impl.Compute();
            Assert.AreEqual(3, c);
            impl.Add(2, 9);
            impl.Add(10, 20);
            c = impl.Compute();
            Assert.AreEqual(18, c);

            impl.Add(9, 10);
            c = impl.Compute();
            Console.WriteLine("TestOverlap:{0}", impl.Compute());
            Assert.AreEqual(19, c);
        }
        public void MergeTests()
        {
            MergeIntervals obj = new MergeIntervals();

            int[][] arr = new int[][]
            {
                new[] { 1, 3 },
                new[] { 2, 6 },
                new[] { 8, 10 },
                new[] { 15, 18 },
            };

            var x = obj.Merge(arr);

            arr = new int[][]
            {
                new[] { 1, 4 },
                new[] { 4, 5 }
            };

            x = obj.Merge(arr);

            arr = new int[][]
            {
                new[] { 1, 4 },
                new[] { 0, 4 }
            };

            x = obj.Merge(arr);


            arr = new int[][]
            {
                new[] { 1, 4 },
                new[] { 2, 3 }
            };

            x = obj.Merge(arr);
        }
        public void Merge_WhenGivenTwoOverlappingIntervals_ReturnsOne()
        {
            // Arrange
            MergeIntervals mergeIntervals = new MergeIntervals();

            int[][] testArray = new int[4][];
            testArray[0] = new int[] { 1, 3 };
            testArray[1] = new int[] { 2, 6 };
            testArray[2] = new int[] { 8, 10 };
            testArray[3] = new int[] { 15, 18 };

            int[][] expected = new int[3][];
            expected[0] = new int[] { 1, 6 };
            expected[1] = new int[] { 8, 10 };
            expected[2] = new int[] { 15, 18 };

            // Act
            int [][] actual = mergeIntervals.Merge(testArray);

            // Assert
            Assert.AreEqual(expected.Length, actual.Length);
            Assert.AreEqual(expected[0][0], actual[0][0]);
        }
Example #12
0
        public void Given_intervals_When_merge_Then_return()
        {
            List <Interval> intervals = new List <Interval>
            {
                new Interval(1, 3),
                new Interval(2, 6),
                new Interval(8, 10),
                new Interval(15, 18),
            };

            var result = MergeIntervals.Merge(intervals);

            Assert.AreEqual(3, result.Count);

            Assert.AreEqual(1, result[0].start);
            Assert.AreEqual(6, result[0].end);

            Assert.AreEqual(8, result[1].start);
            Assert.AreEqual(10, result[1].end);

            Assert.AreEqual(15, result[2].start);
            Assert.AreEqual(18, result[2].end);
        }
Example #13
0
        private static void ExistingCases()
        {
            Console.WriteLine("This is DB practice session..");
            Console.WriteLine("Press 1 for Binary search tree");
            Console.WriteLine("Press 2 for two sum problem");
            Console.WriteLine("Press 3 for Maximum Area Cake problem");
            Console.WriteLine("Press 4 for Find Inflection point.");
            Console.WriteLine("Press 5 for Max heap.");
            Console.WriteLine("Press 6 for Longest substring.");
            Console.WriteLine("Press 7 for Reverse linked list.");
            Console.WriteLine("Press 8 for Reverse linked list.");

            int option = 5;

            switch (option)
            {
            case 1:
                BinarySearchOperations();
                break;

            case 2:
                RandomProblems.TwoSumProblem();
                break;

            case 3:
                MaximumAreaCake.MaximumAreaCakeCaller();
                break;

            case 4:
                CodeFindInflectionPoint.FindInflectionPoint();
                break;

            case 5:
                MaxHeap.Test();
                break;

            case 6:
                LongestSubstring.Test();
                break;

            case 7:
                ReverseListSolution.Test();
                break;

            case 8:
                SlidingWindows.Test();
                break;

            case 9:
                SlowAndFastPointers.Tests();
                break;

            case 10:
                CyclicSort.Tests();
                break;

            case 11:
                FastAndSlowPointers.Tests();
                break;

            case 12:
                MergeIntervals.Tests();
                break;

            default:
                break;
            }
        }
Example #14
0
        static void Main(string[] args)
        {
            // StringProblems
            //Test calls for Reverse string
            string input = "jacob";

            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "jake";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));
            input = "jdshjdh@#$%^&)";
            Console.WriteLine(input + "<=>" + new string(SimpleProblem.ReverseString(input.ToCharArray())));

            ReplaceSpaces.TestReplaceSpacesInplace();
            Anagrams.TestIsAnagramAlgo();
            StringRotation.TestIsThisRotatedString();
            RemoveDuplicates.TestRemoveDuplicatesFromString();
            StringToLongConverter.TestStringToLong();
            RegexMatching.TestMatch();
            SumOfTwoNumbersInArray.TestSumOfTwoNumbersInArray();
            SumOfThreeNumbersInArray.TestSumOfThreeNumbersInArray();
            PairInSortedArrayClosestToAParticularValue.TestPairInSortedArrayClosestToAParticularValue();
            PalindromeInStringPermutation.TestPalindromeInStringPermutation();
            EditDistanceBetweenStrings.TestEditDistanceBetweenStrings();
            AnagramIsPalindrome.TestAnagramIsPalindrome();
            GreatestPalindrome.TestGreatestPalindrome();
            ReverseStringWithoutVowels.TestReverseStringWithoutVowels();
            LongestSubstringWithKDistinctChars.TestLongestSubstringWithKDistinctChars();
            // Pattern Matching
            NativePatternMatching.TestNativePatternMatching();
            KMPPatternMatching.TestKMPPatternMatching();
            BoyerMoorePatternMatching.TestPatternMatching();
            RabinKarp.TestRabinKarp();

            //Console.ReadLine();

            //Array Problems
            ArrayOfNumsIncrement.TestIncrementArrayOfNumbers();
            MajorityElement.TestFindMajorityElement();
            Merge2SortedArrays.TestMergeSortedArrays();
            MaxDistanceInArray.TestMaxDistanceInArray();
            MovingAverage.TestMovingAverage();
            TotalAverage.TestTotalAverage();
            ArrayWithGreaterElementToRight.TestArrayWithGreaterElementToRight();
            WaterCollectedInPuddleShownByHistogram.TestWaterCollectedInPuddleShownByHistogram();
            CountOfPairsWhichSumUpToGivenSum.TestCountOfPairsWhichSumUpToGivenSum();
            //Median.TestGetMedianOf2SortedArray();

            // Sorting Problems
            SelectionSort.TestSorting();
            BubbleSort.TestSorting();
            InsertionSort.TestSorting();
            ShellSort.TestSorting();
            MergeSort.TestMergeSort();
            QuickSort.TestQuickSort();
            HeapSortTester.TestHeapSort();
            CountingSort.TestSorting();
            RadixSort.TestRadixSort();
            DutchNationalFlag.TestDutchNationalFlag();
            SortedSquares.TestSortedSquares();

            // Matrix Problem
            Rotate_Matrix_90_degree.TestRotateMatrix();
            Matrix_Column_Rows_0.TestMakeRowColZero1();
            Matrix_Column_Rows_0.TestMakeRowColZero2();
            RotateMatrix180.TestRotateMatrix180();
            SumOfMatrixElementsFormedByRectangleWithCoordinates.TestSumOfMatrixElements();
            SortedArrayFromSortedMatrix.TestSortedArrayFromSortedMatrix();
            SearchWordInMatrix.TestSearchWordInMatrix();
            MaxOnesInRow.TestMaxOnesInRow();
            MatrixAsTriangle.TestMatrixAsTriangle();
            MinRangeInMatrix.TestMinRangeInMatrix();
            PrintMatrixAsSnake.TestPrintMatrixAsSnake();
            PrintMatrixInSpiral.TestPrintMatrixInSpiral();
            MaxSqAreaInBinaryMatrix.TestMaxRectAreaInBinaryMatrix();
            TicTacToeWinner.TestTicTacToeWinner();
            WaterfallCreation.TestWaterfallCreation();

            // Linked list Problems
            DeleteLinkedListNode.TestDeleteFirstNode();
            DeleteDuplicatesFromLinkedList.TestDeleteDuplicates();
            NthLastElementOfLinkedList.TestNthLastNodeOfLinkedList();
            DeleteNodeWithDirectReference.TestDeleteNode();
            AddNumbers.TestAddNumbersRepresentedByLinkedList();
            CopyLinkedListWithRandomNode.TestGetCopiedLinkedListWithRandomNode();
            CommonElementInTwoLinkedList.TestCommonElement();
            ReverseAdjacentNodesInLinkedList.TestReverseAdjacentNodes();
            MergeSortedLinkedList.TestMerge();
            CycleInLinkedList.TestStartOfCycleInLinkedList();
            MedianForCircularLinkedList.TestGetMedian();
            ReverseLinkedList.TestReverseLinkedList();
            SortedCircularLinkedList.TestCircularLinkedList();

            // stack and queue problem
            ThreeStackWithOneArray.TestThreeStackWithOneArray();
            StackWithMinElement.TestStackWithMinElement();
            StackOfPlates.TestStackOfPlates();
            SortAStack.TestSortAStackAscending();
            WellFormedExpression.TestWellFormedExpression();
            QueueVia2Stack.TestQueueVia2Stack();
            LRUCache.TestLRUCache();
            EvaluatePrefixNotation.TestGetPrefixNotationResult();
            EvaluateInflixNotation.TestGetInflixNotationResults();
            EvaluatePostfixNotation.TestGetPostfixNotationResult();
            TestCircularQueue.TestCircularQueueWithDifferentCases();
            LargestAreaInHistogram.TestLargestAreaInHistogram();
            TextEditerWithUndo.TestTextEditerWithUndo();

            //Recursion Problem
            TowerOfHanoi.TestTowerOfHanoi();
            MaxSumOfConsecutiveNums.TestMaxSumOfConsecutiveNums();

            // Back tracking problems
            Sudoku.TestSudokuSolver();
            HamiltonianCycle.TestHamiltonianCycle();
            GraphColoringWithMColors.TestGraphColoringWithMColors();
            MakeLargestIsland.TestMakeLargestIsland();

            //Misc Problem
            MinNumOfCoins.TestMinNumOfCoins();
            IsPrime.TestCheckPrime();
            SquareRoot.TestCalculateSquareRoot();
            CreditCardCheck.TestLuhnAlgo();
            ExcelFirstRowConversion.TestCovertExcelColumnToLong();
            Skyline.TestSkyline();
            SumOfSquaresWithoutMultiplication.TestSumOfSquares();
            MergeIntervals.TestMergeIntervals();
            WidthOfCalendar.TestWidthOfCalendar();
            JosephusProblem.TestJosephusProblem();

            // Permutation and Combination problem
            ShuffleAList.TestFisherYatesAlgo();
            CombinationsOfBinaryString.TestCombinationsOfBinaryString();
            AllCombinationsOfString.TestAllCombinationsOfString();
            AllPermutationsOfString.TestAllPermutationsOfString();
            PhoneNumberToWords.TestPhoneNumberToWords();
            AllNumbersInRangeWithDifferentDigits.TestAllNumbersInRangeWithDifferentDigits();
            DivideSetIntoTwoEqualSetsWithMinSumDiff.TestDivideSetIntoTwoEqualSetsWithMinSumDiff();
            PowerSet.TestPowerSet();
            AllCombinationsOfParenthesis.TestAllCombinationsOfParenthesis();
            GoodDiceRoll.TestGoodDiceRoll();
            PermutationsOfValidTime.TestPermutationsOfValidTime();

            // Tree Problems
            TreeFromExpression.TestCreateTreeFromExpression();
            TestBinarySearchTree.TestDifferentOperationsOnBST();
            AncestorOfTwoNodesInBST.TestAncestorOfTwoNodesInBST();
            CheckBTisBST.TestCheckBTisBST();
            MaxSumOnTreeBranch.TestMaxSum();
            WalkTheTree.TestWalkTheTree();
            SkewedBSTToCompleteBST.TestConvertSkewedBSTToCompleteBST();
            CheckIfTheTreeIsBalanced.TestIsTreeBalanced();
            LinkedListOfTreeNodesAtEachDepth.TestCreateLinkedListOfTreeNodesAtEachDepth();
            PrintBinaryTreeNodeAtEachLevel.TestPrintBinaryTreeNodeAtEachLevel();
            PrintBinaryTreeNodeAtEachLevelSpirally.TestPrintBinaryTreeNodeAtEachLevelSpirally();
            TreeSubtreeOfAnother.TestMatchTree();
            AncestorOfTwoNodesInBT.TestGetAncestorOfTwoNodesInBT();
            AncestorOfMultiNodesInBT.TestAncestorOfMultiNodesInBT();
            LinkedListFromLeavesOfBT.TestLinkedListFromLeavesOfBT();
            ExteriorOfBT.TestPrintExteriorOfBT();
            DepthOfTree.TestGetDepthOfTree();
            TreeToColumns.TestTreeToColumns();
            KthSmallestElementFromBST.TestKthSmallestElementFromBST();
            MakeBSTFromPreOrder.TestMakeBSTFromPreOrder();
            MirrorATree.TestMirrorATree();
            CloneABTWithRandPointer.TestCloneABTWithRandPointer();
            TreeWithInorderAndPreorder.TestTreeWithInorderAndPreorder();
            TreeWithInorderAndPostorder.TestTreeWithInorderAndPostorder();
            TreePathSumsToValue.TestTreePathSumsToValue();
            AllPathInNArayTree.TestAllPathInNArayTree();
            SerializeDeserializeBinaryTree.TestSerializeDeserializeBinaryTree();
            SerializeDeserializeAnNaryTree.TestSerializeDeserializeAnNaryTree();
            AncestorOfTwoNodesInNaryTree.TestAncestorOfTwoNodesInNaryTree();
            AbsOfMaxAndSecondMaxDepthInBT.TestGetAbsOfMaxAndSecondMaxDepthInBT();

            // Trie problems
            CreateAndSearchSimpleTrie.TestCreateAndSearchSimpleTrie();
            // ToDo: have a problem of suffix trees
            ShortestPrefix.TestGetShortestPrefixNotPresentInStringSet();

            // Dynamic Programming problems
            LongestCommonSubsequence.TestGetLongestCommonSubsequence();
            LongestPalindromeSubString.TestGetLongestPalindromeSubString();
            LongestPalindromicSubsequence.TestGetLongestPalindromicSubsequence();
            MaximumAs.TestGetMaximumAs();
            MinNumberOfJumps.TestGetMinimumNumberOfJumps();
            LongestCommonSubString.TestGetLongestCommonSubString();
            KnapSackProblem.TestGetTheMaximumValueWithLimitedWeight();
            TreeCuttingProblem.TestGetTreeCuttingToMaximizeProfits();
            WordBreaking.TestBreakTheWords();
            DistanceOfWords.TestDistanceOfWords();
            LongestIncreasingSubSequence.TestLongestIncreasingSubSequence();
            MinCostPath.TestMinCostPath();
            DifferentWaysForCoinChange.TestDifferentWaysForCoinChange();
            MatrixMultiplication.TestMatrixMultiplication();
            BinomialCoefficient.TestBinomialCoefficient();
            BoxStacking.TestBoxStacking();
            WordWrapping.TestWordWrapping();
            MaxSubMatrixWithAllOnes.TestMaxSubMatrixWithAllOnes();
            LongestSubStringWithEqualSum.TestLongestSubStringWithEqualSum();
            PartitionArrayIntoEqualSumSets.TestPartitionArrayIntoEqualSumSets();
            MaxSumRectangle.TestMaxSumRectangle();
            RegularExpressionMatch.TestRegularExpressionMatch();
            NumRepresentedByPerfectSquares.TestNumRepresentedByPerfectSquares();
            LongestCommonSubsequenceInSameString.TestLongestCommonSubsequenceInSameString();
            StringDecodeAsAlphabets.TestStringDecodeAsAlphabets();
            BalloonBursting.TestBalloonBursting();
            TravellingSalesmanProblem.TestTravellingSalesmanProblem();
            MaxSumWithoutAdjacentElements.TestMaxSumWithoutAdjacentElements();
            MaxPathThroughMatrix.TestMaxPathThroughMatrix();
            BrickLaying.TestBrickLaying();
            JobSchedullingWithConstraints.TestJobSchedullingWithConstraints();
            EggDropMinTrials.TestEggDropMinTrials();

            // Graph Problems
            ShortestPath.TestGetShortestPathBetween2Vertex();
            CycleInDirectedGraph.TestIsCycleInDirectedGraph();
            CycleInUnDirectedGraph.TestIsCycleInUnDirectedGraph();
            SolveAMaze.TestSolveAMaze();
            AllPathsGivenStartEndVertex.TestGetAllPathsInGraphFromStartVertexToEndVertex();
            AllPaths.TestGetAllPathsInGraphFromStartVertex();
            ColorVertices.TestColorVerticesWithDifferentColor();
            CheckBipartiteGraph.TestCheckBipartiteGraph();
            TransformOneWordToAnother.TestGetTransformation();
            ConstraintsVerification.TestConstraintsVerification();
            ExtendedContactsInSocialNetwork.TestComputeExtendedContacts();
            CourseScheduling.TestCourseScheduling();
            SnakeAndLadder.TestSnakeAndLadder();
            IsGraphATree.TestIsGraphATree();
            ReverseGraph.TestReverseGraph();
            StronglyConnectedGraph.TestStronglyConnectedGraph();
            ConnectedComponents.TestConnectedComponents();
            ContinentalDivide.TestContinentalDivide();
            CloneGraph.TestCloneGraph();
            Wordament.TestWordament();
            // ShortestPathAlgo
            FloydWarshall.TestFloydWarshall();
            DijkstraAlgorithm.TestDijkstraAlgorithm();
            BellmanFord.TestBellmanFord();
            TravelFromLeftToRightInMatrix.TestTravelFromLeftToRightInMatrix();
            HeuristicSearch.TestHeuristicSearch();
            AStar.TestAStar();
            ShortestPathWhenObstaclesRemoved.TestShortestPathWhenObstaclesRemoved();
            ShortestDistanceFromRoomsToGates.TestShortestDistanceFromRoomsToGates();
            //MaxFlow
            FordFulkersonEdmondKarp.TestFordFulkersonEdmondKarp();
            MinCut.TestMinCut();
            MaximumBipartiteMatching.TestMaximumBipartiteMatching();
            //Minimum Spanning Tree
            KruskalAlgorithm.TestKruskalAlgorithm();
            PrimsAlgorithm.TestPrimsAlgorithm();


            //Heap problems
            BasicMaxHeap.TestMaxHeap();
            BasicMinHeap.TestMinHeap();
            TestMinHeapMap.DoTest();
            TestPriorityQueue.Run();
            MedianForAStreamOfNumbers.TestMedianForAStreamOfNumbers();

            //DisjointSets
            TestingDisjointSet.Run();
            //TestWeightedDisjointSetsWithPathCompression.Run(); // this runs slow, hence commenting it

            //Geometry
            ClosestPairOfPoints.TestClosestPairOfPoints();
            RectangleIntersection.TestRectangleIntersection();
            LineSegmentIntersection.TestLineSegmentIntersection();
            ConvexHull.TestConvexHull();
            KClosestPointToOrigin.TestKClosestPointToOrigin();

            //Greedy Algorithm
            HuffmanCoding.TestHuffmanCoding();

            //Randomized Algorithm
            RandomGeneration.TestRandomGeneration();

            // Bit Algorithms
            IntHaveOppositeSigns.TestIntHaveOppositeSigns();
            Parity.TestParity();

            //Math Problem
            ZerosInFactorial.TestZerosInFactorial();
            GetAllPrimeFactors.TestGetAllPrimeFactors();
            NumberOfFactors.TestNumberOfFactors();
            AllFactors.TestAllFactors();
            MultiplyLongNumbers.TestMultiplyLongNumbers();
            NextLargestPermutation.TestNextLargestPermutation();
            AllPrimesTillN.TestAllPrimesTillN();
            PascalsTriangle.TestPascalsTriangle();
            SubtractLongNumbers.TestSubtractLongNumbers();

            //Search problems
            SearchInSortedRotatedArray.TestSearchInSortedRotatedArray();
            KClosestElementInArray.TestKClosestElementInArray();
            SearchInSortedMatrix.TestSearchInSortedMatrix();
            BinarySearchUnbounded.TestBinarySearchUnbounded();
            LinkedListSublistSearch.TestLinkedListSublistSearch();
            NoOfOccuranceInSortedArray.TestNoOfOccuranceInSortedArray();
            GetSmallestInSortedRotatedArray.TestGetSmallestInSortedRotatedArray();

            //Distributed algorithms
            KWayMerge.TestKWayMerge();


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            List <Interval> input1 = new List <Interval>();

            input1.Add(new Interval(7, 9));
            input1.Add(new Interval(1, 4));
            input1.Add(new Interval(2, 5));

            var merged1 = MergeIntervals.MergeIntervalsWithoutEnumerator(input1);

            foreach (var interval in merged1)
            {
                Console.Write($"[{interval.Start}, {interval.End}] ");
            }

            Console.WriteLine();

            List <Interval> input2 = new List <Interval>();

            input2.Add(new Interval(6, 7));
            input2.Add(new Interval(2, 4));
            input2.Add(new Interval(5, 9));

            var merged2 = MergeIntervals.MergeIntervalsWithoutEnumerator(input2);

            foreach (var interval in merged2)
            {
                Console.Write($"[{interval.Start}, {interval.End}] ");
            }

            Console.WriteLine();

            List <Interval> input3 = new List <Interval>();

            input3.Add(new Interval(1, 4));
            input3.Add(new Interval(2, 6));
            input3.Add(new Interval(3, 5));

            var merged3 = MergeIntervals.MergeIntervalsWithoutEnumerator(input3);

            foreach (var interval in merged3)
            {
                Console.Write($"[{interval.Start}, {interval.End}] ");
            }

            Console.WriteLine();
            Console.WriteLine();

            List <Interval> insertTest1 = new List <Interval>();

            insertTest1.Add(new Interval(1, 3));
            insertTest1.Add(new Interval(5, 7));
            insertTest1.Add(new Interval(8, 12));

            var insertMerge1 = MergeIntervals.InsertInterval(insertTest1, new Interval(4, 6));

            foreach (var interval in insertMerge1)
            {
                Console.Write($"[{interval.Start}, {interval.End}] ");
            }

            Console.WriteLine();

            var insertMerge2 = MergeIntervals.InsertInterval(insertTest1, new Interval(4, 10));

            foreach (var interval in insertMerge2)
            {
                Console.Write($"[{interval.Start}, {interval.End}] ");
            }

            Console.WriteLine();

            List <Interval> insertTest3 = new List <Interval>();

            insertTest3.Add(new Interval(2, 3));
            insertTest3.Add(new Interval(5, 7));

            var insertMerge3 = MergeIntervals.InsertInterval(insertTest3, new Interval(1, 4));

            foreach (var interval in insertMerge3)
            {
                Console.Write($"[{interval.Start}, {interval.End}] ");
            }

            Console.WriteLine();
        }
Example #16
0
 public void Setup()
 {
     solution = new MergeIntervals();
 }