Counting Words With a Given Prefix | Brute Force | Trie | Leetcode 2185 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
Trie Playlist - • Word Search II (Google, Amazon, Meta,...
Hi Everyone, this is the 9th video of our Playlist "Trie : Popular Interview Problems".
Now we will be solving a good practice problem based on Trie and string - Counting Words With a Given Prefix | Brute Force | Trie | Leetcode 2185 | codestorywithMIK
Since this is a fairly small problem, hence I will also code it in Java in the video itself. Hope that helps.
Problem Name : Counting Words With a Given Prefix | Brute Force | Trie | Leetcode 2185 | codestorywithMIK
Company Tags : Will update later
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Trie/Counting Words With a Given Prefix.cpp
Leetcode Link : https://leetcode.com/problems/counting-words-with-a-given-prefix
My DP Concepts Playlist : • Roadmap for DP | How to Start DP ? | ...
My Graph Concepts Playlist : • Graph Concepts & Qns - 1 : Graph will...
My Segment Tree Concepts Playlist : • Segment Tree | Introduction | Basics ...
My Recursion Concepts Playlist : • Introduction | Recursion Concepts And...
Trie Playlist - • Word Search II (Google, Amazon, Meta,...
Difference Array Technique: Concepts & Qns : • Introduction | What | How | Differenc...
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 : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
Video Summary :
Approach 1: Brute Force
This approach iterates through all the words and checks if each word starts with the given prefix using find(). If a match is found, the count is incremented.
Time Complexity: O(n⋅m), where n is the number of words and m is the prefix length.
Space Complexity: O(1).
Approach 2: Using Trie
This approach builds a Trie data structure where each node stores the count of words passing through it. After constructing the Trie, it efficiently retrieves the count of words with the given prefix by traversing the prefix path.
Time Complexity: O(n⋅l+m), where l is the average word length and m is the prefix length.
Space Complexity: O(n⋅l), for storing the Trie.
✨ Timelines✨
00:00 - Introduction
00:22 - Motivation
01:32 - Problem Explanation
02:19 - Brute Force using find() or substr()
04:31- Using Trie
16:49 - Coding in C++
26:07 - Coding in JAVA
#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