July 28, 2019

How to check if a Tree is subtree of another Tree?

To check if the given tree is subtree of another tree, first we need to undertand if the how can we check if the tree's are identical or not.

Please visit: Check if two Binary Trees are Identical or not?

To verify if a tree is subtree of another, we need to traverse the Tree T in a preorder fashion.For every visited node in the traversal, see if the subtree rooted with this node is identical to another tree S.

How to check of two Binary Trees are Identical?

Two Binary trees are identical when they have same data and structure/arrangement of data is also same. To find if they are identical or not, we need to traverse both the trees simultaneously, and in each iteration we will compare the data of current node and the children of both the trees.

Factorial using recursion in Java

Write a program to calculate Factorial of a number using recursive function. To improve the performance, try to use HashMap, which will store the calculated factorials that can be reused.

FYI, Factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!.

Bottom View of a Binary Tree

Recently I had given interview in Morgan Stanley for Senior Java Developer profile, the intervier asked me, we have a balanced Binary Tree, am trying to throw a light from a particular node, which all nodes will be visible?

I tried my best, but failed to write an algorithm. After the interview I realized he was asking to write an algorithm to see the bottom view of a Binary Tree.

The bottom view of a binary tree refers to the bottommost nodes present at their horizontal distance.

If we see the tree from bottom from a particular node, which all nodes will be visible is the bottom view of a Binary Tree.
The bottom view of above Binary Tree is: 7, 5, 8, 6

July 27, 2019

Vertical Order Traversal of a Binary Tree

Let's say we have below Binary Tree

In vertical traversal, we print nodes of a binary tree in vertical order by assuming that the left and right child of a node makes 45 degree angle with the parent.

We need to check the Horizontal Distances from the root for all nodes. If two nodes have the same Horizontal Distance (HD), then they are on the same vertical line.

Level Order Traversal of a Binary Tree

Let's say we have below Binary Tree


We need to print nodes level by level. i.e. all nodes present at level 1 should be printed first followed by nodes of level 2 and so on. All nodes for any level should be printed from left to right.

Morgan Stanley Java Interview Questions

  1. What is a predicate in Java? Can you throw an exception from a predicate? Its a functional interface which accept one argument and produce a result. (solution) 
  2. Explain fail fast and fail safe iterators. (solution)
  3. Implement stack using Queue.(solution)
  4. Write a program to reverse a linked list. (solution)
  5. Write a program to return all characters from a string which appeared more than once. (solution)
  6. Generate the Fibonacci recursively and iteratively in Java. Explain the complexities for both solutions.(solution)
  7. Swap the values between two elements without using a third element.
  8. Generate all anagrams of a String.(solution)
  9. How PriorityQueue works internally in Java?
  10. Difference between TreeSet and PriorityQueue in Java.
  11. Given a string like ABC find all possible distinct permutations, e.g:ABC,BAC,CAB etc.
  12. Sort array elements in place making even and odd number together.
  13. Write a function to return the maximum difference between two elements in an array.
  14. I have an array of million integers. I want to sum it efficiently. How would you do it without using Java 8 parallel streams? (Hint: use forkjoinpool)
  15. Some Basic Core Java Interview Questions related to Polymorphism and try catch(solution)
  16. Write a method to find the first non-repeating character from a String? (solution)
  17. We have a balanced Binary Tree, am trying to throw a light from a particular node, which all nodes will be visible?(solution)
  18. What will happen if we return a constant number from overriden hashCode() method?
  19. What will happen if we return constant number from overriden hashCode() method and false from equals()?
  20. What will happen if we return constant number from overriden hashCode() method and true from equals()?

July 24, 2019

Sushmita Sen’s brother, Rajeev talks about his debut

Ullu App is coming up with a series which is based on a terrorist attack on Peshawar's Army Public School on 16th December, 2014, in which more than 148 people, most of them children, were killed. Now we heard, Sushmita Sen’s brother, Rajeev will be making his debut with the series.

Rakshanda Khan roped in for Ullu App's Peshawar


We have exclusively reported that Ullu App is coming up with a series which is based on a terrorist attack on Peshawar's Army Public School. Now we heard, gorgeous Rakshanda Khan has been roped in to play a challenging role in the series.

'Jodha Akbar' fame Ravi Bhatia to do a music video

Popular actor Ravi Bhatia, who shot to fame through his portrayal of Prince Salim in Ekta Kapoor's historic drama 'Jodha Akbar' will soon be seen in a music video. The song is sung by Shaan, apparently he is Bhatia's favorite singer.

July 23, 2019

All About Spring Boot Actuator

What is Actuator?
  • We can monitor our app, gather metrics, understand traffic, or the state of our database with the help of Actuator,
  • With Actuator we can get production-grade tools without having to actually implement these features ourselves.
  • It is mainly used to expose operational information about the running application – health, metrics, info, dump, env, etc. 
  • Actuator uses HTTP endpoints or JMX beans to enable us to interact with it.

SugerBox interview questions for Senior Java Software Engineer

  1. What is the difference between Spring Singleton and Java Singleton?(solution)
  2. Explain JWT.(solution)
  3. Explain Circuit Breaker Pattern.(solution)
  4. What is the purpose of Bulkhead Pattern?(solution)
  5. Suppose we have two web-services E and D. E is calling D. At a time D can accept only 30 requests, but E is getting more than 50 requests. How can you handle this?
  6. Have you ever used Actuator?(solution)
  7. What is the purpose of Consumer groups in Kafka?(solution)
  8. What is the difference between SSL and SSH?(solution)
  9. Explain TLS.(solution)
  10. How can we migrate data from one schema to another?(solution)

Wissen Technology Interview Questions For Senior Java Developer/ Lead Position

  1. What is the difference between Composition and Aggregation? How can we implement them in Java?
  2. How can we implement Least Recently Used (LRU) Cache using LinkedHashMap? (solution)
  3. What is the use of Builder Design Pattern. (solution)
  4. Explain Observer Design pattern. (solution)
  5. Assume we have an Employee class, which contains employeeName, employeeId (both are Strings) and employeeDateOfJoining(which is date). How can I make employee class Immutable? (solution)
  6. What is the advantage of making a String class Immutable? (solution)
  7. Design your own custom Threadpool executor with minimal functionality?(solution) (GIT:Custom Threadpool executor)
  8. An Employee table has four columns, emp_id, emp_name, salary and mngr_id. Find all the employees, who have a bigger salary than their manager. Answer: SELECT e.emp_name FROM Employee e JOIN Employee m ON e.mngr_id = m.emp_id WHERE e.salary > m.salary;
  9. Find the employee who is getting third higest salary? Answer: SELECT top 1 salary FROM (SELECT top 3 salary FROM Employee ORDER BY salary DESC) Result ORDER BY salary;

#Collections: How LinkedHashMap works internally in Java?

Java LinkedHashMap class is Hashtable and Linked list implementation of the Map interface. LinkedHashMap is like HashMap with an additional feature of maintaining an order of elements inserted into it.

July 22, 2019

Ullu App to produce a web-series on Peshawar's terrorist attack

Remember the brutal terrorist attack in Peshawar's Army Public School on December 16, 2014, in which more than 148 people, most of them children, were killed? At that time not only Pakistan, but the whole world, including Indian felt the pain and sorrow. We heard, Ullu App is making a series on the brutal attack.

UBS interview questions

  1. Explain concurrency utils i.e. Atomic package? (Answer)
  2. How AtomicInteger works internally? (Answer)
  3. What is a volatile keyword? (Answer)
  4. Why is AtomicInteger class better than a synchronized counter class? (Answer)
  5. What is CAS?(Answer)