Skip to content

Category Archives: Java Programs

Given a linked list and two keys in it, swap nodes for two given keys. Nodes should be swapped by changing links. Swapping data of… Read More
Given an array arr[0 … n-1] containing n positive integers, a subsequence of arr[] is called Bitonic if it is first increasing, then decreasing. Write… Read More
Given a linked list having two pointers in each node. The first one points to the next node of the list, however, the other pointer… Read More
We have already discussed 2 different ways to clone a linked list. In this post, one more simple method to clone a linked list is… Read More
Given a linked list and a key in it, the task is to move all occurrences of the given key to the end of the… Read More
Given three linked lists, say a, b and c, find one node from each list such that the sum of the values of the nodes… Read More
Example: Let the input string be “i like this program very much”. The function should change the string to “much very program this like i”… Read More
Given a 2D binary matrix of N rows and M columns. The task is to check whether the matrix is horizontally symmetric, vertically symmetric, or… Read More
Given an array where every element occurs three times, except one element which occurs only once. Find the element that occurs once. Expected time complexity… Read More
Java // JAVA program for implementation of KMP pattern // searching algorithm    class KMP_String_Matching {     void KMPSearch(String pat, String txt)     {         int M =… Read More
Given a singly linked list, write a function to swap elements pairwise. For example, if the linked list is 1->2->3->4->5->6->7 then the function should change… Read More
Two Linked Lists are identical when they have the same data and the arrangement of data is also the same. For example, Linked lists a… Read More
Given an array of n integers where each value represents the number of chocolates in a packet. Each packet can have a variable number of… Read More
Given an array of positive and negative numbers, find if there is a subarray (of size at-least one) with 0 sum. Examples :  Input: {4,… Read More
Given a string str, find the length of the longest substring without repeating characters.  For “ABDEFGABEF”, the longest substring are “BDEFGA” and “DEFGAB”, with length… Read More