Articles for category: Data Structures and Algorithms

Longest Palindromic Substring

Problem Statement The Longest Palindrome in a String in one of the most classic problems in DSA. The problem statement goes like this: Given a string, find the maximum length substring of it that is a palindrome. Input: String Output: String Before we move on to examples and the solution to this problem, make a note of the ...

Introduction to Logarithms

Overview In this article, we are going to learn about Logarithms in programming. Before getting started with the topic, let us get a short overview of what is Logarithms. Logarithms: In mathematics, the inverse of an exponential function is called the logarithmic function. In simple terms, the logarithm is the exponent or power of any ...

Merge Sort for Linked Lists

Problem Statement Given a singly linked list, use the merge sort algorithm to sort the list in the ascending order of their node’s values. Example Input Output Example Explanation The nodes in the input are not arranged in any particular order, while they are arranged in ascending order of their value in the output. Constraints ...

Merge Two Sorted Linked Lists

Problem Statement Given two linked lists which are sorted in increasing order. Merge both lists into a single linked list which is also sorted in increasing order. Example Input : Output: Explanation As we can see that if we merge both lists and arrange them in increasing order, it will become 1->2->3->4->4->6->7->8->9. Constraints $1 <= ...

kth Largest Element in an Array

Problem Statement Given an integer k and an array of size n consisting of unique integers. Find the kth largest element in this array. Examples Input : 1 Output : 1 Input : 1 Output: 2 Explanation Constraints All the elements of the array are unique Approach – 1 : Sorting In this approach, we ...

What is the Hamiltonian Graph

Overview The hamiltonian graph is the graph having a Hamiltonian path in it i.e. a path that visits each and every vertex of the graph exactly once, such graphs are very important to study because of their wide applications in real-world problems. Hamiltonian graphs are used for finding optimal paths, Computer Graphics, and many more ...

Diagonal Traversal of Binary Tree

Problem Statement Given a binary tree $A$ containing $n$ nodes, consider diagonals (lines with a slope of $-1$) passing between the nodes and print all the diagonal elements in the binary tree belonging to the same line. Note: The diagonals with a slope of $-45\text{ degree}$ angle, will be like a $\backslash$. This question has ...

Josephus problem

Problem Statement There is n number of people standing in a circle. Numbering starts from 1 to n and is in the fixed clockwise direction. In each step, we are supposed to eliminate a person which is at the $k^{th}$ position from the current position such that only one man remains at the end who ...