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)

July 16, 2019

All About Bloom Filter

What is Bloom Filter?

Bloom filters are for set membership which determines whether an element is present in a set or not. Bloom filter is a probabilistic data structure that works on hash-coding methods (similar to HashTable).

It is a memory-efficient, probabilistic data structure that we can use to answer the question of whether or not a given element is in a set.

System Design Interview: Consistent Hashing

What is Hashing?
Hashing is the process of mapping one piece of data to another piece of data of fixed size. A function is usually used for mapping objects to hash code (which is typically an integer) known as a hash function.

Let's say we have fixed buckets numbered from 0-N. We have X number of balls (which is typically greater than or equal to N), and now we want to distribute these balls in the different buckets.

July 14, 2019

क्यों ख़ास है पारिजात का वृक्ष?

रीब 10 साल पहले विष्णु सहस्रनाम का ये श्लोक कही पढ़ा था..

छायायां पारिजातस्य हेमसिंहासनोपरि, आसीनमम्बुदश्याममायताक्षमलङ्कृतम् ।
चन्द्राननं चतुर्बाहुं श्रीवत्साङ्कित वक्षसं, रुक्मिणी सत्यभामाभ्यां सहितं कृष्णमाश्रये ॥

July 13, 2019

Part 5: Docker Interview Questions And Answers


-K Himaanshu Shuklaa..

Part 4: Docker Interview Questions And Answers (Docker Swarm)

Explain Docker Swarm.
Docker engine is hosted on a particular host, with Docker Swarm we can start the same host on multiple machines. There will be a master machine(which is docker manager) and then we have different slaves/workers. Whatever service we start on manager, will be started on slaves.

Swarm command creates a network of Docker engines/ hosts to execute containers in parallel (for scaling up and high availability).

A Docker Swarm is a service that allows us to create and manage a cluster of Docker nodes and schedule containers. Each node of a Docker Swarm is a Docker daemon, and all Docker daemons interact using the Docker API. Each container within the Swarm can be deployed and accessed by nodes of the same cluster.

What are the features of Docker Swarm?
  • Decentralized Access: Swarm makes it very easy for teams to access and manage the environment 
  • High Security: Any communication between the manager and client nodes within the Swarm is highly secure 
  • Auto Load Balancing: There is autoload balancing within your environment, and you can script that into how you write out and structure the Swarm environment 
  • High Scalability: Load balancing converts the Swarm environment into a highly scalable infrastructure
  • Roll-back A Task: Swarm allows you to roll back environments to previous safe environments.
How does Docker Swarm work?
In Swarm, containers are launched using services, where a service is a group of containers of the same image that enables the scaling of applications. Before we can deploy a service in Docker Swarm, we must have at least one node deployed.

There are two types of nodes in Docker Swarm:
  • Manager node: This node maintains cluster management tasks.
  • Worker Node: It receives and executes tasks from the manager node.
The manager node knows the status of the worker nodes in a cluster, and the worker nodes accept tasks sent from the manager node. Every worker node has an agent that reports on the state of the node's tasks to the manager.

The worker nodes communicate with the manager node using API over HTTP. In Docker Swarm, services can be deployed and accessed by any node of the same cluster. While creating a service, you'll have to specify which container image you're going to use.

You can set up commands and services to be either global or replicated: a global service will run on every Swarm node, and on a replicated service, the manager node distributes tasks to worker nodes. 

Getting started with Swarm Mode
Manager intiate the Docker Swarm. Here the manager is the instance which starts the Swarm cluster. The command to start the cluster is:

$ docker swarm init --advertise-addr < ip-address >

Here, the '--advertise-addr’ flag is used for advertising itself to other nodes who want to join the cluster. We need to specify the IP address of the manager along with the flag.

When the Swarm cluster is initiated, a token is generated at the manager’s end. Other nodes use this token to join the swarm cluster.

Any node that joins the cluster can be later promoted to a manager, to do this we need to execute below command at the manager’s end:

$ docker swarm < join-token > manager

Later when we want the token for a node to join the cluster, we need to run the below command:

$ docker swarm < join-token > node

We need to execute the token at every node you want, to join the cluster.

To leave the swarm, use

$ docker swarm leave

OR to leave force-ably

$ docker swarm leave --force

-K Himaanshu Shuklaa..

July 12, 2019

Part 3: Docker Interview Questions And Answers (docker-compose command)

How to use the docker-compose command?
Docker Compose is used to run multiple containers as a single service.

This command is used to power multi-container applications where various services will be hosted inside different containers.

Part 2: Docker Interview Questions And Answers (Docker Commands)

How to check for Docker Client and Docker Server version?
$ docker --version

Can a container restart on its own?
Since the default flag -reset is set to false, a container cannot restart by itself.

Part 1: Docker Interview Questions And Answers

What is Virtualization?
Virtualization is the process of creating a software-based, virtual version. These virtual versions or environments are created from a single physical hardware system.

With the help of Virtualization we can split one system into many different sections which act like separate, distinct individual systems.

What is Hypervisor?
A hypervisor also called Virtual Machine Monitor is a software that makes virtualization possible. The virtual environment created by the hypervisor is called Virtual Machine.

It divides the host system and allocates the resources to each divided virtual environment. We can  have multiple OS on a single host system. There are two types of Hypervisors:
  • Type 1: It’s also called Native Hypervisor or Bare metal Hypervisor. It runs directly on the underlying host system. It has direct access to your host’s system hardware and hence does not require a base server operating system.
  • Type 2: It is also known as Hosted Hypervisor and this kind of hypervisor makes use of the underlying host operating system.

देवशयनी एकदाशी..


ज आषाढ़ मास की शुक्ल पक्ष की एकादशी तिथि है। इस एकादशी को शास्त्रों में देवशयनी एकदाशी, पद्म एकदाशी, हरी शयनी एकदाशी या आषाढी एकदाशी कहा गया है। कहते है आज के दिन भगवान् विष्णु चार मास के लिए योग निद्रा करने जाते है और देवप्रबोधिनी एकदाशी के दिन उठते है।

July 04, 2019

Prince Narula Bereaved..

Prince Narula, who will soon be seen shaking his legs with Yuvika Chaudhary in Nach Baliye recently suffered a personal loss. We heard, the actor has lost his cousin brother recently.

July 03, 2019

OMG! Swaragini Actor Namish Taneja's Car Struck By Lightning


Namish Taneja, who is currently playing the main lead in Sony TV's 'Main Maayke Chali Jaaungi' met with a horrifying incident.

'Nazar' actress Ritu Chaudhary 'engineers' her disappearance from real to reel..

Ritu Chaudhary Seth, who plays the role of Vedhshree in Gul Khan's 'Nazar', has been continuously shooting since the inception of the show. Although she got random day-offs, but since her husband Gautam Seth is working, she couldn't got the time to go out and spend time with him and their daughter Ivaana.

She discussed this with the production house and they decided to tweak the story a bit so that Ritu can get a few days off.

July 01, 2019

CAP Theorem

CAP theorem (also known as Eric Brewers theorem) states that we can only achieve at most two out of three guarantees for a database: Consistency, Availability and Partition Tolerance.

What's New in Spring Framework 5?

What are the new features added in Spring 5?
#Java Baseline Support
  • Spring framework 5.0 codebase runs on Java 8. Therefore, Java 8 is the minimum requirement to work on Spring Framework 5.0. It also supports java 9.
  • Spring 5 supports Java EE 7 and also compatible with Java EE 8. We can use Servlet 4.0, Bean Validation 2.0, JPA 2.2 in our applications. We can also use their older versions i.e. Servlet 3.1, Bean Validation 1.1, JPA 2.1.
  • Spring 5 applications preferred server versions are Tomcat 8.5+, Jetty 9.4+ and WildFly 10+.