Articles for author: Vishwas Sharma

Find the Middle Element in Linked List

Problem Statement You are given the head of a linked list, write a program to Find middle element in linked list. When there are even number of nodes in linked list, then there would be two middle nodes, return the second middle node. Example Input-1 Output-1 Explanation Here, 3 is the middle node of the ...

Difference Between Linear Search and Binary Search

As developers, we should be aware of the basic computer science concept of search algorithms such as linear search and binary search. Finding a given element’s occurrence in a list is the process of searching. In this article, we will discuss the difference between linear search and Binary search. There are two types of searching algorithms What ...

Delete a Node without Head Pointer

Problem Statement You are given a singly linked list and the reference to the node to be deleted in the linked list, write a program to delete that node from linked list. There is no information provided about the head pointer or any other node. The normal deletion would fail here as the linked list we ...

Maximum Sum Increasing Subsequence

Problem Statement An array of positive integers of size n is given. write a program to find the maximum sum increasing subsequence in the given array. The maximum sum increasing subsequence is a subsequence of an integer array where the sum is maximum and all of the elements are sorted in non decreasing order. Example ...

What is an Internal Sorting Algorithm?

Any sorting algorithm that uses the main memory exclusively during the sort is known as an internal sorting algorithm. In Internal sorting, the data can be accessed extremely fast and randomly. The internal sorting technique is used when data items are less than enough to be held in the main memory (RAM). Algorithms Used for ...

Triplet Sum in Array

Problem Statement An array of integers and a target sum are given, find out if there is any triplet whose sum is equal to the given target sum exists in the array or not, print the triplet, if a triplet sum in array is present and return true. Otherwise, return false. Example Input-1 Output-1 Explanation ...

Median of Array

Problem Statement An unsorted array of size n is given. write a program to find the median of an array. The median of array is the middle element of a sorted array in case of odd number of elements in an array and average of middle two elements when the number of elements in an array is even. Example Input-1 Output-1 ...

Container with Most Water

Problem Statement You are given an array $height[n]$ of integers of size n, where each value represents a coordinate position $(i, height[i])$. n vertical lines are drawn such that the endpoints of line i are at $(i, 0)$ and $(i, height[i])$. Find the container that is formed by two lines along with the x-axis, where the container ...

Majority Element in an Array

Problem Statement You are given an array arr[] containing n integers including duplicates. Write a program to find the majority element in an array if it is present. Else print no Majority Element Found. An element is called a majority element when it appears more than n/2 times in an array of length n. Example Input-1 Output-1 Explanation 9 appears 5 times which is ...

Rotate A Linked List

Problem Statement You are given the head of a singly linked list and an integer K, write a program to Rotate the Linked List in a clockwise direction by K positions from the last node. Example Input-1 Output-1 Explanation Here, we have rotated the linked list exactly 2 times. On the First rotation 5 becomes head and 4 becomes ...