Print Prime Numbers from 1 to N | Sieve of Eratosthenes

Write a program to print prime numbers from 1 to N (where n is an integer).

This problem can also be asked like,

i) How to print prime numbers from 1 to 100.

ii) How to print prime numbers from 1 to 1000 etc.

In this tutorial, we are going to learn how to print prime numbers efficiently using sieve algorithm.

Suppose the value of N is 10, So the prime numbers between 1 to 10 is 2, 3, 5, 7.

Before writing a code, let’s first first understand, what is prime number?

Program to Delete a Linked List

Write a program to delete a linked list. Given a linked list, we have to write a code to delete a linked list.

To delete a complete linked list, traverse all the nodes of a linked list and delete one by one.

Print Middle Element of a Linked List

How to Delete a Linked List

To delete a node one by one maintain two pointers.  The first pointer points to head and the second pointer keeps the reference to next node. So when a node is free, you can assign the reference of next node using the second pointer.

Find Duplicate Elements in an Array – Java Program

Write a java program to find duplicate elements in an array. Given an array of integers, We have to write a code to find all duplicate elements in an array.

For example :

Input : arr = { 2, 5, 3, 1, 8, 7, 5, 3, 2 }

Output: {5, 3, 2}

In this tutorial, I am going to explain three approaches to find duplicate elements in an array. This question is also very important for technical interviews.