Count Unique Characters of All Substrings of a Given String | Leetcode 828

preview_player
Показать описание
This video explains a very important interview problem which is to Count Unique Characters of All Substrings of a Given String. This problem is a common Amazon, Microsoft interview problem. It is based on counting unique characters in all substrings of a string.
CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

======================================PLEASE DONATE=============================
==============================================================================

=======================================================================
USEFUL LINKS:

RELATED LINKS:

Рекомендации по теме
Комментарии
Автор

After struggling for hours with text solutions, finally understood it from this beautiful explanation.

anuragkhugshal
Автор

Very good and planned explanation., Understood in a shot

akhilkumarp
Автор

Your teaching style is awesome. Keep up the good work.

lapujain
Автор

Thank you, your explanation was very easy to understand. You made a difficult problem somewhat easy, at least "medium".

RajiurRahman
Автор

Thank you so much! Very well explained!

cunghocthuattoan
Автор

idea is:
Find contribution of each char in string
eg. ABCABDA
here we see A at starting: putting A in middle
Check LHS size = 1 & RHS side (as long as A is unique) 4
Doing 1*4 = 4 (gives contribution of first A)
Similarlily, do rest all chars and add up at the end!

How do we know this? Observation & Dry run to check!

Approach---
Create a MAP (for constant time lookup) of vector of occurence
A-> 0-3-6
B-> 1-4
C-> 2
D-> 5
Now, do add -1 before each vec and n after each vec in map
So that when we check for each occurence (since we know index)
we can do e.g.[0], 0-(-1) * (3-0) = 1
and for [6], (6-3)* (n-6) = 3*1 = 3
and [3], (3-0)*(6-3) = 3*3 = 9
ADDING UP, 1+3+9 = 13

phantom
Автор

Very Good Explanation!
how's the time complexity O(N)?
we have a list of list and for each list we count.
isn't it a time complexity near to O(N^2)?

priyadarshinir
Автор

what is the name of the software you are using?

danielaviv
Автор

Avoid Flood In The City
please please please
explain this problem
why everyone is getting TLE ?
please please please

hhcdghjjgsdrt
Автор

This is a master piece thank you so much!

tien