Given an array with duplicate elements give an algorithm to get the count of distinct elements in the array

public class ArrayHandler {
    public static void main(String[] args) {

        int[] intArray = {1, 2, 3, 4, 5, 3, 1};
        Set valueSet = new HashSet();
        for (Integer intValue : intArray) {
        System.out.println("No of distinctive elements are " + valueSet.size());


Find first Non repeating char in a String

Given a string, return the first NON-repeating character that occurs in the string. EX: “adzbdcab” returns ‘z’.

public class StringHandler {

    public static void main(String[] args) {

        String input = "adzbdcab";
        char[] inputCharArray = input.toCharArray();
        for (char inputChar : inputCharArray) {
            if (input.indexOf(inputChar) == input.lastIndexOf(inputChar)) {
                System.out.println("First NON-repeating character is " + inputChar);


How to do versioning in REST API

We can versionize REST Api in any one of the following ways.

1. Use the version in the REST Service URI as below


2. Pass the service version as a query param to the actual service as below


3. Use the date as version and pass it to the REST Api


4. Using the customized accept header as like below

    public Response getVersion1() {
       String test="This is one of simple api to test. The version is 1";
       return Response.ok().entity(test).build();

    public Response getVersion2() {
        String test="this is one of simple api to test. The version is 2";
        return Response.ok().entity(test).build();

Then call the service as like below and pass the version in the accept header

curl --cookie "cookie name: cookie value" -H "accept:application/vnd.bala-v2+json" -X GET http://localhost:8080/api/server/version

5. Custom request header
Use the custom request header and pass the version in the http headers as like below. Note that your service should consume the api-version from the header and do the needful

curl --cookie "" -H "api-version:2" -X GET http://localhost:8080/api/users

Kanban board

A Kanban board is a work and workflow visualization tool that enables you to optimize the flow of your work

Below is one of the nice example of a Kanban board.


This is widely used in all the companies along with Agile Development.

If we want to maintain a personal Kanban board for managing your personal tasks then we could use the below site


Docker Checking logs

Check all the logs:
docker-compose -f <DOCKER_COMPOSE_FILE_NAME> logs

Check logs for a particular container:

We can also use the below command to tail the logs
docker-compose -f <DOCKER_COMPOSE_FILE_NAME> logs -f <CONTAINER_NAME>

docker-compose -f <DOCKER_COMPOSE_FILE_NAME> logs –follow <CONTAINER_NAME>

Check the log by container name:

  • Get the container name by running the below command
    docker ps
  • Then get the container name of the service for which we want to check the logs
    docker logs <>