From ee5e08cf9603684ef0230b222c85fee8e6f25c8f Mon Sep 17 00:00:00 2001 From: Yash Garg <72246420+yashgarg7302@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:15:50 +0530 Subject: [PATCH 1/2] Create _916 Solution for the leetcode daily question 916. Word Subsets --- cpp/_916 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 cpp/_916 diff --git a/cpp/_916 b/cpp/_916 new file mode 100644 index 0000000000..7ac4a644a1 --- /dev/null +++ b/cpp/_916 @@ -0,0 +1,34 @@ +class Solution { +public: + vector wordSubsets(vector& words1, vector& words2) { + int maxCharFreq[26] = {0}; + int tempCharFreq[26]; + for (const auto& word : words2) { + memset(tempCharFreq, 0, sizeof tempCharFreq); + for (char ch : word) { + tempCharFreq[ch - 'a']++; + } + for (int i = 0; i < 26; ++i) { + maxCharFreq[i] = max(maxCharFreq[i], tempCharFreq[i]); + } + } + vector universalWords; + for (const auto& word : words1) { + memset(tempCharFreq, 0, sizeof tempCharFreq); + for (char ch : word) { + tempCharFreq[ch - 'a']++; + } + bool isUniversal = true; + for (int i = 0; i < 26; ++i) { + if (maxCharFreq[i] > tempCharFreq[i]) { + isUniversal = false; + break; + } + } + if (isUniversal) { + universalWords.emplace_back(word); + } + } + return universalWords; + } +}; From 75a6154cd77c937bf1b7ed710349fb6a34a35467 Mon Sep 17 00:00:00 2001 From: Yash Garg <72246420+yashgarg7302@users.noreply.github.com> Date: Sun, 12 Jan 2025 23:05:18 +0530 Subject: [PATCH 2/2] Rename _916 to _916.cpp --- cpp/{_916 => _916.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cpp/{_916 => _916.cpp} (100%) diff --git a/cpp/_916 b/cpp/_916.cpp similarity index 100% rename from cpp/_916 rename to cpp/_916.cpp pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy