Загрузка...

Target Sum | Two Ways Of Memoization | Detailed | Leetcode 494 | Explanation + Code

Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A

Hi Everyone, this is the 105th video of our Playlist "Dynamic Programming : Popular Interview Problems".
In this video we will solve a very classic knapsack variant of DP - Target Sum | Two Ways Of Memoization | Detailed | Leetcode 494 | Explanation + Code
We will also see two different ways of doing memoization.

Problem Name : Target Sum | Two Ways Of Memoization | Detailed | Leetcode 494 | Explanation + Code
Company Tags : Google, META
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/DP/Target%20Sum.cpp
Leetcode Link : https://leetcode.com/problems/target-sum
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Segment Tree Concepts Playlist : https://www.youtube.com/watch?v=k99r1A7krcY&list=PLpIkg8OmuX-K1qUIQToCllUO0UIKXt8dB
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Video Summary :
Approach-1: Normal Recursion & Memoization using unordered_map

Description:
This approach uses recursion to explore all possible combinations of adding or subtracting elements to achieve the target sum. Memoization is implemented using an unordered_map to store intermediate results, where the key is a string representation of the current state (index, sum).

Advantages:

Flexible and dynamic as it doesn't require predefining the memoization table size.
Efficient for sparse states.
Disadvantages:

Slightly slower due to string manipulation and hashing overhead.
Approach-2: Normal Recursion & Memoization using vector

Description:
Similar to the first approach, this uses recursion to explore all possible combinations. However, memoization is implemented using a 2D vector, where the dimensions are based on the number of elements (n) and the range of sums (2 * totalSum + 1). A shift (S) is used to handle negative sums by offsetting the indices.

Advantages:

Faster access compared to unordered_map due to direct indexing.
No overhead of key creation and hashing.
Disadvantages:

Memory-intensive as the entire table is preallocated, even for unused states.
Not suitable for very large inputs or sparse state spaces.
✨ Timelines✨
00:00 - Introduction
0:45 - Motivation
1:47 - Problem Explanation
4:51 - Notice
5:46 - Thought Process + Tree Diagram
14:27 - Coding Brute Force
16:51 - 2 Ways to Memoize
28:37 - Coding Memoization

#MIK #mik #Mik
#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #coding #programming #100daysofcode #developers #techjobs #datastructures #algorithms #webdevelopment #softwareengineering #computerscience #pythoncoding #codinglife #coderlife #javascript #datascience #leetcode #leetcodesolutions #leetcodedailychallenge #codinginterview #interviewprep #technicalinterview #interviewtips #interviewquestions #codingchallenges #interviewready #dsa #hindi #india #hindicoding #hindiprogramming #hindiexplanation #hindidevelopers #hinditech #hindilearning #helpajobseeker #jobseekers #jobsearchtips #careergoals #careerdevelopment #jobhunt #jobinterview #github #designthinking #learningtogether #growthmindset #digitalcontent #techcontent #socialmediagrowth #contentcreation #instagramreels #videomarketing #codestorywithmik #codestorywithmick #codestorywithmikc #codestorywitmik #codestorywthmik #codstorywithmik #codestorywihmik #codestorywithmiik #codeistorywithmik #codestorywithmk #codestorywitmick #codestorymik #codestorwithmik

Видео Target Sum | Two Ways Of Memoization | Detailed | Leetcode 494 | Explanation + Code канала codestorywithMIK
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять