ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

1920. Build Array from Permutation | Leetcode Daily 6 May 2025 | Java | Hindi

potd

daily

challenge

leetcode

algorithm

hq

aditi

solution

answer

approach

intuition

problem

question

story

binary

search

linear

matrix

medium

explanation

walkthrough

coding

gfg

geeks

for

maths

mathematics

amazon

google

flipkart

netflix

apple

interview

solve

hard

complexity

easy

studio

striver

sde

sheet

to

hackerrank

streak

time

stack

queue

linked

list

array

graph

tree

depth

first

dfs

bfs

breadth

string

algorithmhq

1920

Build Array from Permutation

Автор: AlgorithmHQ

Загружено: 2025-05-05

Просмотров: 676

Описание: "1920. Build Array from Permutation" is a medium-level problem and the LeetCode daily challenge (POTD) for 5 May 2025. The solution, written in Java, is explained with a dry-run on a blackboard, making it accessible to viewers with diverse programming backgrounds by focusing on the logic rather than language-specific details.

Intuition:
The problem asks us to build a new array such that ans[i] = nums[nums[i]] using the original array nums. A naive solution would require creating a new array, thus using extra space. However, we can cleverly modify the original array in-place using a technique that temporarily encodes both the old and new values in each index. The key idea here is to store two values in one integer without losing the original — we take advantage of the fact that all values are in the range 0 to n-1, so multiplying by n lets us shift one value into the higher digits.

During the first loop, we update nums[i] to store both the original value and the desired new value: nums[i] = nums[i] + n * (nums[nums[i]] % n). The modulo ensures we only use the original value (in case nums[nums[i]] was already updated). Then, in the second loop, we divide each element by n to extract just the new value we want, discarding the original. This trick gives us an efficient in-place solution with O(n) time and O(1) extra space, which is a smart and elegant use of number encoding.

Link to the problem: https://leetcode.com/problems/build-a...

Link to the Java Code: https://github.com/AditiChourasia/Lee...

For doubts/queries, please reach out on [email protected]
Connect with me on Linkedin:   / aditi-chourasia-a2a572121  

Other problems for practice:

   • 1128. Number of Equivalent Domino Pairs | ...  
   • 1007. Minimum Domino Rotations For Equal R...  
   • 838. Push Dominoes | Leetcode Daily 2 May ...  
   • 1295. Find Numbers with Even Number of Dig...  
   • 2302. Count Subarrays With Score Less Than...  
   • 3392. Count Subarrays of Length Three With...  
   • 2444. Count Subarrays With Fixed Bounds | ...  
   • 2845. Count of Interesting Subarrays | Lee...  

#leetcodejava #leetcode #dailychallenge #potd #hindi

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
1920. Build Array from Permutation | Leetcode Daily 6 May 2025 | Java | Hindi

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]