Find Sum of Digits of a Number – Java Code

Write a java program to find sum of digits of a number. Given an input number, we have to write a java code to calculate sum of digits of a number.

For example –

i)

Input : 256

Output : 13 (2+5+60

ii)

Input : 15

Output : 6 (1+5)

Find Largest Sum Contiguous Subarray – Kadane’s algorithm

Write a program to find largest sum contiguous subarray. Given an array of N elements, find the maximum possible sum of a contiguous subarray. An array can contain both positive and negative values.

For example –

Let’s take an array whose values are { 1, 2, -5, 4, 3, 8 , 5 }

Subscribe Our Tutorials

Get Latest Updates on Facebook

The maximum sum of a subarray in this array is 20.  And the subarray is (4, 3, 8, 5).

C Program to Print Prime Numbers from 1 to N – Sieve of Eratosthenes

Write a c program to print prime numbers from 1 to N (where n is an integer). This question can also be asked like, print prime numbers from 1 to 100 in c. In this tutorial, we are going to use sieve algorithm to print prime numbers from 1 to N.

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

Now, Let’s learn how to print prime numbers from to 1 to N using Sieve of Eratosthenes. Before solving this program, let’s understand what is a prime number.

Program to Search an Element in an Array

Write a program to search an element in an array. Given a sorted array, how do you search an element in an array. Think for a moment how do you solve this problem.

You can use multiple approaches to find the solution of this problem. But try to solve this problem in minimum time complexity.

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.

Bubble Sort Program, Algorithm & their Time Complexity

Bubble Sort program, Algorithm & their time complexity.In this tutorial, We are going to learn about bubble sort algorithm and their implementation in various programming languages.

In this tutorial, we are going to cover following things

  • What is Bubble Sort?
  • Bubble sort algorithm & it’s time complexity
  • Bubble sort program in C & C++
  • Bubble sort implementation in PHP

 

What is Bubble Sort?

Bubble sort is a sorting algorithm, It works by comparing each pair of adjacent elements and switching their positions if necessary. It repeats this process until all the elements are sorted.