Leetcode 42 – Trapping Rain Water | Two Pointer

Trapping Rain Water

Problem Description: 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. Example 1 : Example 2: Constraints: Problem Link :Trapping Rain Water – LeetCode Solution(s): Approach 1: Brute Force Solution Java Code: Explanation: 1.Initialization: 2.Main Loop: 3.Finding Maximum Height to the Left: … Read more

Leetcode 88- Merge Sorted Array | Two Pointer

Merge Sorted Array

Problem Descrption: You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a length of m + n, where the first m elements … Read more

Leetcode 189 – Rotate Array | Three Approaches

Leetcode 189 - Rotate Array

Problem Description: Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. Example 1: Example 2: Constraints: Problem Link : Rotate Array – LeetCode Solution(s): Approach 1: Using temporary array Java Code: Complexity: Approach 2 : In-Place Java Code : Complexity:

Leetcode 27- Remove Element from Array

Leetcode 27- Remove Element

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val. Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things: Custom Judge: The judge will test your … Read more