Two Pointer Approach: An Efficient Technique

In this article we will discuss a linear and constant space technique to solve the programming questions. Two pointer Approach is an efficient technique to solve the problem with optimized time and space complexity. Two Pointer Approach Algorithm is mostly used for solving the array problems, where pointers are actually array indexes. Whenever the solution … Read more

Selection Sort Algorithm

Here, you’ll get thorough info about writing a program using a selection sort algorithm, while implementing an example. This is one of the simplest algorithms for sorting arrays. Its disadvantages are relating to time complexity which will be discussed further. We are tasked to create a sorted array of elements from a given random array, … Read more

Insertion Sort – A Stable Sorting Algorithm

Have you ever played card? If yes, then you’ll feel that insertion sort is somewhat similar to arranging cards in your hand. While arranging cards you’ll place the first card in your hand. After picking the second card you’ll compare it with the existing card and place it in the correct order. In the same … Read more

Bubble Sort – A Stable Algorithm

Bubble sort is one of the simplest sorting algorithms that is based on swapping adjacent elements if they are present in the wrong order. It is a stable algorithm since it preserves the order of the original vector in case of repetition. Bubble Sort C++ Algorithm Implementation Dry Run Input: nums = [5, 2, 10, … Read more

Median of Two Sorted Arrays | Leetcode Problem #4

In this question, given two sorted arrays nums1 and nums2 of size m and n respectively, you have to return the median of two sorted arrays Goal: The overall run time complexity should be O(log(m+n)) Naive Solution to Find Median of Two Sorted Arrays In this solution, we create a vector and then insert all … Read more

Find Repeating Element in Array| Leetcode #287

This article will discuss various approaches to find the element repeating more than once in an array, from naive to most efficient. Problem statement: Given an array of size n where each element is in the range [1,n-1], exactly one element repeats any no. of times in the array. Find that repeating element. Input: arr = … Read more

Find Peak Element in Array | Leetcode Problem #162

A peak element is defined as an element that is strictly greater than its neighbor. In this question, you’ll be provided with an array in which you have to find peak element and return its index. In case the array contains multiple peak elements, return the index of any one of the peak elements. You … Read more

Program to Find Square Root of an Integer Using Binary Search

This article will discuss how to find the square root of an integer efficiently using Binary Search. If the number is a perfect square, the program should return the square root, else return the floor of the square root of the number. Before that we first discuss the naive approach to find the square root … Read more

Program to Count Occurrence in a Sorted Array (From Naive to an Efficient Approach)

In this question, you’ll have to find the frequency of a given number(k) in a sorted array (nums[ ]). Below we have provided some of the examples so that you can have a better understanding of how to count occurrence in a sorted array. Naive Solution(Using Linear Search) In this approach, we use a linear … Read more

Maximum Sum Circular Subarray | Leetcode #918

Maximum Sum Circular Subarray this problem is variation of Maximum Sum Subarray question where we implemented the Kadane’s Algorithm. Check out our previous blog post on Kadane’s Algorithm here. Link to the current question https://leetcode.com/problems/maximum-sum-circular-subarray/ Let us consider an array {2, 1, -5, 4, -3, 1, -3, 4, 1}. So according to the problem the … Read more