1. Implement preOrder and postOrder Traversal for a B-Tree in Java
Discuss the preOrder traversal for a B-Tree and implement it in Java. Write the Node class and print the preOrder output. Provide both recursive and iterative implementations. As a follow-up, implement the postOrder traversal using an iterative approach. Consider the possibility of duplicate values and discuss how you might handle them, for example, using a stack or a set to store nodes. Finally, explain how postOrder can be thought of as a mirrored version of preOrder, where you would change the order of pushing children and then reverse the result to achieve the postOrder output.
2. Maximize Product of Five Numbers in an Array
Given an array, find the maximum product that can be obtained from any five numbers in the array. The solution should consider the following cases: the product of the five largest positive numbers, the product of the two smallest negative numbers and the three largest positive numbers, and the product of the four smallest negative numbers and the largest positive number. You should not sort the array; instead, scan through the data once to find the five largest positive numbers and the four smallest negative numbers, then compare to find the maximum product. Write code to implement this logic.
3. Linkedlist Middle Node and Loop Detection
Write a function to find the middle node of a linked list, and another function to detect a loop in a linked list using the fast and slow pointer technique.
4. Basic Binary Search
Write the most basic form of binary search without any variations.
5. Count and Say Problem
Implement a function that transforms a string by counting the consecutive characters. For example, the input 'aaabbcdd' should be converted to 'a3b2c1d2'.