leetcode 88:- Merge Sorted Array solution in java

Merge Sorted Array solution in java 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…

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…

java solution of Build Array from Permutation problem

Problem Statement of leetcode 1920:- Given a zero-based permutation nums (0-indexed), build an array ans of the same length where ans[i] = nums[nums[i]] for each 0 <= i < nums.length and return it. A zero-based permutation nums is an array of distinct integers from 0 to nums.length – 1 (inclusive). The problem is taken from…

leetcode 2037 solution in java

Minimum Number of Moves to Seat Everyone There are n seats and n students in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student. You…

leetcode 2006 solution in java

Count Number of Pairs With Absolute Difference K Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] – nums[j]| == k. The value of |x| is defined as: x if x >= 0. -x if x < 0. This above problem…