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 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 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…

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…

leetcode 1816 solution in java

Truncate Sentence A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each of the words consists of only uppercase and lowercase English letters (no punctuation). For example, “Hello World”, “HELLO”, and “hello world hello world” are all sentences. You are given a sentence s​​​​​​…

leetcode 1854 solution in java

Maximum Population Year Solution This above problem is taken from https://leetcode.com/problems/maximum-population-year/ Solution:- Approach:- Code:- public static int methodeName(int[][] arr) { //defined one array years with size 2051 int[] years = new int[2051]; //Now hover over the goven 2d array for (int[] log : arr) { //given array is {1952,1961},{1953,1961 } //so for first iteration log…

leetcode 1859 solution in java

Sorting the Sentence A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters. A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence. For example,…