public static void Main(string[] args) { IHackerRankSolution solution = new AppleAndOrange(); solution.PrepareData(File.ReadAllLines(args[0])); solution.RunSolution(); }
public void TestCase03() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase03.txt")); Assert.AreEqual(18409, aor.Count("apple")); Assert.AreEqual(19582, aor.Count("orange")); }
public void TestCase11() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase11.txt")); Assert.AreEqual(5046, aor.Count("apple")); Assert.AreEqual(5659, aor.Count("orange")); }
public void TestCase09() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase09.txt")); Assert.AreEqual(16141, aor.Count("apple")); Assert.AreEqual(3358, aor.Count("orange")); }
public void TestCase10() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase10.txt")); Assert.AreEqual(37609, aor.Count("apple")); Assert.AreEqual(38141, aor.Count("orange")); }
public void TestCase08() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase08.txt")); Assert.AreEqual(28, aor.Count("apple")); Assert.AreEqual(2966, aor.Count("orange")); }
public void TestCase06() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase06.txt")); Assert.AreEqual(6661, aor.Count("apple")); Assert.AreEqual(4075, aor.Count("orange")); }
public void TestCase05() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase05.txt")); Assert.AreEqual(8032, aor.Count("apple")); Assert.AreEqual(3129, aor.Count("orange")); }
public void TestCase04() { AppleAndOrange aor = new AppleAndOrange(); aor.ReadStream(CreateFileStream("AppleAndOrangeTestCase04.txt")); Assert.AreEqual(2530, aor.Count("apple")); Assert.AreEqual(1149, aor.Count("orange")); }
public void AppleAndOrangeTests() { // Case One (Correct) var inputStartPointHouseCaseOne = 7; var inputEndPointHouseCaseOne = 11; var inputAppleTreePointCaseOne = 5; var inputOrangeTreePointCaseOne = 15; var inputFallenApplesCaseOne = new int[3] { -2, 2, 1 }; var inputFallenOrangesCaseOne = new int[2] { 5, -6 }; var exercise = new AppleAndOrange( inputStartPointHouseCaseOne, inputEndPointHouseCaseOne, inputAppleTreePointCaseOne, inputOrangeTreePointCaseOne, inputFallenApplesCaseOne, inputFallenOrangesCaseOne); var resultCaseOne = exercise.Execute(); var expectedOutputCaseOne = new int[2] { 1, 1 }; CollectionAssert.AreEqual(expectedOutputCaseOne, resultCaseOne); // Case Two (Check Constraints) var inputStartPointHouseCaseTwo = -1; var inputEndPointHouseCaseTwo = 11; var inputAppleTreePointCaseTwo = 5; var inputOrangeTreePointCaseTwo = 15; var inputFallenApplesCaseTwo = new int[3] { -2, 2, 1 }; var inputFallenOrangesCaseTwo = new int[2] { 5, -6 }; Assert.ThrowsException <ConstraintException>( () => new AppleAndOrange( inputStartPointHouseCaseTwo, inputEndPointHouseCaseTwo, inputAppleTreePointCaseTwo, inputOrangeTreePointCaseTwo, inputFallenApplesCaseTwo, inputFallenOrangesCaseTwo)); }
static void appleAndOrange() { int s = 7; int t = 11; int a = 5; int b = 15; int[] apples = new int[] { -2, 2, 1 }; int[] oranges = new int[] { 5, -6 }; Console.WriteLine("Apple and Orange"); AppleAndOrange.countApplesAndOranges(s, t, a, b, apples, oranges); }
public void TestCase02() { /* * Example Input: * 2 3 * 1 5 * 1 1 * 2 * -2 */ int house_bound_left = 2, house_bound_right = 3; int apple_tree = 1, orange_tree = 5; const int apple_count = 1, orange_count = 1; int[] apples = new int[apple_count] { 2 }; int[] oranges = new int[orange_count] { -2 }; Assert.AreEqual(1, AppleAndOrange.Count(house_bound_left, house_bound_right, apple_tree, apples)); Assert.AreEqual(1, AppleAndOrange.Count(house_bound_left, house_bound_right, orange_tree, oranges)); }
public void TestCase0() { /* * Example Input: * 7 11 * 5 15 * 3 2 * -2 2 1 * 5 -6 */ int house_bound_left = 7, house_bound_right = 11; int apple_tree = 5, orange_tree = 15; const int apple_count = 3, orange_count = 2; int[] apples = new int[apple_count] { -2, 2, 1 }; int[] oranges = new int[orange_count] { 5, -6 }; Assert.AreEqual(1, AppleAndOrange.Count(house_bound_left, house_bound_right, apple_tree, apples)); Assert.AreEqual(1, AppleAndOrange.Count(house_bound_left, house_bound_right, orange_tree, oranges)); }
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 }