Software AG interview question

Round 1: What principles should be followed when exposing a function from a Java library. Can custom exceptions be sub classes of Runtime exception class. The time complexity of add and get operation for ArrayList,LinkedList,HashSet,TreeSet,HashMap and TreeMap. When should each of these data structures be used. Difference between ConcurrentHashMap,synchronized Map,HashMap. How locking is done on portion of the Map in ConcurrentHashMap. Describe the different areas in Java heap. Why composition is favored over inheritance. Why ReentrantLock is needed. Given a class with one String field and int field, what needs to be done to store object reference in ArrayList,TreeSet,HashMap Write a program which starts 3 threads,and the first thread to execute prints " Execution started" the last thread to terminate prints "Execution completed". The 3 threads should print numbers in different ranges.(1 -10,11-20,21-30) Was given a design problem on Observer pattern and asked to explain and draw the class diagram. Round 2 Given 2 arrays of size N and M (N > M ), print the intersection of the arrays. Derive the time complexity.You cannot use any other data structure . Since I used binary search in my implementation was asked to write function for binary search Given a 5 digit number, write program to find the next higher number using the digits. Example 56123 --> 56132 Given the stock prices of a particular stock over 10 days. Write a function to calculate maximum possible profit All the cases needed the most optimized solution.