Leet Code 42:- Trapping rain water solution

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…

Leetcode problem 1409:- Queries on a Permutation With Key

Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules: Return an array containing the result for the given queries. Example 1: Input: queries = [3,1,2,1], m = 5Output: [2,1,2,1]Explanation: The queries are processed as follow:For i=0: queries[i]=3, P=[1,2,3,4,5],…

leetcode solution of problem “Two Sum”

Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. This problem is…

leetcode solution of problem 53 in java

Maximum Subarray Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array. The problem is taken from the below mentioned link:- Leetcode Problem Approach:- In most of the case this kind of problems…

Leetcode solution of problem 217 in java

Contains Duplicate Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. The above problem is taken from the below mentioned link:- Leetcode Problem Approach:- Use of HashSet data structure will solve the problem. Here Set is chosen as it…

leetcode solution of problem 1409

Queries on a Permutation With Key Given the array queries of positive integers between 1 and m, you have to process all queries[i] (from i=0 to i=queries.length-1) according to the following rules: In the beginning, you have the permutation P=[1,2,3,…,m]. For the current i, find the position of queries[i] in the permutation P (indexing from…