filmov
tv
Shortest Unique prefix for every word GeeksforGeeks Full explanation of line by line code | Trie
![preview_player](https://i.ytimg.com/vi/CB-WeyCFjlc/maxresdefault.jpg)
Показать описание
Timestamps:
0:00 What is the problem saying?
2:50 Building Solution
9:40 Example Walkthrough
12:00 Code
Given an array of words, find all shortest unique prefixes to represent each word in the given array. Assume that no word is prefix of another.
Example 1:
Input:
N = 4
arr[] = {"zebra", "dog", "duck", "dove"}
Output: z dog du dov
Example 2:
Input:
N = 3
arr[] = {"geeksgeeks", "geeksquiz",
"geeksforgeeks"};
Output: geeksg geeksq geeksf
Explanation:
Your task:
You don't have to read input or print anything. Your task is to complete the function findPrefixes() which takes the array of strings and it's size N as input and returns a list of shortest unique prefix for each word
Expected Time Complexity: O(N*length of each word)
Expected Auxiliary Space: O(N*length of each word)
Check out our other playlists:
Dynamic Programming:
Trees:
Heaps and Maps:
Arrays and Maths:
Bit Manipulation:
Greedy Algorithms:
Sorting and Searching:
Strings:
Linked Lists:
Stack and Queues:
Two Pointers:
Graphs, BFS, DFS:
Backtracking:
Non- DSA playlists:
Probability:
SQL-Basic Join functions:
SQL-Basic Aggregate functions:
0:00 What is the problem saying?
2:50 Building Solution
9:40 Example Walkthrough
12:00 Code
Given an array of words, find all shortest unique prefixes to represent each word in the given array. Assume that no word is prefix of another.
Example 1:
Input:
N = 4
arr[] = {"zebra", "dog", "duck", "dove"}
Output: z dog du dov
Example 2:
Input:
N = 3
arr[] = {"geeksgeeks", "geeksquiz",
"geeksforgeeks"};
Output: geeksg geeksq geeksf
Explanation:
Your task:
You don't have to read input or print anything. Your task is to complete the function findPrefixes() which takes the array of strings and it's size N as input and returns a list of shortest unique prefix for each word
Expected Time Complexity: O(N*length of each word)
Expected Auxiliary Space: O(N*length of each word)
Check out our other playlists:
Dynamic Programming:
Trees:
Heaps and Maps:
Arrays and Maths:
Bit Manipulation:
Greedy Algorithms:
Sorting and Searching:
Strings:
Linked Lists:
Stack and Queues:
Two Pointers:
Graphs, BFS, DFS:
Backtracking:
Non- DSA playlists:
Probability:
SQL-Basic Join functions:
SQL-Basic Aggregate functions:
Комментарии