Construct Target Array With Multiple Sums | Leetcode 1354 Hard | Live coding session | Leetcode Hard

preview_player
Показать описание
Here is the solution toConstruct Target Array With Multiple Sums leetcode question. Hope you have a great time going through it.

1) 0:00 Explaining the problem out loud
2) 1:10 Algorithm walkthrough
3) 2:30 Test cases
3) 11:15 Coding it up
4) 15:00 Time Complexity

PS : Please increase the speed to 1.25X
Рекомендации по теме
Комментарии
Автор

the approach is really understandable ! Kudos to you

anishapal
Автор


this is the new discord server for the channel

shyamsundar
Автор

clean and concise. you write the most readable codes.

himanshuchhikara
Автор

Missing that modulo trick actually results in TLE. Missed that one. Great content !

soumavabanerjee
Автор

class Solution {
public boolean isPossible(int[] target) {
if (target.length == 1) return target[0] == 1;

PriorityQueue<Integer> pq = new
int sum = 0;
for (int t: target) {
pq.add(t);
sum += t;
}

while (pq.peek() != 1) {
int curr = pq.poll();
if (sum - curr == 1) return true;

int x = curr % (sum - curr);
sum = sum - curr + x;

if (x == 0 || x == curr) return false;
else pq.add(x);
}

return true;
}
}

yashalwar
Автор

awesome explanation quenched my thirst...

shubhamagarwal
Автор

it was indeed a hard problem, but your explanation made it quite easy for me . thanks a lot sunchit !!

crackthecode
Автор

big fan, could not have been better👌🏼

parikabajaj
Автор

actually better explain the modulo trick a bit more. This is far more important than using heap in this question.

hoyinli
Автор

Nice explanation I got the idea but Time exceeded due to - instead % trick, totally forget it😅

abhishekvishwakarma
Автор

Amazing Explanation, keep putting out content.

satviksharma
Автор

can u expalin this maxEl< remaingTotal

himanshuchhikara
Автор

Can you pls explain how ->
remainingTotal == 1 returns true.

As you can consider this case where:
2 1 0 0 where max is 2 and remaining sum is 1 which will give true but it's incorrect as it is having two zeros behind.
Thanks!

amazinglife
join shbcf.ru