The problem says we are provided set of intervals. Find the overlapping interval and merge into one.

Let us try to understand the problem with the help of an example.

Now let’s have a look at the code to visualize it.

Provided there is only one duplicate number existing in an array.

The idea is to take some data structure like Set and whenever we find some element which already exists in the set we will return it.

Lets have a look at the code.

Time complexity O(n)

Given an array, the job is to rotate the array cyclically by one.

Let us try to understand the problem with the help of an example below.

arr: {1,2,3,4,5,6}

the resultant array should be

arr: {6,1,2,3,4,5}

That is the last element at top and the rest of the elements pushed by one. Let us try to understand this witht he help of the code.

Have a look at the code, I think things are much clearer.

Time complexity O(n)

space complexity O(1)

Hello there so today I am starting in my journey towards Data Structure and Algorithm and here in this blog I will kind of share my experience learning DS and algorithm. This is a continuous blog so each day I will keep adding the content in it.

Day 1



public class HelloWorld{
public static int maxSub(){
int[] array = {1,3,-2,0,12,2};

int maxSum = array[0];
int sumPerIteration = array[0];
for(int i = 1; i < array.length; i++) {if(sumPerIteration < 0) {
sumPerIteration = array[i];
} else {
sumPerIteration=sumPerIteration + array[i];
if(sumPerIteration > maxSum) {
maxSum = sumPerIteration;
return maxSum;
public static void main(String []args){

The Code

/* package codechef; // don't place package name! */import java.util.*;
import java.lang.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
public static void seive(int n)
boolean nums[] = new boolean[n+1];

for(int i = 0;i<n;i++)
nums[i] = true;

for(int p = 2;p*p<=n;p++){
if(nums[p] == true){
for(int i = p*p;i<=n;i=i+p){
nums[i] = false;

for(int i = 0;i<n;i++){
if(nums[i] == true){
System.out.print(i + " ");
public static void main (String[] args) throws java.lang.Exception


print the content of the file using awk

awk ‘{print}' filename.txt

Adding a new line of word at top of the file

awk ‘BEGIN{printf "This is new line"}{print}’ filename.txt

Assigning a value to the variable before execution

awk -v name="Jack" ‘BEGIN{printf "Name = $s\n", name}’



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store