Skip to main content

Command Palette

Search for a command to run...

Build Array from Permutation

Published
1 min read
Build Array from Permutation
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

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).

LeetCode Problem - 1920

class Solution {
    // Method to build an array where each element is replaced with the value at its corresponding index in the original array
    public int[] buildArray(int[] nums) {
        // Initialize an array to store the result
        int[] ans = new int[nums.length];

        // Iterate through the input array
        for(int i = 0; i < nums.length; i++) {
            // Replace the current element with the value at the index specified by the current element
            ans[i] = nums[nums[i]];
        }

        // Return the resulting array
        return ans;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.