Solve LeetCode #1920: Build Array from Permutation

preview_player
Показать описание
🎯 LeetCode Problem of the Day (POTD) for May 6, 2025: #1920 Build Array from Permutation 🎯

In this video, I’ll walk you through solving LeetCode problem #1920: Build Array from Permutation. This is an easy problem that involves creating a new array based on a given permutation. I’ll explain the problem, share a simple solution using a separate array, and also touch on an advanced in-place approach with O(1) space!

📌 Timestamps:
0:00 - Introduction
0:30 - Problem Explanation
2:00 - Simple Solution (O(n) Space)
4:30 - Code Walkthrough
6:00 - Advanced In-Place Solution (O(1) Space)
8:00 - Time & Space Complexity
9:00 - Outro

💻 Code: Check the pinned comment for the full code in Java!

#LeetCode #POTD #BuildArrayFromPermutation #Coding #Programming #Java #Algorithms #DataStructures
Рекомендации по теме
Комментарии
Автор

class Solution {
public:
vector<int> buildArray(vector<int>& nums) {
vector<int> res(nums.size());
for(int i ; i < nums.size(); i++){
res[i] = nums[nums[i]]; //res[2] = nums[nums[2]] = nums[1] = 2;
}
return res;
}
};

utsxvrai
visit shbcf.ru