Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Here we have to calculate the total trapped water area under this blocks. To solve this problem, best approach is to use the double counter. Will start from each end…
Tag: algorithm
Recursive solution of the exponential problem and it’s illustration in detail
This is very common problem that is asked in any interview. So that will be explained below:- Before solving any recursive solution, we have to find the base case first and then the recursive portion. Here if we apply the power rule like a^(4) = a^(2) * a(^2) , then we can see one recursive…
Leet code problem 1733: – Minimum Number of People to Teach
On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer n, an array languages, and an array friendships where: You can choose one language and teach it to some users so that all friends…
Leet code problem 1664: – Ways to Make a Fair Array
You are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may change after the removal. For example, if nums = [6,1,7,4,1]: An array is fair if the sum of the odd-indexed values equals the sum of the even-indexed values. Return…
Leet code problem 1641: – Count Sorted Vowel Strings
Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted. A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet. Example 1: Input: n = 1Output:…
Leet code 1637: – Widest Vertical Area Between Two Points Containing No Points
Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area. A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width….
Leet code problem 1631: – Path with Minimum Effort
You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0), and you hope to travel to the bottom-right cell, (rows-1, columns-1) (i.e., 0-indexed). You can move…
Leet code problem 1672: – Richest Customer Wealth
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the ith customer has in the jth bank. Return the wealth that the richest customer has. A customer’s wealth is the amount of money they have in all their bank accounts. The richest customer is the customer that…
Leet code problem 1668: – Maximum Repeating Substring
For a string sequence, a string word is k-repeating if word concatenated k times is a substring of sequence. The word’s maximum k-repeating value is the highest value k where word is k-repeating in sequence. If word is not a substring of sequence, word’s maximum k-repeating value is 0. Given strings sequence and word, return…
Leet code problem 1662: – Check If Two String Arrays are Equivalent
Given two string arrays word1 and word2, return true if the two arrays represent the same string, and false otherwise. A string is represented by an array if the array elements concatenated in order forms the string. Example 1: Input: word1 = [“ab”, “c”], word2 = [“a”, “bc”]Output: trueExplanation:word1 represents string “ab” + “c” ->…