Esempio n. 1
0
        public void TestMultipleBatches()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Col1");
            dt.Columns.Add("Col2", typeof(int));

            dt.Rows.Add("Fish", 123);
            dt.Rows.Add("Fish", 123);


            DataTable dt2 = new DataTable();

            dt2.Columns.Add("Col1");
            dt2.Columns.Add("Col2", typeof(int));

            dt2.Rows.Add("Fish", 123);
            dt2.Rows.Add("Haddock", 123);


            var remover = new RemoveDuplicates();

            //send it the batch with the duplication it will return 1 row
            Assert.AreEqual(1, remover.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count);

            //now send it the second batch which contains 2 records, one duplication against first batch and one new one, expect only 1 row to come back
            Assert.AreEqual(1, remover.ProcessPipelineData(dt2, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count);
        }
Esempio n. 2
0
        public void Excution1Test()
        {
            var func = new RemoveDuplicates();

            Assert.AreEqual(2, func.Excution1(new int[] { 1, 1, 2 }));
            Assert.AreEqual(5, func.Excution1(new int[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 }));
        }
Esempio n. 3
0
        public void TestRemovingDuplicatesFromDataTable()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Col1");
            dt.Columns.Add("Col2", typeof(int));

            dt.Rows.Add("Fish", 123);
            dt.Rows.Add("Fish", 123);
            dt.Rows.Add("Fish", 123);

            Assert.AreEqual(3, dt.Rows.Count);


            Assert.AreEqual(123, dt.Rows[0]["Col2"]);

            var receiver = new ToMemoryDataLoadEventListener(true);

            var result = new RemoveDuplicates().ProcessPipelineData(dt, receiver, new GracefulCancellationToken());

            //should have told us that it processed 3 rows
            Assert.AreEqual(3, receiver.LastProgressRecieivedByTaskName["Evaluating For Duplicates"].Progress.Value);

            //and discarded 2 of them as duplicates
            Assert.AreEqual(2, receiver.LastProgressRecieivedByTaskName["Discarding Duplicates"].Progress.Value);

            Assert.AreEqual(1, result.Rows.Count);
            Assert.AreEqual("Fish", result.Rows[0]["Col1"]);
            Assert.AreEqual(123, result.Rows[0]["Col2"]);
        }
Esempio n. 4
0
        public void RemoveDuplicatesTest()
        {
            var input  = Node.BuildNodeListOne();
            var result = RemoveDuplicates.Run(input);

            Assert.Equal("53146", TestHelpers.ToString(result));
        }
Esempio n. 5
0
        public void FindDuplicateSuccess()
        {
            var input = new int[] { 2, 3, 3, 3, 6, 9, 9 };

            var result = RemoveDuplicates.Remove(input);

            Assert.Equal(result, 4);
        }
    //public int SearchMoviesCount(string title)
    //{
    //    return SearchMovies(title).Count();
    //}
    public IEnumerable <Movie> GetMoviesList()
    {
        //var movies = GetMovies().Where(s => s.Title.ToLower().Contains(title));
        var movies  = GetMovies();
        var results = RemoveDuplicates.RemoveDuplicatesMovies(movies.ToList());

        return(results.ToList());//.Distinct(new RemoveDuplicates());
    }
Esempio n. 7
0
        public void RemoveDuplicatesSolution()
        {
            var nums = new[] { 0, 0, 1, 1, 1, 2, 2, 3, 3, 4 };

            var testClass = new RemoveDuplicates();
            var res       = testClass.Solution(nums);

            Assert.AreEqual(5, res);
        }
Esempio n. 8
0
        /// <summary>
        /// Makes the current batch ONLY distinct.  This only works if you have a bounded batch (see OrderByAndDistinctInMemory)
        /// </summary>
        /// <param name="chunk"></param>
        /// <param name="listener"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private DataTable MakeDistinct(DataTable chunk, IDataLoadEventListener listener, GracefulCancellationToken cancellationToken)
        {
            var removeDuplicates = new RemoveDuplicates()
            {
                NoLogging = true
            };

            return(removeDuplicates.ProcessPipelineData(chunk, listener, cancellationToken));
        }
        public IEnumerable <Movie> SortMovies(int?skip = null, int?take = null, string sortColumn = null, SortDirection sortDirection = SortDirection.Ascending)
        {
            var movies = GetMovies();

            var          results = RemoveDuplicates.RemoveDuplicatesMovies(movies.ToList());
            List <Movie> obj     = CodingChallenge.Utilities.StringComparer.CreateSortList <Movie>(results, sortColumn, sortDirection);

            return(obj.Skip(skip.Value).Take(take.Value));
        }
Esempio n. 10
0
        public void TestDuplicateRemoval()
        {
            var ll = new LinkedList <int>();

            ll.Push(1).Push(1).Push(2).Push(2).Push(3).Push(3).Push(4).Push(4);

            var uniqueLl = RemoveDuplicates <int> .Go(ll);

            Assert.Equal("1 -> 2 -> 3 -> 4 -> <null>", uniqueLl.ToString());
        }
Esempio n. 11
0
        public void Solution1Test(int[] nums, int[] expected)
        {
            var result = RemoveDuplicates.Solution1(nums);

            Assert.Equal(expected.Length, result);
            for (var i = 0; i < expected.Length; i++)
            {
                Assert.Equal(expected[i], nums[i]);
            }
        }
Esempio n. 12
0
        public void MissingInputs()
        {
            RemoveDuplicates t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();
            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual(0, t.Filtered.Length);
        }
Esempio n. 13
0
        public void MissingInputs()
        {
            var t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();
            bool success = t.Execute();

            Assert.True(success);
            Assert.Empty(t.Filtered);
            Assert.False(t.HadAnyDuplicates);
        }
Esempio n. 14
0
        public void RemoveDuplicates_RemoveDuplicatesFromStringUsingDefaultMethod_DuplicatesRemoved()
        {
            // Arrange
            var startingString = "AABBCC,ABC,D";
            var expectedString = "ABC,D";

            // Act
            var result = RemoveDuplicates.RemoveDuplicatesFromString(startingString);

            // Assert
            Assert.AreEqual(expectedString, result);
        }
        public IEnumerable <Movie> SearchMovies(string title, int?skip = null, int?take = null, string sortColumn = null, SortDirection sortDirection = SortDirection.Ascending)
        {
            //var movies = GetMovies().Where(s => s.Title.ToLower().Contains(title));
            var movies = GetMovies().Where(x => x.Title.ToLower().Contains(title));

            if (skip.HasValue && take.HasValue)
            {
                movies = movies.Skip(skip.Value).Take(take.Value);
            }
            var results = RemoveDuplicates.RemoveDuplicatesMovies(movies.ToList());

            return(results.ToList());//.Distinct(new RemoveDuplicates());
        }
Esempio n. 16
0
        public void TwoItemsTheSame()
        {
            RemoveDuplicates t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            t.Inputs = new ITaskItem[] { new TaskItem("MyFile.txt"), new TaskItem("MyFile.txt") };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal("MyFile.txt", t.Filtered[0].ItemSpec);
        }
Esempio n. 17
0
        public void CaseInsensitive()
        {
            RemoveDuplicates t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            t.Inputs = new ITaskItem[] { new TaskItem("MyFile.txt"), new TaskItem("MyFIle.tXt") };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual("MyFile.txt", t.Filtered[0].ItemSpec);
        }
Esempio n. 18
0
        public void OneItemNop()
        {
            var t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            t.Inputs = new[] { new TaskItem("MyFile.txt") };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Single(t.Filtered);
            Assert.Equal("MyFile.txt", t.Filtered[0].ItemSpec);
            Assert.False(t.HadAnyDuplicates);
        }
Esempio n. 19
0
        public void CaseInsensitive()
        {
            var t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            t.Inputs = new[] { new TaskItem("MyFile.txt"), new TaskItem("MyFIle.tXt") };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal(1, t.Filtered.Length);
            Assert.Equal("MyFile.txt", t.Filtered[0].ItemSpec);
            Assert.True(t.HadAnyDuplicates);
        }
Esempio n. 20
0
        public void SimpleTest_SingleRemoval()
        {
            //Given
            var nums = new int[3] {
                1, 1, 2
            };

            //When
            var result = new RemoveDuplicates().Go(nums);

            //Then
            Assert.Equal(2, result);
            Assert.Equal(nums[0], 1);
            Assert.Equal(nums[1], 2);
        }
Esempio n. 21
0
        public void TwoItemsDifferent()
        {
            var t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            t.Inputs = new[] { new TaskItem("MyFile1.txt"), new TaskItem("MyFile2.txt") };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal(2, t.Filtered.Length);
            Assert.Equal("MyFile1.txt", t.Filtered[0].ItemSpec);
            Assert.Equal("MyFile2.txt", t.Filtered[1].ItemSpec);
            Assert.False(t.HadAnyDuplicates);
        }
Esempio n. 22
0
        public void SimpleTest_MultipleRemoval()
        {
            //Given
            var nums = new int[10] {
                0, 0, 1, 1, 1, 2, 2, 3, 3, 4
            };

            //When
            var result = new RemoveDuplicates().Go(nums);

            //Then
            Assert.Equal(5, result);
            Assert.Equal(nums[0], 0);
            Assert.Equal(nums[1], 1);
            Assert.Equal(nums[2], 2);
            Assert.Equal(nums[3], 3);
            Assert.Equal(nums[4], 4);
        }
Esempio n. 23
0
        public void RemoveDuplicatesFromUnsortedArray()
        {
            // Arrange
            int[] unsorted = { 9, 3, 3, 0, 1, -1, 4, 3 };
            int[] expected = { 9, 3, 0, 1, -1, 4 };

            // Act
            int[] actual = RemoveDuplicates <int> .Unsorted(unsorted);

            // Assert
            int e = 0; // expected index

            foreach (int a in actual)
            {
                Assert.AreEqual(expected[e], a);
                e++;
            }
        }
Esempio n. 24
0
        public void RemoveDuplicatesFromSortedArray()
        {
            // Arrange
            int[] sorted   = { -1, 2, 2, 2, 3, 4, 5, 6, 6, 6, 9 };
            int[] expected = { -1, 2, 3, 4, 5, 6, 9 };

            // Act
            int[] actual = RemoveDuplicates <int> .Sorted(sorted);

            // Assert
            int e = 0;

            foreach (int a in actual)
            {
                Assert.AreEqual(expected[e], a);
                e++;
            }
        }
Esempio n. 25
0
        public void TestNulls()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Col1");
            dt.Columns.Add("Col2", typeof(int));

            dt.Rows.Add("Fish", 123);
            dt.Rows.Add("Fish", null);
            dt.Rows.Add(null, 123);
            dt.Rows.Add("Pizza", null);
            dt.Rows.Add(null, null);
            dt.Rows.Add(null, null);

            var remover = new RemoveDuplicates();

            Assert.AreEqual(6, dt.Rows.Count);

            //send it the batch with the duplication it will return 5 rows (the only duplicate is the double null)
            Assert.AreEqual(5, remover.ProcessPipelineData(dt, new ThrowImmediatelyDataLoadEventListener(), new GracefulCancellationToken()).Rows.Count);
        }
Esempio n. 26
0
        public void OrderPreservedNoDups()
        {
            var t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            // intentionally not sorted to catch an invalid implementation that sorts before
            // de-duping.
            t.Inputs = new[]
            {
                new TaskItem("MyFile2.txt"),
                new TaskItem("MyFile1.txt"),
                new TaskItem("MyFile3.txt")
            };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal(3, t.Filtered.Length);
            Assert.Equal("MyFile2.txt", t.Filtered[0].ItemSpec);
            Assert.Equal("MyFile1.txt", t.Filtered[1].ItemSpec);
            Assert.Equal("MyFile3.txt", t.Filtered[2].ItemSpec);
        }
Esempio n. 27
0
        public void OrderPreservedDups()
        {
            var t = new RemoveDuplicates();

            t.BuildEngine = new MockEngine();

            t.Inputs = new[]
            {
                new TaskItem("MyFile2.txt"),
                new TaskItem("MyFile1.txt"),
                new TaskItem("MyFile2.txt"),
                new TaskItem("MyFile3.txt"),
                new TaskItem("MyFile1.txt")
            };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal(3, t.Filtered.Length);
            Assert.Equal("MyFile2.txt", t.Filtered[0].ItemSpec);
            Assert.Equal("MyFile1.txt", t.Filtered[1].ItemSpec);
            Assert.Equal("MyFile3.txt", t.Filtered[2].ItemSpec);
        }
Esempio n. 28
0
        private static void TestRemoveDuplicates()
        {
            RemoveDuplicates instance = new RemoveDuplicates();

            Console.WriteLine(instance.Solution(new[] { 1, 1, 1, 1 }));
        }
Esempio n. 29
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();
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            var sumList = PairSum.FindAPairsSumThatMatchesTarget(new List <int>()
            {
                1, 2, 3, 4, 6
            }, 6);

            Console.WriteLine($"Sum List [{sumList[0]}, {sumList[1]}]");

            Console.WriteLine();

            var sumListAlt = PairSum.FindAPairsAltSolution(new List <int>()
            {
                1, 2, 3, 4, 6
            }, 6);

            Console.WriteLine($"Sum List Alt [{sumList[0]}, {sumList[1]}]");

            Console.WriteLine();

            var removeDups = RemoveDuplicates.RemoveAllDuplicateNumbers(new List <int>()
            {
                2, 2, 2, 11
            });

            Console.WriteLine($"Length after Dups have been removed: {removeDups}");

            Console.WriteLine();

            var removeDupsEducativeVersion = RemoveDuplicates.RemoveAllDupsWithArray(new int[] { 2, 3, 3, 3, 6, 9, 9 });

            Console.WriteLine($"Length after Dups have been removed: {removeDupsEducativeVersion}");

            Console.WriteLine();

            var easySquares = SquareArray.GenerateListOfSquaresEasy(new List <int>()
            {
                -2, -1, 0, 2, 3
            });

            Console.Write($"[ ");

            foreach (var number in easySquares)
            {
                Console.Write($"{number} ");
            }

            Console.Write($"]");

            Console.WriteLine();

            var squares = SquareArray.GenerateArrayOfSquares(new int[] { -2, -1, 0, 2, 3 });

            Console.Write($"[ ");

            foreach (var number in squares)
            {
                Console.Write($"{number} ");
            }

            Console.Write($"]");

            Console.WriteLine();

            var listSquares = SquareArray.GenerateListOfSquares(new List <int>()
            {
                -2, -1, 0, 2, 3
            });

            Console.Write($"[ ");

            foreach (var number in listSquares)
            {
                Console.Write($"{number} ");
            }

            Console.Write($"]");

            Console.WriteLine();

            var triplets = TripletsToZero.FindUniqueTripletsThatEqualZero(new List <int>()
            {
                -3, 0, 1, 2, -1, 1, -2
            });

            foreach (var list in triplets)
            {
                Console.Write($"Triplet: ");
                foreach (var number in list)
                {
                    Console.Write($"{number} ");
                }
                Console.WriteLine();
            }

            Console.WriteLine();

            var closestToTarget = TripletSum.FindTripletSumClosestToTarget(new List <int>()
            {
                1, 0, 1, 1
            }, 100);

            Console.WriteLine($"Closest: {closestToTarget}");

            Console.WriteLine();

            var searchTriplet = TripletSum.SearchTriplet(new int[] { 1, 0, 1, 1 }, 100);

            Console.WriteLine($"Educative Closest: {searchTriplet}");

            Console.WriteLine();

            var tripletCount = CountTriplets.CountTripletsThatHasASumLessThanTarget(new List <int>()
            {
                -1, 4, 2, 1, 3
            }, 5);

            Console.WriteLine($"Triplets Less than target: {tripletCount}");

            Console.WriteLine();

            var productsList = ProductLessThanTarget.FindProductsLessThanTarget(new List <int>()
            {
                8, 2, 6, 5
            }, 50);

            Console.WriteLine($"Product List: ");
            foreach (var list in productsList)
            {
                Console.Write(" [");
                foreach (var number in list)
                {
                    Console.Write($"{number} ");
                }
                Console.Write("] ");
            }

            Console.WriteLine();

            var productsEducative = ProductLessThanTarget.FindProductEducative(new int[] { 8, 2, 2, 5 }, 50);

            Console.WriteLine($"Product List: ");

            foreach (var list in productsEducative)
            {
                Console.Write(" [");
                foreach (var number in list)
                {
                    Console.Write($"{number} ");
                }
                Console.Write("] ");
            }

            Console.WriteLine();

            var dutchFlag = DutchFlag.SortInPlace(new List <int>()
            {
                2, 2, 0, 1, 2, 0
            });

            Console.WriteLine("DutchFlag = ");

            foreach (var number in dutchFlag)
            {
                Console.Write($"{number} ");
            }

            Console.WriteLine();

            var quad = QaudSum.ListOfQuads(new List <int>()
            {
                4, 1, 2, -1, 1, -3, 28, -26
            }, 1);

            Console.WriteLine("Quad List: ");
            foreach (var list in quad)
            {
                Console.Write($"[");

                foreach (var number in list)
                {
                    Console.Write($"{number} ");
                }
                Console.Write("]");
            }

            Console.WriteLine();
        }