Skip to content

Category Archives: Java Programs

A disjoint-set data structure is a data structure that keeps track of a set of elements partitioned into a number of disjoint (non-overlapping) subsets. A… Read More
Given an unsorted array of integers, sort the array into a wave like array. An array ‘arr[0..n-1]’ is sorted in wave form if arr[0] >=… Read More
Given an array arr[] of n integers, find the maximum that maximizes the sum of the value of i*arr[i] where i varies from 0 to… Read More
Given a singly linked list L0 -> L1 -> … -> Ln-1 -> Ln. Rearrange the nodes in the list so that the new formed… Read More
Given an array of integers, evaluate queries of the form LCM(l, r). There might be many queries, hence evaluate the queries efficiently.   LCM (l, r)… Read More
Given a Singly Linked List, write a function to delete a given node. Your function must follow the following constraints:  It must accept a pointer… Read More
Given an array of distinct elements. The task is to find triplets in the array whose sum is zero. Examples :  Input : arr[] =… Read More
Given a string str and an array of strings arr[], the task is to check if the given string can be formed by any of… Read More
Following is a typical recursive implementation of QuickSort for arrays. The implementation uses last element as pivot.  Java /* A typical recursive implementation of    Quicksort… Read More
Given a singly linked list and a position, delete a linked list node at the given position. Example:   Input: position = 1, Linked List =… Read More
Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1? (eg given s1 = ABCD and… Read More
Write a removeDuplicates() function that takes a list and deletes any duplicate nodes from the list. The list is not sorted. For example if the linked… Read More
We have discussed Linked List Introduction and Linked List Insertion in previous posts on a singly linked list.Let us formulate the problem statement to understand… Read More
Given a singly linked list, select a random node from the linked list (the probability of picking a node should be 1/N if there are… Read More
Given singly linked list with every node having an additional “arbitrary” pointer that currently points to NULL. Need to make the “arbitrary” pointer point to… Read More

Start Your Coding Journey Now!