-
Notifications
You must be signed in to change notification settings - Fork 20
Solution #3306 - Mridul/Edited - 11/03/2025 #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Solution #3306 - Mridul/Edited - 11/03/2025 #27
Conversation
Initialization: | ||
|
||
n: Length of the word. | ||
|
||
freq: Array to store the frequency of each character. | ||
|
||
currConsonant: Counter for the current number of consonants in the substring. | ||
|
||
cnt: Counter for the valid substrings. | ||
|
||
left: Left pointer for the sliding window. | ||
|
||
Iterating through the word: | ||
|
||
For each character ch in the word: | ||
|
||
If ch is a consonant, increment currConsonant. | ||
|
||
Increment the frequency of ch in freq. | ||
|
||
Checking the conditions: | ||
|
||
While the current substring contains at least k consonants and all vowels: | ||
|
||
Increment cnt by the number of valid substrings ending at the current position. | ||
|
||
Move the left pointer to reduce the window size. | ||
|
||
Decrement the frequency of the character at the left pointer. | ||
|
||
If the character is a consonant, decrement currConsonant. | ||
|
||
This logic ensures that we count all substrings that meet the conditions specified in the problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you utilize the markdown like your other PR's? Also add time and space complexity + how this could be further optimized (if possible)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly make changes to the explanation.md file
added solution.java and explanation.md, please check.