Exemplo n.º 1
0
        public void ExecuteTest()
        {
            var strs     = new[] { "flower", "flow", "flight" };
            var expected = "fl";

            LongestCommonPrefix.Execute(strs).Should().Be(expected);
        }
Exemplo n.º 2
0
        public void StringsCanShareCommonPrefix()
        {
            var input = new[] { "aab", "aabcd" };
            var lcp   = new LongestCommonPrefix();

            Assert.Equal("aab", lcp.longestCommonPrefix(input));
        }
Exemplo n.º 3
0
        public void NoCommonPrefixReturnsEmptyString()
        {
            var input = new[] { "cat", "bat", "hat" };
            var lcp   = new LongestCommonPrefix();

            Assert.Equal("", lcp.longestCommonPrefix(input));
        }
Exemplo n.º 4
0
        public void ExecuteTest2()
        {
            var strs     = new[] { "dog", "racecar", "car" };
            var expected = "";

            LongestCommonPrefix.Execute(strs).Should().Be(expected);
        }
Exemplo n.º 5
0
        public void GetLongestCommonPrefix_flower_flow_flight()
        {
            var    srv = new LongestCommonPrefix();
            string s   = srv.GetLongestCommonPrefix(new string[] { "flower", "flow", "flight" });

            Assert.AreEqual("fl", s);
        }
Exemplo n.º 6
0
        public void GetLongestCommonPrefix_dog_racecar_car()
        {
            var    srv = new LongestCommonPrefix();
            string s   = srv.GetLongestCommonPrefix(new string[] { "dog", "racecar", "car" });

            Assert.AreEqual("", s);
        }
Exemplo n.º 7
0
        public void TestEmptyPrefix()
        {
            LongestCommonPrefix longestCommonPrefix = new LongestCommonPrefix();

            string[] stringArray = new string[] { "abc", "efg" };
            string   prefix      = longestCommonPrefix.GetLongestCommonPrefix(stringArray);

            Assert.AreEqual("", prefix);
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            //var result = ReverseInteger.Reverse(123);
            //var result = Palindrome.IsPalindrome(123);
            var result = LongestCommonPrefix.FindLongestCommonPrefix(new string[] { "dog", "racecar", "car" });

            Console.WriteLine(result);
            Console.ReadLine();
        }
Exemplo n.º 9
0
        public void Excution1Test()
        {
            var fun = new LongestCommonPrefix();

            Assert.AreEqual("fl", fun.Excution1(new string[] { "flower", "flow", "flight" }));

            Assert.AreEqual(string.Empty, fun.Excution1(new string[] { "dog", "racecar", "car" }));

            Assert.AreEqual(string.Empty, fun.Excution1(new string[] { }));
        }
Exemplo n.º 10
0
        public void TestLongestCommonPrefix()
        {
            var r = LongestCommonPrefix.S1(new [] { "abcefg", "abcd", "ab" });

            Assert.AreEqual(r, "ab");

            r = LongestCommonPrefix.S2Binary(new[] { "abckkkkefg", "abckk", "abckkkdddd" });
            Assert.AreEqual(r, "abckk");

            r = LongestCommonPrefix.S2Binary(new[] { "", "abckk", "abckkkdddd" });
            Assert.AreEqual(r, "");
        }
Exemplo n.º 11
0
        private static void LongestCommonPrefixTest()
        {
            Console.WriteLine("\nLongest Common Prefix question:");

            LongestCommonPrefix longestCommonPrefix = new LongestCommonPrefix();

            IList <string[]> testStringArrays = new List <string[]> {
                new string[] { "flower", "flow", "flight" },
                new string[] { "dog", "racecar", "car" },
                new string[] { }
            };

            foreach (string[] stringArray in testStringArrays)
            {
                Console.WriteLine("[{0}] -> {1}", string.Join(", ", stringArray), longestCommonPrefix.LongestCommonPrefixOne(stringArray));
            }
        }
Exemplo n.º 12
0
 public void BeforeEach()
 {
     LongestCommonPrefix = new LongestCommonPrefix();
 }
Exemplo n.º 13
0
 public LongestCommonPrefixTests()
 {
     _testsVerifier = new TestsVerifier();
     _objUnderTest  = new LongestCommonPrefix();
 }
Exemplo n.º 14
0
        void InternalTest(string[] strs, string expected)
        {
            string actual = LongestCommonPrefix.Solve(strs);

            Assert.Equal(expected, actual);
        }
 public void FindPrefix_PassedFStringArray_Returnsf()
 {
     string[] input = new string[] { "flower", "flow", "fello", "fleet" };
     Assert.AreEqual("f", LongestCommonPrefix.FindPrefix(input));
 }
Exemplo n.º 16
0
 public void When_single_Then_whole_word()
 {
     Assert.AreEqual("abcgd", LongestCommonPrefix.LongestCommonPrefixFunc(new[] { "abcgd" }));
 }
Exemplo n.º 17
0
        public void Find(string[] array, string expectedProfix)
        {
            var result = new LongestCommonPrefix().Find(array);

            result.Should().Be(expectedProfix);
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            SortedMatrixSearch.Run();
            SparseSearch.Run();
            SearchInRotatedArray.Run();
            GroupAnagrams.Run();
            CombinationsOfNPairsParentheses.Run();
            PermutationWithDuplicates.Run();
            PermutationNoDuplicates.Run();

            var subsetList = new List <List <int> >();

            subsetList = SubsetInSet.FindAllSubsetInSet(new List <int> {
                1, 2, 3
            });
            ReverseLinkedList.Run();
            IsUniqueString.Run();
            StoneDivisionProblem.Run();
            Kangaroo.Run();
            AppleAndOrange.Run();
            AbbreviationProblem.Run();
            FibonacciModifiedProblem.Run();
            RecursiveDigitSum.Run();
            RangeSumOfBST.Run();
            GradingStudentsProblem.Run();
            // XorSequenceProblem.Run();
            CounterGameProblem.Run();
            MaximizingXORProblem.Run();
            LonelyIntegerProblem.Run();
            FlippingBitsProblem.Run();
            QueueUsingTwoStacksProblem.Run();
            GetNodeValue.Run();
            MergeTwoSortedLinkedLists.Run();
            Compare_Two_linked_lists.Run();

            DeleteNodeProblem.Run();
            ArrayManipulationProblem.Run();
            LeftRotationProblem.Run();
            HourGlass2D.Run();
            SimpleTextEditorProblem.Run();
            EqualStacksProblem.Run();
            MaximumElementProblem.Run();
            BinarySearchTreeInsertion.Run();
            TopViewProblem.Run();
            TimeConvertsionProblem.Run();
            BinaryTreePathsProblem.Run();
            IncreasingOrderSearchTree.Run();
            RemoveAllAdjacentDuplicatesInStringWithKLength.Run();
            RemoveAllAdjacentDuplicatesInString.Run();
            CheckStraightLineProblem.Run();
            HouseRobber.Run();
            UniquePathsProblem.Run();
            FirstUniqueCharacterInString.Run();
            BinaryTreeInorderTraversal.Run();
            DailyTemperaturesProblem.Run();
            CountingBitsproblem.Run();
            SortIntegersByTheNumberOf1BitsProblem.Run();
            HammingDistanceProblem.Run();
            RansomNoteProblem.Run();
            ConvertBinaryNumberInLinkedListToIntegerProblem.Run();
            NumberOfStepsToReduceNumberToZeroProblem.Run();
            JewelsAndStones.Run();
            ClimbingStairsProblem.Run();
            BestTimeToBuyAndSellStock.Run();
            MajorityElementProblem.Run();
            MoveZeroesProblem.Run();
            InvertBinaryTree.Run();
            SingleNumberProblem.Run();
            MaximumDepthInTrree.Run();
            MergeTwoBinaryTrees.Run();
            AddBinaryProblem.Run();
            PlusOneProblem.Run();
            LengthOfLastWordProblem.Run();
            KadaneAlgorithmForMaxSubArray.Run();
            KMPAlgorithm.Run();
            CountAndSayProblem.Run();
            SearchInsertPosition.Run();
            ImplementIndexOfString.Run();
            RemoveElement.Run();
            RemoveDuplicatesFromSortedArray.Run();
            MergeTwoSortedLists.Run();
            ValidParentheses.Run();
            LongestCommonPrefix.Run();
            RomanToInteger.Run();
            PalindromeNumber.Run();
            ReverseInteger.Run();
            TwoSumProblem.Run();
            AddOneToNumber.Run();
            MostAmountOfChange.Run();
            #region BinaryTree
            LeastCommonAncestor.Run();
            PrintAllPaths.Run();
            HasPathSum.Run();
            CheckIfBinaryTreeIsBinarySearchTree.Run();
            PrintAllNodesWithRangeInBinarySearchTree.Run();
            UniqueTreeStructureNumber.Run();
            MirrorTree.Run();
            #region BitManuiplation_GetNthNumber
            NumberOfStepsToReduceNumberToZeroProblem.Run();
            CountNumbersOf1InBit.Run();
            ReverseThebitsInInteger.Run();
            PrintBitsInInteger.Run();
            GetNthBit.Run();
            setNthBitTo1.Run();
            SetNthBitTo0.Run();
            #endregion
            MinimumtValueInTrree minValueInTree = new MinimumtValueInTrree();
            minValueInTree.Run();
            #endregion

            #region Recursion
            Chessboard chessboard = new Chessboard();
            chessboard.Run();
            RatPathToMaze ratPathToMaze = new RatPathToMaze();
            ratPathToMaze.Run();
            List <string> anagramList = new List <string>();
            anagramList        = WordAnagram.GenerateWordAnagram("abc");
            Pixel[,] pixelList = new Pixel[3, 3] {
                { new Pixel(0, 0, "red"), new Pixel(0, 1, "green"), new Pixel(0, 2, "green") },
                { new Pixel(1, 0, "red"), new Pixel(1, 1, "green"), new Pixel(1, 2, "green") },
                { new Pixel(2, 0, "red"), new Pixel(2, 1, "green"), new Pixel(2, 2, "green") }
            };
            FillPaint.PaintFill(pixelList, 1, 2, "green", "black");

            BinaryTreesAreTheSame.Run();

            #endregion

            #region General problems
            RotateArrayByKSpaces.Run();

            #region AddtwoNumbersReferencedByTheirDigits
            var addRes = AddtwoNumbersReferencedByTheirDigits.AddNumbers(new int[] { 1, 2, 7 }, new int[] { 9, 4 });
            #endregion

            #region RunLengthEncoding
            var encodedStr = RunLengthEncoding.Encode("aabbbbc");
            var decodedStr = RunLengthEncoding.Decode(encodedStr);
            #endregion

            #region BreakDocumentIntoChunk
            var chunkRes = BreakDocumentIntoChunk.Chunkify("ab:dd:ddfcct:aab:cccc", ':', 5);
            #endregion

            #region GameOfLife
            var gameRes = GameOfLife.GetNextInteration(new int[3, 3] {
                { 1, 0, 0 }, { 0, 1, 1 }, { 1, 0, 0 }
            });
            #endregion .

            #endregion


            #region InsertionSort
            InsertionSort.insertionSort(listToSort);
            #endregion

            #region BinarySearch
            Console.WriteLine(String.Format("%s is present at index: %s", 30, BinarySearch.binarySearch(sortedArray, 30, 0, sortedArray.Length - 1)));
            Console.WriteLine(String.Format("%s is present at index: %s", 4, BinarySearch.binarySearch(sortedArray, 4, 0, sortedArray.Length - 1)));
            Console.WriteLine(String.Format("%s is present at index: %s", 15, BinarySearch.binarySearch(sortedArray, 15, 0, sortedArray.Length - 1)));
            #endregion


            #region MergeSort
            MergeSort.print(listToSort);
            MergeSort.mergeSort(listToSort);
            #endregion


            #region QuickSort
            QuickSort.print(listToSort);
            QuickSort.quickSort(listToSort, 0, listToSort.Length - 1);
            QuickSort.print(listToSort);
            #endregion
        }
Exemplo n.º 19
0
 public void When_tow_Then_same_prefix()
 {
     Assert.AreEqual("ab", LongestCommonPrefix.LongestCommonPrefixFunc(new[] { "abcgd", "absadfsdaf" }));
 }
Exemplo n.º 20
0
        public void ReturnsEmptyStringForNoInput()
        {
            var lcp = new LongestCommonPrefix();

            Assert.Equal("", lcp.longestCommonPrefix(null));
        }
Exemplo n.º 21
0
 public void When_empty_Then_whole_word()
 {
     Assert.AreEqual(string.Empty, LongestCommonPrefix.LongestCommonPrefixFunc(new string[] { }));
 }
Exemplo n.º 22
0
 public void Setup()
 {
     _kata = new LongestCommonPrefix();
 }
Exemplo n.º 23
0
 private void oldProblems()
 {
     LongestCommonPrefix.Run();
     ConvertToBase.Run();
     PalindromeString.Run();
 }
 public void FindPrefix1_PassedNoCommonPrefixStringArray_ReturnsEmptyString()
 {
     string[] input = new string[] { "abc", "def", "ghi" };
     Assert.AreEqual("", LongestCommonPrefix.FindPrefix1(input));
 }
Exemplo n.º 25
0
        public void Case1()
        {
            var r = new LongestCommonPrefix().Go(new string[] { "flower", "flow", "flight" });

            Assert.AreEqual("fl", r);
        }
Exemplo n.º 26
0
        public void Case2()
        {
            var r = new LongestCommonPrefix().Go(new string[] { "dog", "racecar", "car" });

            Assert.AreEqual("", r);
        }