Skip to content
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

Count the Number of Consistent Strings.java #3625

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shubhangdutta96
Copy link

@shubhangdutta96 shubhangdutta96 commented Sep 12, 2024

@shubhangdutta96
Copy link
Author

💡 Method to Count the Number of Consistent Strings

This PR introduces a solution for counting consistent strings in a list based on a given set of allowed characters. The main highlights of the code are:

  • Use of a HashSet: The allowed characters are stored in a HashSet for efficient lookups, ensuring O(1) time complexity for membership checks.

  • Two-pass Iteration:

    • First loop to populate the set with allowed characters.
    • Second loop iterates through each word in the array and checks if all characters of the word exist in the allowed set.
  • Efficient Flagging: A boolean flag is used to check the validity of each word. If any character is found outside the allowed set, the loop breaks early, optimizing the solution.

The logic is simple and clear, and the solution runs efficiently with O(n * m) complexity, where n is the number of words and m is the length of each word.

@Ykhan799
Copy link
Collaborator

@shubhangdutta96 Follow the Contributing guidelines on the naming standards for your solution. Once you fix it, I'll take another look at your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants