codestorywithMIK
codestorywithMIK
  • 940
  • 4 579 637
Find the Closest Palindrome | Simple Observations | Leetcode 564 | codestorywithMIK
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 42nd Video of our Playlist "Strings : Popular Interview Problems" by codestorywithMIK
In this video we will try to solve a very good String Problem : Find the Closest Palindrome | Simple Observations | Leetcode 564 | 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 : Find the Closest Palindrome | Simple Observations | Leetcode 564 | codestorywithMIK
Company Tags : YELP
My solutions on Github(C++ & JAVA) - github.com/MAZHARMIK/Interview_DS_Algo/blob/master/strings/Find%20the%20Closest%20Palindrome.cpp
Leetcode Link : leetcode.com/problems/find-the-closest-palindrome
My DP Concepts Playlist : ua-cam.com/video/7eLMOE1jnls/v-deo.html
My Graph Concepts Playlist : ua-cam.com/video/5JGiZnr6B5w/v-deo.html
My Recursion Concepts Playlist : ua-cam.com/video/pfb1Zduesi8/v-deo.html
My GitHub Repo for interview preparation : github.com/MAZHARMIK/Interview_DS_Algo
Instagram : codestorywithmik
Facebook : people/codestorywithmik/100090524295846/
Twitter : CSwithMIK
Subscribe to my channel : www.youtube.com/@codestorywithMIK
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Summary :
The solution aims to find the closest palindrome to a given number by generating several potential palindrome candidates. The steps are:
Mirror the First Half: The first step is to create a palindrome by mirroring the first half of the given number.
Generate Variants: Next, it generates two additional palindromes by mirroring (firstHalf + 1) and (firstHalf - 1) to handle cases where the nearest palindrome is slightly larger or smaller.
Handle Edge Cases: The solution also considers edge cases, such as palindromes of the form 999... (e.g., 999) and 100...001 (e.g., 1001), which could be nearest palindromes for numbers like 1000.
Find the Closest: Among the generated candidates, the closest palindrome is selected based on the smallest absolute difference from the original number. If multiple palindromes have the same difference, the smaller one is chosen.
This approach ensures that all relevant possibilities are considered to find the nearest palindromic number efficiently.
✨ 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
Переглядів: 7 792

Відео

Fraction Addition and Subtraction | Simple Simulation | Leetcode 592 | codestorywithMIK
Переглядів 10 тис.7 годин тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 41st Video of our Playlist "Strings : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a very good String Problem : Fraction Addition and Subtraction | Simple Simulation | Leetcode 592 | codestorywithMIK I will explain the intuition so easily that you will never forget and s...
Number Complement | Multiple Approaches | Leetcode 476 | codestorywithMIK
Переглядів 6 тис.9 годин тому
Whatsapp Community Link : whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 52nd Video of our Playlist "Leetcode Easy : Popular Interview Problems" by codestorywithMIK In this video we will try to solve an easy problem : Number Complement | Multiple Approaches | Leetcode 476 | codestorywithMIK I will explain the intuition so easily that you will never forget and start seeing this as cak...
2 Keys Keyboard | Detailed Explanations | Leetcode 650 | codestorywithMIK
Переглядів 8 тис.16 годин тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 99th Video of our Playlist "Dynamic Programming : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a very good and famous problem : 2 Keys Keyboard | Multiple Approaches | Leetcode 650 | codestorywithMIK I will explain the intuition so easily that you will never forget and s...
Count Substrings That Satisfy K-Constraint I & II | Detailed Explanation | Leetcode 3258 & 3261
Переглядів 4,1 тис.19 годин тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 26th Video of our Playlist "Sliding Window : Popular Interview Problems" by codestorywithMIK Minimum Falling Path Sum - ua-cam.com/video/EQC0ckOyEGs/v-deo.html In this video we will try to solve two very Sliding Window problems : Count Substrings That Satisfy K-Constraint I & II | Detailed Explanation | Leet...
The Imperial Delhi | Weekend Getaway | Luxury Stay | 5 Star hotel | WeekendWithMik
Переглядів 6 тис.21 годину тому
Stepping into “The Imperial Delhi” felt like traveling through time! This hotel isn’t just about luxury-it’s a living piece of history, with every corner telling a story of Delhi’s rich past. From the grand hall to the art-filled galleries, it’s where heritage meets modern comfort. 🛏️✨ The cozy room, relaxing spa, and top-notch gym had me feeling like royalty. And yes, I even tried to quiz a pi...
Maximum Number of Points with Cost | Detailed Explanation | Leetcode 1937 | codestorywithMIK
Переглядів 11 тис.21 годину тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 98th Video of our Playlist "Dynamic Programming : Popular Interview Problems" by codestorywithMIK Minimum Falling Path Sum - ua-cam.com/video/EQC0ckOyEGs/v-deo.html In this video we will try to solve a very good 2D - DP problem : Maximum Number of Points with Cost | Detailed Explanation | Leetcode 1937 | cod...
Maximum Distance in Arrays | Leetcode 624 | codestorywithMIK
Переглядів 7 тис.День тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 37th Video of our Playlist "Greedy : Popular Interview Problems" by codestorywithMIK In this video we will try to solve an Easy-Medium Greedy problem : Maximum Distance in Arrays | Leetcode 624 | codestorywithMIK I will explain the intuition so easily that you will never forget and start seeing this as cakew...
Lemonade Change | Leetcode 860 | codestorywithMIK
Переглядів 4 тис.День тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 51st Video of our Playlist "Leetcode Easy : Popular Interview Problems" by codestorywithMIK weekendwithmik Instagram Link - weekendwithmik?igsh=MXI2dml6ZjBrYzJidA & In this video we will try to solve an easy problem : Lemonade Change | Leetcode 860 | codestorywithMIK I will explain the intuitio...
Find K-th Smallest Pair Distance | Multiple Approaches | Leetcode 719 | codestorywithMIK
Переглядів 11 тис.День тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 31st Video of our Playlist "Binary Search : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a very good Problem on Binary Search on Answer topic : Find K-th Smallest Pair Distance | Multiple Approaches | Leetcode 719 | codestorywithMIK I will explain the intuition so easily...
Combination Sum II | Simple Khandani Template | Leetcode 40 | codestorywithMIK
Переглядів 8 тис.День тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 16th Video of our Playlist "Backtracking : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a simple Backtracking Problem : Combination Sum II | Simple Khandani Template | Easy Code | Leetcode 40 | codestorywithMIK I will explain the intuition so easily that you will never f...
Minimum Number of Days to Disconnect Island | Studied Concept | Leetcode 1568 | codestorywithMIK
Переглядів 11 тис.14 днів тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 103rd Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a simple 2D Array Problem : Minimum Number of Days to Disconnect Island | Already Studied Concept | Easy Code | Leetcode 1568 | codestorywithMIK This can be more efficiently solved us...
Regions Cut By Slashes | Already Studied Concept | Easy Code | Leetcode 959 | codestorywithMIK
Переглядів 10 тис.14 днів тому
Whatsapp Community Link : www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 102nd Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a simple 2D Array Problem : Regions Cut By Slashes | Already Studied Concept | Easy Code | Leetcode 959 | codestorywithMIK I will explain the intuition so easily that you will never f...
Magic Squares In Grid | Simple Approach | Clean Code | Leetcode 840 | codestorywithMIK
Переглядів 8 тис.14 днів тому
Magic Squares In Grid | Simple Approach | Clean Code | Leetcode 840 | codestorywithMIK
Spiral Matrix III | Simple Simulation | Made Easy | Leetcode 885 | codestorywithMIK
Переглядів 12 тис.14 днів тому
Spiral Matrix III | Simple Simulation | Made Easy | Leetcode 885 | codestorywithMIK
Integer to English Words | Story To Code | Leetcode 273 | codestorywithMIK
Переглядів 11 тис.14 днів тому
Integer to English Words | Story To Code | Leetcode 273 | codestorywithMIK
Range Sum of Sorted Subarray Sums | Learning Something New | Leetcode 1508 | codestorywithMIK
Переглядів 9 тис.21 день тому
Range Sum of Sorted Subarray Sums | Learning Something New | Leetcode 1508 | codestorywithMIK
Make Two Arrays Equal by Reversing Subarrays | Easy | Leetcode 1460 | codestorywithMIK
Переглядів 3,9 тис.21 день тому
Make Two Arrays Equal by Reversing Subarrays | Easy | Leetcode 1460 | codestorywithMIK
Minimum Swaps to Group All 1's Together II | 2 Ways | Dry Runs | Leetcode 2134 | codestorywithMIK
Переглядів 10 тис.21 день тому
Minimum Swaps to Group All 1's Together II | 2 Ways | Dry Runs | Leetcode 2134 | codestorywithMIK
Filling Bookcase Shelves | Recursion Memoization | Why not Greedy | Leetcode 1105 | codestorywithMIK
Переглядів 11 тис.21 день тому
Filling Bookcase Shelves | Recursion Memoization | Why not Greedy | Leetcode 1105 | codestorywithMIK
Minimum Deletions to Make String Balanced | Multiple Approaches | Leetcode 1653 | codestorywithMIK
Переглядів 9 тис.21 день тому
Minimum Deletions to Make String Balanced | Multiple Approaches | Leetcode 1653 | codestorywithMIK
Count Number of Teams | Simple thought process | Intuition | Leetcode 1395
Переглядів 9 тис.28 днів тому
Count Number of Teams | Simple thought process | Intuition | Leetcode 1395
Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045
Переглядів 8 тис.28 днів тому
Second Minimum Time to Reach Destination | 2 Approaches | FULL DRY RUN | Leetcode 2045
Find the City With the Smallest Number of Neighbors at a Threshold Distance | 3 Ways | Leetcode 1334
Переглядів 7 тис.Місяць тому
Find the City With the Smallest Number of Neighbors at a Threshold Distance | 3 Ways | Leetcode 1334
Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
Переглядів 6 тис.Місяць тому
Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
Переглядів 3,9 тис.Місяць тому
Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
Переглядів 7 тис.Місяць тому
Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
Переглядів 1,5 тис.Місяць тому
Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
Переглядів 7 тис.Місяць тому
Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK
Переглядів 1,7 тис.Місяць тому
Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK

КОМЕНТАРІ

  • @justanuhere
    @justanuhere 42 хвилини тому

    class Solution { public boolean predictTheWinner(int[] nums) { int total=0; for(int num:nums)total+=num; int [][]dp=new int[nums.length][nums.length]; for(int []arr:dp)Arrays.fill(arr,-1); int p1=recursion(0,nums.length-1,nums,true,dp); int p2=total-p1; return p1>p2; } public int recursion(int start,int end,int []piles,boolean p1,int [][]dp) { if(start>end)return 0; if(dp[start][end]!=-1)return dp[start][end]; if(p1){ int stTake=piles[start]+recursion(start+1,end,piles,false,dp); int endTake=piles[end]+recursion(start,end-1,piles,false,dp); dp[start][end]=Math.max(stTake,endTake); } else{ int stTake=piles[start]+recursion(start+1,end,piles,true,dp); int endTake=piles[end]+recursion(start,end-1,piles,true,dp); dp[start][end]=Math.min(stTake,endTake); } return dp[start][end]; } } can anyone tell me why this doesnt work for this problem?

  • @nishantdehariya5769
    @nishantdehariya5769 Годину тому

    class Solution { public: vector<vector<int>> dpInc; vector<vector<int>> dpDec; int calculateInc(vector<int>& rating, int idx,int count) { if (count == 2) { return 1; } if(idx>=rating.size()) return 0; if(dpInc[idx][count] != -1) { return dpInc[idx][count]; } int total = 0; for (int i = idx+1; i < rating.size(); i++) { if (rating[idx] < rating[i]) { total +=calculateInc(rating, i, count+1); } } return dpInc[idx][count]=total; } int calculateDec(vector<int>& rating, int idx,int count) { if (count == 2) { return 1; } if(idx>=rating.size()) return 0; if(dpDec[idx][count] != -1) { return dpDec[idx][count]; } int total = 0; for (int i = idx+1; i < rating.size(); i++) { if (rating[idx] > rating[i]) { total +=calculateDec(rating, i, count+1); } } return dpDec[idx][count]=total; } int numTeams(vector<int>& rating) { dpInc.resize(rating.size(),vector<int>(4,-1)); dpDec.resize(rating.size(),vector<int>(4,-1)); int ans = 0; for(int i=0;i<rating.size();i++) { ans +=calculateInc(rating, i, 0) + calculateDec(rating,i,0); } return ans; } };

  • @sahilshrivastava6455
    @sahilshrivastava6455 2 години тому

    I guess space complexity is O(N)

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 3 години тому

  • @__h__-
    @__h__- 3 години тому

    Congratulations 👏.

  • @ManishKumar-uc1rw
    @ManishKumar-uc1rw 4 години тому

    Rank teams by vote wale questions me doubt ek video uspar banao na pls sir

  • @user-ih4jr8iz2q
    @user-ih4jr8iz2q 4 години тому

    sir please make video on minimum number of operations to make string sorted

  • @cgoxo
    @cgoxo 5 годин тому

    Bhai maza aa gaya kya solution samjhaya hai

  • @shabananoor9423
    @shabananoor9423 5 годин тому

    ❤❤❤

  • @mind-010
    @mind-010 7 годин тому

    Bhaiya, what's the reason to have a array size of "n + 1" in bottom-up approach?? How can we find whether to have a "n" sized array or "n + 1" sized array ? By the way, very well explained ❤

  • @SanjeevKumar-xv5lw
    @SanjeevKumar-xv5lw 9 годин тому

    hard one becomes easy :) when it's @CodestorywithMIK!!! definitely one day you will be the king in DSA world.

  • @simnidhnidh9122
    @simnidhnidh9122 9 годин тому

    can i directly jump to sliding window soln and skipping that binary wala sol becoz that seems to be difficult?

  • @paglikadamad7574
    @paglikadamad7574 12 годин тому

    Thank you ❤, your explanation skill is simply amazing. The problems others are struggling in making understandable, you made it very easy. Once again, thank you ❤.

  • @deadxgaming1405
    @deadxgaming1405 13 годин тому

    It was a hard problem but clearly explained ❤

  • @SimarjeetKaur-h4x
    @SimarjeetKaur-h4x 13 годин тому

    Level of explaination is top-notch.. Thanku Sir😊

  • @adityamittal7335
    @adityamittal7335 14 годин тому

    smjh nahi aaya aaj bhai

    • @codestorywithMIK
      @codestorywithMIK 14 годин тому

      Would you kindly share where you lost me ? I will try my best to add more clarity here ❤️

  • @deepaksingh091
    @deepaksingh091 14 годин тому

    Kabhi Kabhi lagta hai => Apun hi bhagwan hai .❌ Kabhi Kabhi lagta hai => Apse DSA samajkar , Apun Dhanya ho gaya.✅

  • @abhi__shek__
    @abhi__shek__ 15 годин тому

    Starting this on 26th August 2024..

  • @prathmeshkakde3731
    @prathmeshkakde3731 15 годин тому

    Mere gharwalo ne bola tha bas itni si salary ,aur baki relatives se compare kiyq jaise dekh uska beta 1 lakh kama rha tu aur tu dekh ,kuch kr nahi paya ....😢not everyone parent is same some are mean and dumb like mine

    • @smitpatel9275
      @smitpatel9275 14 годин тому

      Have a big heart bro ❤️, You got this 👍

  • @abhishekkesharwani7453
    @abhishekkesharwani7453 15 годин тому

    It gives TLE when implementing in java

  • @gui-codes
    @gui-codes 16 годин тому

    Respect <3

  • @ayansikari6281
    @ayansikari6281 17 годин тому

    Bhaiya with the help of your video soon I will be placed and I will reach out to you to tell my steps ....

  • @iamnottech8918
    @iamnottech8918 20 годин тому

    using 1 map class Solution { public: bool isIsomorphic(string s, string t) { unordered_map<char, char> mpp; // length same given int i = 0; while (i < s.length()) { if (mpp.find(s[i]) == mpp.end()) // not there { for (const auto& pair : mpp) { // as actual mapp is {key ,val} pair if (pair.second == t[i]) { return false; } } mpp[s[i]] = t[i]; } else if (mpp.find(s[i]) != mpp.end()) // there { // if already presmt and now we got different val if (mpp[s[i]] != t[i]) // value was not as expected then not isomorphic return false; } i++; } return true; } };

  • @SriHarshaChilakapati
    @SriHarshaChilakapati 21 годину тому

    In October 1990, my dad got his first salary of 400 rupees as a trainee. He kept them in a cover, and he never used it. He kept that first cover as a token of memory and spent the entire first month without making any expenditure at all (company took care of food and hostel during training). I joined my first paid internship in December 2017, and in January, when I got paid (₹16000), I did the same. I took a bank statement with this record (didn't dare to withdraw because of the recently happened demonetization though), and kept it in a cover. It's now right next to my dad's cover back home. I spent the money on saree for mom and a shirt and formal pants for dad, but I decided to keep that amount in my bank always.

  • @ITG-xd5mk
    @ITG-xd5mk 21 годину тому

    You are really a gem I am studying for my interview right now with your channel.... waiting for the day when I will take my parents to dinner with my first income and give all my 1st month salary to them ❤

  • @akmarkan2490
    @akmarkan2490 22 години тому

    Incredible Brother🫶🏻

  • @user-zc3bd2fc9s
    @user-zc3bd2fc9s 22 години тому

    I bought my mom her favourite sweet with my first salary. I still have a picture of her eating that sweet. Will cherish it forever

  • @floatingpoint7629
    @floatingpoint7629 23 години тому

    @MIK playlist kab aye gi?

  • @souravkumar7612
    @souravkumar7612 23 години тому

    ❤❤❤

  • @priyanshukumarsah2746
    @priyanshukumarsah2746 23 години тому

    Like you , I will also pay my education loan debt and will feel that feeling like you did. ❤

  • @anjanasahay2172
    @anjanasahay2172 23 години тому

    Yeah The Education Loan ❤❤

  • @sauravranjan3537
    @sauravranjan3537 День тому

    Wooooow....just woww.....i watched this video and boom...i coded my self..thank u mik

  • @KishanSingh-vc3re
    @KishanSingh-vc3re День тому

    why the following approach didnt work : class Solution { public: int maximumRequests(int n, vector<vector<int>>& requests) { vector<int>in(n,0); vector<int>out(n,0); for(auto & it:requests){ int from = it[0]; int to = it[1]; in[from]++; out[to]++; } int cnt=0; for(int i=0; i<n; i++){ cnt+= min(in[i], out[i]); } return cnt; } };

  • @Singh_5454
    @Singh_5454 День тому

    Bhaiya preorder and post order ka bhi code comment me reply kr do please

  • @manimanohar_001
    @manimanohar_001 День тому

    I tried to solve this question by myself. I tried for 2 days but finally I lost to this question & had to see you video.😢