# Print missing and duplicate numbers in the given sequence of numbers.

Given a range of natural numbers where some numbers are repeated and some are missing in the range. Our aim is to find missing numbers and repeated numbers. Let us discuss the problem with an example. So for the input {2, 3, 3, 5, 5, 8, 2} our output should be as follows. This problemRead More »

# Auto-suggestion implementation using Trie Data Structure.

Trie data structure has many useful applications, one of the important applications of the trie is auto-suggestion when user inputs using the keyboard. Let us assume we have a dictionary that contains “APPLE”, “APE”, “GOD”, “GOOD”, “GUN”. So, when a user enters “GO” then our auto-suggestion suggests “GOD”, “GOOD” as a suggested list of words.Read More »

# Sort squares of a sorted array in linear runtime (O(n))

Given a sorted array that contains both negative and positive integers we aim to get its squares array in sorted orders. Let us understand this with an example. Let’s understand how we can solve this problem in linear time. To solve this in linear time, we have to take two handles which represent the startRead More »

# Find the longest substring with given max unique characters.

Given a string and an integer representing max unique characters, we aim to find the longest substring that does not exceed max unique characters. Let us understand this with an example. We can solve this problem by iterating over each character set in the array and gets the difference in character change. Let’s see thisRead More »

# Find the nearest integer of a given number in the binary search tree.

Given a Binary Search Tree (BST) contains integers and an integer. We aim to find the nearest node to input integer in the BST. Let us understand this with an example. Let’s see how our solution works to get the nearest node to the target integer. This algorithm runs with O(H), where is ‘H’ isRead More »

# Clone given Graph

Given a graph with an adjacency list, we aim to clone the complete graph with edges. Cloning does creates a new memory for similar data. Let us understand this with a three-node example graph. We can solve this problem using either DFS or BFS. Let’s solve this problem using DFS. Our Graph object contains theRead More »

# An algorithm to move all zeros to rightmost in an integer array.

Given an integer array, which contains some ‘k’ zeros. We aim to move all ‘k’ zeros to the right of most of the integer array. Let us see this with an example. Algorithm Iterate through each integer in the array and take a variable “pos,” representing the end of the array at first. If theRead More »

# Find if there exists a pair with a given sum in a sorted array.

Given an array of integers which are in ascending order and a sum. Our aim is to find if there is any pair of integers which total is equal to input sum. Let us discuss this problem with below example. Above example contains numbers 4 & 9 which sum is equal to our input. WeRead More »

# Parentheses matching problem.

Given a set of parentheses (a string expression), we aim to validate those parentheses. Let us see this with some examples. We can solve this problem using stack data structure. Here we have taken three sets of braces which are ‘{}’, ‘()’ and ‘[]’. Algorithm Check if stack not empty and current bracket character isRead More »

# Find the starting point of a sorted rotated array.

Given an ascending sorted rotated array, we aim to get the starting point of the array (the smallest element in the input array). Let us discuss this with an example. We use binary search to find the starting point of the sorted array. Let us see how this works. As we are using binary searchRead More »

# Find the number of visible boxes after inserting smaller size boxes into bigger size boxes.

Given an array of integers, each number represents the size of its box. A smaller size box can fit into a larger size box, whereas the same or larger size boxes can’t fit into one another. Let us see this problem with the below example. If we observe the above example, whatever the sized boxRead More »

# Find all possible combinations of decodings of a number.

Given an encoding number as explained below, we aim to print all combinations of decoding strings to that input number. The encoding number is as follows. Defining a recursion for this problem is very simple. Let us see the recursion tree for the input number. Let us now write the code for this recursion algorithm.Read More »

# Given two linked lists, both represent a number need to find its sum linked list.

As described in problem statement, we have two linked lists represents as decimal numbers. We aim to find its sum as a linked list. Let us understand this with an example. We can solve this problem in two different ways. Digit by digit sum calculation. Converting a list to the number and calculate the sumRead More »

# Remove duplicate characters from a string in-place.

Given a string of length ‘N’ (characters), we aim to remove all the characters which are duplicates in the input string. Let us understand this with the following example. To solve this kind of problem, we follow the same approach as we observed in removing alternate characters in a string in-place. The steps are asRead More »

# Eliminate Duplicate Characters in a Sentence Quickly and Easily!

Given a string of characters, we aim to remove all its alternate duplicate characters in that string in-place. Let’s look at an example to demonstrate how we can quickly and easily remove all alternating duplicate characters from a string of characters. We can solve this issue by creating an integer array of constant size 127.Read More »