public void TestArrayReverse(int[] array, int[] expectedResult) { var ae = new ArrayExercises(); var result = ae.ReverseArray(array); Assert.Equal(expectedResult, result); }
public void ArrayManipulation4(int emptyArrayLength, int expectedResult) { int[][] queries = new int[][] { new int[] { 1, 2, 100 }, new int[] { 2, 5, 100 }, new int[] { 3, 4, 100 } }; var ae = new ArrayExercises(); var result = ae.ArrayManipulation(emptyArrayLength, queries); Assert.Equal(expectedResult, result); }
public void ArrayManipulation3(int emptyArrayLength, int expectedResult) { int[][] queries = new int[][] { new int[] { 2, 6, 8 }, new int[] { 3, 5, 7 }, new int[] { 1, 8, 1 }, new int[] { 5, 9, 15 } }; var ae = new ArrayExercises(); var result = ae.ArrayManipulation(emptyArrayLength, queries); Assert.Equal(expectedResult, result); }
public void ArrayManipulation1(int emptyArrayLength, int expectedResult) { int[][] queries = new int[][] { new int[] { 1, 5, 3 }, new int[] { 4, 8, 7 }, new int[] { 6, 9, 1 } }; var ae = new ArrayExercises(); var result = ae.ArrayManipulation(emptyArrayLength, queries); Assert.Equal(expectedResult, result); }
public void Minimum_Swaps_works(int expectedResult, int[] array) { // var array = ArrayHelper.CreateArray("1 2 5 3 7 8 6 4"); var ae = new ArrayExercises(); var result = ae.MinimumSwaps(array); Assert.Equal(expectedResult, result); }
public void BeforeEachTest() { //Arrange arrayEx = new ArrayExercises(); }
public void FindDuplicatesTest(int[] nums, int[] expected) { int[] actual = ArrayExercises.FindDuplicates(nums).ToArray(); Assert.Equal(expected, actual); }
public void RotateTest(int[] nums, int k, int[] expected) { int[] actual = ArrayExercises.Rotate(nums, k); Assert.Equal(expected, actual); }
public void MaxProfitTest(int[] prices, int maxProfit) { int result = ArrayExercises.MaxProfit(prices); Assert.Equal(maxProfit, result); }
private static void RandomExercises() { int[] numValues = { 8, 1, 2, 2, 3 }; ArrayExercises.SmallerNumbersThanCurrent(numValues); int[] FirstDuplicate = { 2, 1, 3, 5, 3, 2 }; Console.WriteLine(string.Format("{0} is the first duplicate.", ArrayExercises.FindFirstDuplicate(FirstDuplicate))); BinaryTree <int> MyTree = new BinaryTree <int>(); MyTree.Insert(6); MyTree.Insert(7); MyTree.Insert(8); MyTree.Insert(2); MyTree.Insert(7); MyTree.Insert(1); MyTree.Insert(3); MyTree.Insert(9); MyTree.Insert(1); MyTree.Insert(4); MyTree.Insert(5); MyTree.SumEvenGrandparent(MyTree.Find(6)); long binary_val = 100100111000000; BitManipulator x = new BitManipulator(); Console.WriteLine(x.GetDecimalValue(binary_val)); int[] luis = ManyExercises.BeautifulArray(4); int[] arri = { 1, 1, 2, 3, 3, 4, 4, 8, 8 }; int UniqueVal = ManyExercises.SingleNonDuplicate(arri); if (UniqueVal > -1) { Console.WriteLine(string.Format("Unique value is {0}.", UniqueVal)); } else { Console.WriteLine("No unique value is found in given array."); } Console.WriteLine("\n"); string a = "kqep"; string b = "pekeq"; CustomSortString.SortString(a, b); int[] Pancakes = { 3, 2, 4, 1 }; ArrayExercises.PancakeSort(Pancakes); // [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]] int[][] matrix = new int[5][] { new int[] { 11, 25, 66, 1, 69, 7 }, new int[] { 23, 55, 17, 45, 15, 52 }, new int[] { 75, 31, 36, 44, 58, 8 }, new int[] { 22, 27, 33, 25, 68, 4 }, new int[] { 84, 28, 14, 11, 5, 50 } }; Console.WriteLine("Original Matrix:"); PrintMatrix(matrix); JaggedArray.DiagonalSort(matrix); Console.WriteLine("\nDiagonally Sorted Matrix:"); PrintMatrix(matrix); Console.ReadLine(); int[] arr = { 8, 3, 2, 7, 9, 1, 4, 1 }; Console.WriteLine("\n"); Console.WriteLine("Before SelectionSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.ReadLine(); SelectionSortAlgorithm.SelectionSort(arr); Console.WriteLine("\n"); Console.WriteLine("After SelectionSort:"); foreach (int i in arr) { Console.Write(i + ","); } Console.WriteLine("\n"); Console.ReadLine(); Console.Write("Binary Search. Enter number to search for: "); int.TryParse(Console.ReadLine(), out int key); BinarySearchAlgorithm.BinarySearch(arr, key); arr = Sorting(); int[] G = { 1, 2, 3, 3, 4, 5 }; Console.WriteLine(OneDimensionalArray.FindDuplicate(G)); Console.ReadLine(); int[] arrX1 = { 3, 4, -7, 1, 3, 3, 1, -4 }; OneDimensionalArray.FindSubarrayForGivenSum(arrX1, 7); var y1 = new int[] { 3, 1, 7, 5, 4, 9, 2 }; InsertionSortAlgorithm.InsertionSortBitWise(y1); PrintResults(y1); //ArrayExercises.StoreElementsInArray(); var x1 = new int[] { 1, 2, 3 }; var x2 = new int[] { 1, 2, 3 }; ArrayExercises.MergeToArraysSameSizeSorted(x1, x2); LeetCode lc = new LeetCode(); var groupSizes = new int[] { 3, 3, 3, 3, 3, 1, 3 }; var List111 = OneDimensionalArray.GroupThePeople(groupSizes); int[][] indices = new int[3][] { new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 }, new int[] { 0, 0, 0 } }; lc.OddCells(2, 3, indices); }
static void Main(string[] args) { ArrayExercises exercises = new ArrayExercises(); //FirstLast6 Console.WriteLine(":::::::FIrstLast6::::::::::"); int[] a = new int[] { 1, 2, 6 }; Console.WriteLine(exercises.FirstLast6(a));//-> true int[] a1 = new int[] { 6, 1, 2, 3 }; Console.WriteLine(exercises.FirstLast6(a1));// -> true int[] a2 = new[] { 13, 6, 1, 2, 3 }; Console.WriteLine(exercises.FirstLast6(a2));// -> false //SameFirstLast Console.WriteLine("::::SAMEFIRSTLAST:::::::::"); int[] b = new[] { 1, 2, 3 }; Console.WriteLine(exercises.SameFirstLast(b));// -> false int[] b1 = new[] { 1, 2, 3, 1 }; Console.WriteLine(exercises.SameFirstLast(b1));// -> true int[] b2 = new[] { 1, 2, 1 }; Console.WriteLine(exercises.SameFirstLast(b2));// -> true //MakePi //Console.WriteLine(exercises.MakePi(3));//-> { 3, 1, 4} //CommonEnd Console.WriteLine(":::::::::COMMONEND::::::::::::::"); int[] c = new[] { 1, 2, 3 }; int[] c1 = new[] { 7, 3 }; Console.WriteLine(exercises.CommonEnd(c, c1));// -> true int[] d = new[] { 1, 2, 3 }; int[] d1 = new[] { 7, 3, 2 }; Console.WriteLine(exercises.CommonEnd(d, d1));// -> false int[] e = new[] { 1, 2, 3 }; int[] e1 = new[] { 1, 3 }; Console.WriteLine(exercises.CommonEnd(e, e1));// -> true //Sum Console.WriteLine("::::::SUM:::::::::::::"); int[] f = new[] { 1, 2, 3 }; Console.WriteLine(exercises.Sum(f));// -> 6 int[] f1 = new[] { 5, 11, 2 }; Console.WriteLine(exercises.Sum(f1));// -> 18 int[] f2 = new[] { 7, 0, 0 }; Console.WriteLine(exercises.Sum(f2));// -> 7 //RotateLeft Console.WriteLine("::::::::::ROTATELEFT::::::::::::"); int[] g = new[] { 1, 2, 3 }; int[] rotateLeft = exercises.RotateLeft(g); foreach (var i in rotateLeft) { Console.Write(i);// -> {2, 3, 1} } Console.WriteLine(); int[] g1 = new[] { 5, 11, 9 }; int[] g2 = exercises.RotateLeft(g1); foreach (var i in g2) { Console.Write(i);// -> {11, 9, 5} } Console.WriteLine(); int[] g3 = new[] { 7, 0, 0 }; int [] g4 = exercises.RotateLeft(g3); foreach (var i in g4) { Console.Write(i); // -> {0, 0, 7} } Console.WriteLine(); //Reverse //int[] h = new[] { 1, 2, 3 }; //Console.WriteLine("::::::::::::::ReVERSE::::::::::"); //Console.WriteLine(exercises.Reverse(h));// //so for example {h} becomes {3, 2, 1}. //HigherWins //Console.WriteLine(":::::::::::::::HIGHERWINS:::::::::::::"); //int[] i = {1, 2, 3}; //Console.WriteLine(exercises.HigherWins(i));// -> {3, 3, 3} //int[] i2 = {11, 5, 9}; //Console.WriteLine(exercises.HigherWins(i2));// -> {11, 11, 11} //int[] i3 = {2, 11, 3}; //Console.WriteLine(exercises.HigherWins(i3));// -> {3, 3, 3} //11.HasEven //HasEven({ 2, 5}) -> true //HasEven({ 4, 3}) -> true //HasEven({ 7, 5}) -> false Console.WriteLine(":::::::::::::::::HASEVEN::::::::::::::::"); Console.ReadLine(); }