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…

Algorithm to check if a String has all unique characters in java

This is a very common interview questions asked by many interviewer in SDET and SET interviews. At the very first, clear with the interviewer about the characters that the given string can hold. Here we are assuming that the string can contain ASCII characters with value from 1 to 128. Aproach:- So, at the very…