Rotating Elements of a Matrix by 90 Degrees

We’ll understand rotating elements of a matrix by 90 degrees, without using extra space and write the program to implement the same. Directly placing the elements of a matrix row by row in a temporary matrix is a reasonable solution, but the space complexity doubles in that case, when we have large sets of data, … Read more

Program for Spiral Traversal of a Matrix

We’ll learn to write a program for spiral traversal of a matrix of size m x n, which does mean as it sounds, we’ll start the corner of the matrix and traverse in a spiral towards the center of the matrix. Understanding the question, and output Given: Matrix, SizeOutput: Printing elements in a line using … 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

Program to Search in Row-wise and Column-wise Sorted Matrix

Program to search in a row-wise column-wise sorted matrix i.e. printing the location of an element(if it exists) in a row and column-wise sorted matrix.

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

Window Sliding Technique – An Efficient Technique

The window sliding technique if helpful when you have to reduce the time complexity from O(N2) to O(N) by converting nested loop into a single loop in problems that includes linear sequences, like arrays. A window is a contiguous sequence of elements in an array and as the name suggests in the window sliding technique, … Read more