Longest Ideal Subsequence | LIS Variant | Bottom Up | Optimal | Leetcode 2370 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 92nd Video of our Playlist "Dynamic Programming : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a very good DP problem based on LIS Variant : Longest Ideal Subsequence | LIS Variant | Bottom Up | Optimal | Leetcode 2370 | codestorywithMIK
I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.
Problem Name : Longest Ideal Subsequence | LIS Variant | Bottom Up | Optimal | Leetcode 2370 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/DP/LIS%20%26%20Variants/Longest%20Ideal%20Subsequence.cpp
Leetcode Link : https://leetcode.com/problems/longest-ideal-subsequence/
My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
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
Approach Summary :
Approach-1: This approach utilizes the Longest Increasing Subsequence (LIS) algorithm to find the length of the longest ideal string in a given string `s`. It iterates through each character of `s` and for each character, it checks all previous characters to find the maximum length of an ideal subsequence that can be formed ending at that character. Time complexity is O(n^2) because of nested loops where n is the length of the string `s`. Space complexity is O(n) because of the additional storage required for the `t` vector.
Approach-2: This approach optimizes the previous approach by only considering characters within a certain range around the current character `s[i]`. It maintains an array `t` of size 26 to store the length of the longest ideal subsequence ending at each character in the alphabet. It iterates through each character of `s`, calculates the range of characters to consider based on the difference `k`, and updates the length of the longest ideal subsequence ending at the current character accordingly. Time complexity is O(n) as it iterates through the string once, and space complexity is O(1) since the size of the auxiliary array `t` is fixed.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
#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 #newyear2024