// https://leetcode.com/discuss/interview-question/689328/Bloomberg-or-Phone-or-Shuffle-Cards public void ShuffleTest() { var list = new [] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; Console.WriteLine($"\nInput: [{string.Join(',', list)}]"); Console.Write($"Output: [{string.Join(',', Shuffle(ListNodeUtilities.GetSinglyLinkedList(list)).AsEnumerable())}]"); }
public void SortedListToBSTTest() { var input = new[] { -10, -1, 5, 64, 77, 100 }; Console.WriteLine($"input: {string.Join(" -> ", input)}"); var result = SortedListToBST(ListNodeUtilities.GetSinglyLinkedList(input)); Console.WriteLine("\noutput:"); TreeNodeUtilities.PrintTree(result); }
public void ReverseBetweenTest() { var list = new[] { 1, 2, 3, 4, 5 }; var head = ListNodeUtilities.GetSinglyLinkedList(list); var m = 2; var n = 4; Console.WriteLine($"[{string.Join(',', list)}]"); Console.WriteLine($"[{string.Join(',', ReverseBetween(head, m, n).ToList())}]"); }
// https://leetcode.com/discuss/interview-question/435407/Facebook-or-Phone-or-Construct-a-Binary-Tree-and-Swap-Nodes-in-Pairs public void SwapNodesTest() { var list = ListNodeUtilities.GetDoublyLinkedList(new[] { 1, 2, 3, 4 }); Console.WriteLine( $@"Given: [{string.Join(',', list.AsEnumerable())}] OutPut: [{string.Join(',', SwapNodes(list).AsEnumerable())}] "); list = ListNodeUtilities.GetDoublyLinkedList(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }); Console.WriteLine( $@"Given: [{string.Join(',', list.AsEnumerable())}] OutPut: [{string.Join(',', SwapNodes(list).AsEnumerable())}] "); }