Skip to main content

Posts

Showing posts from May, 2022

Find root of largest tree

Today we will discuss a popular interview question. The problem tests a developers hands-on on various aspect of Java programming language as well as his problem solving ability. The resultant solution must have optimum time and space complexity. Problem Statement: Find the root of largest tree in the forest. Given each tree is represented as a hashmap entry with child as the key and parent as the value. Higher the number of children for any given root larger the tree. constrains: a. One child has only one immediate parent b. Any parent can have more than one children c. If two trees are equal then return root with least id Sample forest: {{1 -> 2}{3 -> 4}} Here we have 2 trees, one with node 1 and root 2 and second with node 3 and root 4. Both trees have same size hence the output should be the node with least id ie. 2. Solution:  Approach: We receive input hashmap with key as child and value as parent, hence child nodes are unique in this collection but parent values can b...

Frequently asked interview questions - Microservices

In this section, we are going to review most asked interview questions on micro-services architecture as well as micro-services in java. 1. What is an API gateway? A.  An API gateway or a service gateway is a software mechanism that sits between a client and a collection of back-end services.It provides single entry point in to the system. It is mainly responsible for request routing and security. An API gateway acts as a reverse proxy to accept all API calls, aggregate the various services required to fulfill them, and return the appropriate result . 2. How to upload images to a web service? A. We can upload image in a web service by marking the endpoint method with @consumes(media.type= MULTI_PART_FORM_DATA) 3.What is a loadbalancer? A. Load balancing refers to efficiently distributing incoming network traffic across a group of back-end servers such that it maximizes speed and CPU utilization and ensures that no one server is overworked, which could degrade performance. ...