Matrix Diagonal Traverse Solution In C++/Python/java/JS Problem Description Given an m x n matrix mat, return an array of all the elements of the array in a diagonal order. Example Input: mat = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,4,7,5,3,6,8,9] Explanation: We pick elements diagonally.
Prime In Diagonal Problem Description You are given a 0-indexed two-dimensional integer array nums. Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0. Note that: 1) An integer is prime if it is
Control Flow Practice if-else and else-if ladder Practice Just doing the theory in a practical course is not a good idea. It's recommended to practice questions on these basic concepts when we are starting our programming journey to understand the concepts properly and build intuition for advanced concepts. Trust me this will help you in the
Matrix Diagonal Sum Problem Description Given a square matrix mat, return the sum of the matrix diagonals. Only include the sum of all the elements on the primary diagonal and all the elements on the secondary diagonal that are not part of the primary diagonal. What is a Square Matrix? A square matrix
Difference Between Ones and Zeros in Row and Column Solution In C++/Python/java/JS Problem Description You are given a 0-indexed m x n binary matrix grid. A 0-indexed m x n difference matrix diff is created with the following procedure: Let the number of ones in the ith row be onesRow_i. Let the number of ones in the jth column be onesCol_
Equal Row and Column Pairs Solution In C++/Python/java/JS Equal Row and Column Pairs Problem Description: Given a 0-indexed n x n integer matrix grid, return the number of pairs (ri, cj) such that row ri and column cj are equal. A row and column pair is considered equal if they contain the same elements in the same order
Lucky Numbers in a Matrix Problem Statement Given an m x n matrix of distinct numbers, return all lucky numbers in the matrix in any order. A lucky number is an element of the matrix such that it is the minimum element in its row and maximum in its column. Examples: Input: matrix = [[3,7,
Richest Customer Wealth Problem Statement You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the i th customer has in the j th bank. Return the wealth that the richest customer has. A customer's wealth is the amount of money they
more-articles-dsa Coming soon.. Hold tight! our team is working on more articles. We're constantly trying to bring a few new articles every week.
Time and Space Complexity Quiz: Time Complexity No talking here, only testing. int Sum1ToN(int n) { int ans = n*(n+1)/2; return ans; } int getSum(int n, int m) { int ans = 0; for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) ans++; return ans; } int doRandomStuff(int n, int
Time and Space Complexity How to Calculate Time Complexity? To calculate Time Complexity, we must try to understand the code line-by-line and see how many operations it will have to do for a given set of inputs. After finding the approximate number of operations as a function of the input variable: 1. Get rid of those terms that will
Time and Space Complexity Comparing Different Time Complexities In this article, I'll try to give you folks a brief idea about how much time codes with different time complexities take to run when given different sizes of inputs. Before diving in, I'd like to share that a C++ code can run around 2∗108
Time and Space Complexity Different Notations in Time Complexity Now that we know, on a high level, what time & space complexities are, it's a good time to look at different ways to represent them and try to make sense of them practically. Let's clear out the make sense of it part right now. It&
Time and Space Complexity Introduction to Space Complexity Alright; after having understood time complexity, this should be fairly easy. We just learned that measuring time efficiency in terms of the absolute time it takes to run a code is not ideal. Similarly, we can't just say that the space complexity of a program is 73 bytes
Time and Space Complexity Inroduction to Time Complexity Why did the algorithm go to therapy? It had an issue with time, and needed a safe space to sort it out! If I ask you, how time-efficient is this code you've written? What do you think will be the right way to measure it? What if you
Online Judge Tearing Down a Problem In this section, let's take a simple example problem from CodeForces and try to understand the following nuances involved: Problem Statement The Problem Statement is precisely what it suggests, i.e., an explanation of the problem for which the code has to be written. Usually, these statements are
Online Judge Popular Online Platforms I've made up my mind. I want to attain an appealing physique. From now on, I'll go to the gym daily for about an hour and closely watch my gym trainer work out. Within a year, I'll look like Hrithik Roshan. 💪🏻 Sounds pretty stupid?
Online Judge Why, What and How? Online judges: Where every line of code gets a fair trial, and bugs are considered 'guilty' until proven innocent. As Simon Sinek says: Let's start with Why! Imagine you're writing the code for a DSA problem in the college exam hall. I'm
DSA Preface Preface About the Course This course is designed to cater to both beginners and seasoned coders. Whether you want to build a solid foundation or enhance your problem-solving skills, we've got you covered. From the basics of arrays to advanced topics like dynamic programming, we'll leave nothing
Row with Maximum ones Problem Statement Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row. In case there are multiple rows that have the maximum count of ones, the row with the smallest
Minimum Operations to Make a Uni-Value Grid Solution In C++/Python/java/JS Problem Description You are given a 2D integer grid of size m x n and an integer x. In one operation, you can add x to or subtract x from any element in the grid. A uni-value grid is a grid where all the elements of it are equal. Return
Image Overlap Solution In C++/Python/java/JS Problem Description You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values. We translate one image however we choose by sliding all the 1 bits left, right, up, and/or down any
Where Will the Ball Fall Solution In C++/Python/java/JS Problem Description You have a 2-D grid of size m x n representing a box, and you have n balls. The box is open on the top and bottom sides. Each cell in the box has a diagonal board spanning two corners of the cell that can redirect a ball
Number of Laser Beams in a Bank Solution In C++/Python/java/JS Problem Description A bank's security system is represented as an m x n binary string array bank, where '1' denotes a security device and '0' represents an empty cell. A laser beam is formed between two devices if they are in different rows (r1
Valid Tic-Tac-Toe State Solution In C++/Python/java/JS Problem Description In this problem, you are given a 3x3 Tic-Tac-Toe board represented as a string array. The goal is to determine if the given board configuration could have been reached through a sequence of valid moves according to the rules of Tic-Tac-Toe. The game follows a turn-based approach where