# Merge Overlapping Intervals

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.

# Find the first duplicate number in an array

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)

# Minimum number of jumps to reach the end of an array

The problem says given an array where the elements of the array signifies the maximum number of box we could jump. We need to calculate the minimum number of jumps to be made to reach the end.

Let’s illustrate this with an example:

arr: {2,3,2,4,4}

Here arr = 2, so…

# Cyclically Rotate an Array By One

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)

# Extract Negative and Positive Numbers in constant space

Given an array of integers containing negative and positive numbers. Our task is to extract negative and positive numbers aside.

Let’s try to understand the problem clearly with the help of an example.

Let’s say given an array:

arr = {-1,2,-3,5,6,-12}

And we need to make it:

either : {-1,-3,-12,2,5,6}…

# Dutch National Flag or 3-Way Partitioning

The problem statement says you got to partition the array of 0,1,2 so that all the similar elements comes along and the elements be in order 0 then 1 and then 2.

Lets first have intuition what we need to do and then we will proceed with whatever we need…

# My Journey to DSA

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

So…

# Maximum Sub Array Sum[Contagious]

Code

`public class HelloWorld{    public static int maxSub(){        int[] array = {1,3,-2,0,12,2};                int maxSum = array;        int sumPerIteration = array;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){        System.out.println(maxSub());     }}`

# Sieve of Erasothenes

The Code

`/* package codechef; // don't place package name! */import java.util.*;import java.lang.*;import java.io.*;/* 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 {  seive(20); }}`

# AWK COMMAND AND QUESTIONS

SOME COMMON AWK COMMANDS

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}’`

Print… 