Posts

Showing posts with the label apple

583. Delete Operation for Two Strings

https://leetcode.com/problems/delete-operation-for-two-strings/description/ Given two strings  word1  and  word2 , return  the minimum number of  steps  required to make   word1   and   word2   the same . In one  step , you can delete exactly one character in either string.   Example 1: Input: word1 = "sea", word2 = "eat" Output: 2 Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea". Example 2: Input: word1 = "leetcode", word2 = "etco" Output: 4   Constraints: 1 <= word1.length, word2.length <= 500 word1  and  word2  consist of only lowercase English letters. --- Time - O(M * N) Space - O(M * N) --- ---- ----

916. Word Subsets

 https://leetcode.com/problems/word-subsets/description/ You are given two string arrays  words1  and  words2 . A string  b  is a  subset  of string  a  if every letter in  b  occurs in  a  including multiplicity. For example,  "wrr"  is a subset of  "warrior"  but is not a subset of  "world" . A string  a  from  words1  is  universal  if for every string  b  in  words2 ,  b  is a subset of  a . Return an array of all the  universal  strings in  words1 . You may return the answer in  any order .   Example 1: Input: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["e","o"] Output: ["facebook","google","leetcode"] Example 2: Input: words1 = ["amazon","apple","facebook","google","leetcode"], words2 = ["l","e"] Output: ["apple","google","leetco...

474. Ones and Zeroes

 https://leetcode.com/problems/ones-and-zeroes/description/ You are given an array of binary strings  strs  and two integers  m  and  n . Return  the size of the largest subset of  strs  such that there are  at most   m   0 's and  n   1 's in the subset . A set  x  is a  subset  of a set  y  if all elements of  x  are also elements of  y .   Example 1: Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3 Output: 4 Explanation: The largest subset with at most 5 0's and 3 1's is {"10", "0001", "1", "0"}, so the answer is 4. Other valid but smaller subsets include {"0001", "1"} and {"10", "1", "0"}. {"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3. Example 2: Input: strs = ["10","0","1"], m = 1, n = 1 Output: 2 Explanation: The largest subs...