Coding Interview Patterns Z Algorithm - Matching Patterns in A String

This is the first video in Series of Patterns we encounter during Leetcode Weekly and Biweekly Contests.
In this video, we cover Z Algorithm - A String Matching Algorithm which is famous and helps solve a lot of string related problems.
Code of Z Algorithm: ideone.com/bOv5J4
More problems to practice
Longest Happy Prefix: leetcode.com/problems/longest...
Password: codeforces.com/contest/126/pr...
Connect on Insta: / bharatkhanna1995
Connect on Linkedin: / bharat-khanna-717b4817b
00:00-3:43 String Matching Problem and Brute Force way
3:44-7:04 Z Array and what it stores?
7:05-9:56 O(N^2) way to calculate Z Array
9:57-14:28 Optimising to O(N) - Major idea
14:29-17:00 Major idea code for Z
17:01-22:23 Optimising - What if less characters match?
22:24-29:23 Optimising - What if more characters match?
29:24-30:52 Using Z array for String matching
30:53-36:55 Code

Пікірлер: 28

  • @Tenebrous-le6yt
    @Tenebrous-le6ytКүн бұрын

    Such a perfect explanation! Not even the top Competitive Programmers explained the algorithm this easily.

  • @terabaap1775
    @terabaap17757 күн бұрын

    all other videos I have seen on this algorithm were very confusing but you are the only one who has explained this so well. thank you so much!

  • @JIGARSINGTHAKOR-yy6qp
    @JIGARSINGTHAKOR-yy6qp3 күн бұрын

    awesome explaination

  • @mainwhihoon
    @mainwhihoon2 ай бұрын

    Only ones who understand the algorithm themselves can explain it this well. Kudos Bharat, very well done video. So nicely explained!!

  • @CodingwithBharat

    @CodingwithBharat

    2 ай бұрын

    Thanks man!

  • @Dontpushyour_luck
    @Dontpushyour_luck4 ай бұрын

    Nice explanation. I coded it myself after you explained the approach, without seeing your code. Hope to see more string matching algo videos from you

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    Great! Will plan it out ✌️

  • @mavishhaq5864
    @mavishhaq58644 ай бұрын

    Thank you so much for the video.

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    ✌️✌️

  • @Harmless_creature
    @Harmless_creature2 ай бұрын

    Great explanation

  • @CodingwithBharat

    @CodingwithBharat

    2 ай бұрын

    Thanks!

  • @chetan.s.bandurkar2690
    @chetan.s.bandurkar26904 ай бұрын

    must needed video bhaiya ,because in past contest ,,there were direct question on z-function and i was unable to understand it.thanks

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    Keep coding Chetan! 🫡

  • @vyomgoyal3125
    @vyomgoyal31254 ай бұрын

    Bhaiya please make dedicated videos on KMP and Rabin Karp as well Your method of explanation is very good. Also is Boyer Moore Algorithm for Pattern Searching used in contest?

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    Hi Vyom! Thanks and yes will make those too. Regarding Boyer Moore Voting Algorithm, that is a different technique.

  • @vyomgoyal3125

    @vyomgoyal3125

    4 ай бұрын

    I am talking about Booyer Moore String Matching Algorithm

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    @@vyomgoyal3125Oh! Yeah that is not common one to be asked.

  • @vyomgoyal3125

    @vyomgoyal3125

    4 ай бұрын

    @@CodingwithBharat Ok Thanks

  • @piyushsrivastava5883
    @piyushsrivastava58834 ай бұрын

    Thanks a lot

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    ✌️

  • @ArpitMarkana
    @ArpitMarkanaАй бұрын

    Good Explanation

  • @CodingwithBharat

    @CodingwithBharat

    Ай бұрын

    Thanks

  • @architroychoudhury5466
    @architroychoudhury54664 ай бұрын

    Thank you for the explanation. Can you please make videos on KMP and Rabin Karp too please

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    Yes will plan to.

  • @Cools74
    @Cools744 ай бұрын

    Please make video on kmp algorithm also 🙏

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    Sure

  • @aniketsharma5003
    @aniketsharma50034 ай бұрын

    A lil bouncer for me, will use the code for zMatch in the questions where pattern$string can be use ( for the time being, samgh ni aata )

  • @CodingwithBharat

    @CodingwithBharat

    4 ай бұрын

    What parts got confusing?