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…

Leetcode 1290 solution in java

Convert Binary Number in a Linked List to Integer Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representation of a number. Return the decimal value of the number in the linked list. The problem is…

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…

leetcode 1929 solution in java

Concatenation of Array Given an integer array nums of length n, you want to create an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). Specifically, ans is the concatenation of two nums arrays. Return the array ans. The problem is taken…

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 1920 solution in java

Build Array from Permutation 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). This 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…