diff --git a/LeetCode.xcodeproj/project.pbxproj b/LeetCode.xcodeproj/project.pbxproj index 81dccf1..c37c9c1 100644 --- a/LeetCode.xcodeproj/project.pbxproj +++ b/LeetCode.xcodeproj/project.pbxproj @@ -66,6 +66,14 @@ 498B5C502C1062F700B2DC79 /* StringCompression.swift in Sources */ = {isa = PBXBuildFile; fileRef = 498B5C4E2C1062F700B2DC79 /* StringCompression.swift */; }; 498B5C532C107BC600B2DC79 /* FindCommonCharacters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 498B5C522C107BC600B2DC79 /* FindCommonCharacters.swift */; }; 498B5C542C107BC600B2DC79 /* FindCommonCharacters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 498B5C522C107BC600B2DC79 /* FindCommonCharacters.swift */; }; + 4992C5242C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C5232C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift */; }; + 4992C5252C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C5232C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift */; }; + 4992C5292C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C5282C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift */; }; + 4992C52A2C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C5282C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift */; }; + 4992C52D2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C52C2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift */; }; + 4992C52E2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C52C2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift */; }; + 4992C5312C170E9900E16FCF /* HeightChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C5302C170E9900E16FCF /* HeightChecker.swift */; }; + 4992C5322C170E9900E16FCF /* HeightChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4992C5302C170E9900E16FCF /* HeightChecker.swift */; }; 499763162BFF8181009D6EF5 /* BenchTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 495D40482BFC94DC00ECFC81 /* BenchTimer.swift */; }; 499763172BFF8181009D6EF5 /* TreeNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 495D404C2BFC960B00ECFC81 /* TreeNode.swift */; }; 499763182BFF8181009D6EF5 /* Node.swift in Sources */ = {isa = PBXBuildFile; fileRef = 495D404E2BFC965F00ECFC81 /* Node.swift */; }; @@ -178,6 +186,10 @@ 498B5C4A2C1061DE00B2DC79 /* IncreasingTripletSubsequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IncreasingTripletSubsequence.swift; sourceTree = ""; }; 498B5C4E2C1062F700B2DC79 /* StringCompression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringCompression.swift; sourceTree = ""; }; 498B5C522C107BC600B2DC79 /* FindCommonCharacters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FindCommonCharacters.swift; sourceTree = ""; }; + 4992C5232C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaximumNumberOfVowelsInSubstringOfGivenLength.swift; sourceTree = ""; }; + 4992C5282C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaxConsecutiveOnesIII.swift; sourceTree = ""; }; + 4992C52C2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongestSubarrayOf1sAfterDeletingOneElement.swift; sourceTree = ""; }; + 4992C5302C170E9900E16FCF /* HeightChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeightChecker.swift; sourceTree = ""; }; 499762E92BFF8031009D6EF5 /* LeetCode75 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = LeetCode75; sourceTree = BUILT_PRODUCTS_DIR; }; 499762EB2BFF8031009D6EF5 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 499762F42BFF809E009D6EF5 /* LeetCode75_UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LeetCode75_UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -272,6 +284,7 @@ 49EC4CBB2C06082900D68CF9 /* 876. Middle of the Linked List */, 49EC4CC12C06096800D68CF9 /* 949. Largest Time for Given Digits */, 498B5C512C107BB500B2DC79 /* 1002. Find Common Characters */, + 4992C52F2C170E8B00E16FCF /* 1051. Height Checker */, 49EC4CC32C06096800D68CF9 /* 1480. Running Sum of 1d Array */, ); path = Easy; @@ -510,6 +523,38 @@ path = "1002. Find Common Characters"; sourceTree = ""; }; + 4992C5222C14AB7300E16FCF /* 1456. Maximum Number of Vowels in a Substring of Given Length */ = { + isa = PBXGroup; + children = ( + 4992C5232C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift */, + ); + path = "1456. Maximum Number of Vowels in a Substring of Given Length"; + sourceTree = ""; + }; + 4992C5262C16FD9900E16FCF /* 1004. Max Consecutive Ones III */ = { + isa = PBXGroup; + children = ( + 4992C5282C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift */, + ); + path = "1004. Max Consecutive Ones III"; + sourceTree = ""; + }; + 4992C52B2C16FF0000E16FCF /* 1493. Longest Subarray of 1's After Deleting One Element */ = { + isa = PBXGroup; + children = ( + 4992C52C2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift */, + ); + path = "1493. Longest Subarray of 1's After Deleting One Element "; + sourceTree = ""; + }; + 4992C52F2C170E8B00E16FCF /* 1051. Height Checker */ = { + isa = PBXGroup; + children = ( + 4992C5302C170E9900E16FCF /* HeightChecker.swift */, + ); + path = "1051. Height Checker"; + sourceTree = ""; + }; 499762EA2BFF8031009D6EF5 /* LeetCode75 */ = { isa = PBXGroup; children = ( @@ -565,6 +610,9 @@ 49B703632C0F106C0005B3D4 /* 238. Product of Array Except Self */, 498B5C492C1061BB00B2DC79 /* 334. Increasing Triplet Subsequence */, 498B5C4D2C1062E800B2DC79 /* 443. String Compression */, + 4992C5262C16FD9900E16FCF /* 1004. Max Consecutive Ones III */, + 4992C5222C14AB7300E16FCF /* 1456. Maximum Number of Vowels in a Substring of Given Length */, + 4992C52B2C16FF0000E16FCF /* 1493. Longest Subarray of 1's After Deleting One Element */, 49450F762C11828B0036A167 /* 1679. Max Number of K-Sum Pairs */, ); path = Medium; @@ -907,6 +955,7 @@ 49450F802C11AE370036A167 /* LongTestCases.swift in Sources */, 49E202562C04E623005D75E9 /* NAryTreePreorderTraversal.swift in Sources */, 49EC4CC42C06096900D68CF9 /* LargestTimeForGivenDigits.swift in Sources */, + 4992C5312C170E9900E16FCF /* HeightChecker.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -926,6 +975,7 @@ 49E202592C04E623005D75E9 /* LongestPalindrome.swift in Sources */, 495D40FE2BFCBBBE00ECFC81 /* BenchTimer.swift in Sources */, 495511A02C12FCBB004BCD04 /* ReplaceWords.swift in Sources */, + 4992C5322C170E9900E16FCF /* HeightChecker.swift in Sources */, 49450F812C11AE370036A167 /* LongTestCases.swift in Sources */, 495D40FF2BFCBBBE00ECFC81 /* TreeNode.swift in Sources */, 490BB3652C0F441B0026F70C /* MaximizeDistanceToClosestPerson.swift in Sources */, @@ -961,6 +1011,7 @@ 49EC4CF62C06115C00D68CF9 /* MergeStringsAlternately.swift in Sources */, 49B703662C0F10830005B3D4 /* ProductOfArrayExceptSelf.swift in Sources */, 498B5C4F2C1062F700B2DC79 /* StringCompression.swift in Sources */, + 4992C52D2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift in Sources */, 4955119B2C12FC87004BCD04 /* TrieNode.swift in Sources */, 49EC4CD62C060E0D00D68CF9 /* IsSubsequence.swift in Sources */, 4973991A2C0E0DFC003031AA /* SingleNumber.swift in Sources */, @@ -968,6 +1019,7 @@ 49B331292C09AE6600BC47D8 /* NthTribonacciNumber.swift in Sources */, 499763192BFF8181009D6EF5 /* ListNode.swift in Sources */, 49EC4CEE2C06102E00D68CF9 /* GreatestCommonDivisorOfStrings.swift in Sources */, + 4992C5292C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift in Sources */, 49EC4CEC2C06102E00D68CF9 /* KidsWithTheGreatestNumberOfCandies.swift in Sources */, 49DA51162C08B1D30062A064 /* GuessNumberHigherOrLower.swift in Sources */, 49450F782C1182A70036A167 /* MaxNumberOfKSumPairs.swift in Sources */, @@ -978,6 +1030,7 @@ 49450F742C117FE90036A167 /* ContainerWithMostWater.swift in Sources */, 490BD5822C0721AC003AE043 /* MaximumDepthOfBinaryTree.swift in Sources */, 49B703612C0EFAAF0005B3D4 /* ReverseWordsInString.swift in Sources */, + 4992C5242C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift in Sources */, 49EC4CE22C060F1F00D68CF9 /* MaximumAverageSubarrayI.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1002,12 +1055,14 @@ 49EC4CFB2C06115C00D68CF9 /* FindTheDifferenceOfTwoArrays.swift in Sources */, 4973991B2C0E0DFC003031AA /* SingleNumber.swift in Sources */, 490119312C087DD0009ADEC2 /* SearchInBinarySearchTree.swift in Sources */, + 4992C52A2C16FDAC00E16FCF /* MaxConsecutiveOnesIII.swift in Sources */, 4997631D2BFF8181009D6EF5 /* ListNode.swift in Sources */, 49450F832C11AE370036A167 /* LongTestCases.swift in Sources */, 49EC4CF92C06115C00D68CF9 /* FindTheHighestAltitude.swift in Sources */, 4955119C2C12FC87004BCD04 /* TrieNode.swift in Sources */, 49EC4CCD2C060CAA00D68CF9 /* ReverseLinkedList.swift in Sources */, 4912C7AE2C09CBBA00DEB016 /* MinCostClimbingStairs.swift in Sources */, + 4992C52E2C16FF2300E16FCF /* LongestSubarrayOf1sAfterDeletingOneElement.swift in Sources */, 490BD5832C0721AC003AE043 /* MaximumDepthOfBinaryTree.swift in Sources */, 490BD57F2C071DB7003AE043 /* NumberOfRecentCalls.swift in Sources */, 49DA51172C08B1D30062A064 /* GuessNumberHigherOrLower.swift in Sources */, @@ -1015,6 +1070,7 @@ 49450F792C1182A70036A167 /* MaxNumberOfKSumPairs.swift in Sources */, 497399172C0DBA1A003031AA /* CountingBits.swift in Sources */, 49EC4CF72C06115C00D68CF9 /* MergeStringsAlternately.swift in Sources */, + 4992C5252C14AB8900E16FCF /* MaximumNumberOfVowelsInSubstringOfGivenLength.swift in Sources */, 498B5C4C2C1061DE00B2DC79 /* IncreasingTripletSubsequence.swift in Sources */, 49450F752C117FE90036A167 /* ContainerWithMostWater.swift in Sources */, 498B5C502C1062F700B2DC79 /* StringCompression.swift in Sources */, diff --git a/LeetCode100/Easy/1051. Height Checker/HeightChecker.swift b/LeetCode100/Easy/1051. Height Checker/HeightChecker.swift new file mode 100644 index 0000000..a40eeea --- /dev/null +++ b/LeetCode100/Easy/1051. Height Checker/HeightChecker.swift @@ -0,0 +1,62 @@ +// +// HeightChecker.swift +// LeetCode +// +// Created by Artem Mayer on 10.06.2024. +// + +import Foundation + +// MARK: - 1051. Height Checker + +/// A school is trying to take an annual photo of all the students. The students are asked to stand in a single file line in non-decreasing order by height. Let this ordering be represented by the integer array expected where expected[i] is the expected height of the ith student in line. +/// +/// You are given an integer array heights representing the current order that the students are standing in. Each heights[i] is the height of the ith student in line (0-indexed). +/// +/// Return the number of indices where heights[i] != expected[i]. +/// +/// +/// **Example 1:** +/// ``` +/// Input: heights = [1,1,4,2,1,3] +/// Output: 3 +/// Explanation: +/// heights: [1,1,4,2,1,3] +/// expected: [1,1,1,2,3,4] +/// Indices 2, 4, and 5 do not match. +/// ``` +/// +/// **Example 2:** +/// ``` +/// Input: heights = [5,1,2,3,4] +/// Output: 5 +/// Explanation: +/// heights: [5,1,2,3,4] +/// expected: [1,2,3,4,5] +/// All indices do not match. +/// ``` +/// +/// **Example 3:** +/// ``` +/// Input: heights = [1,2,3,4,5] +/// Output: 0 +/// Explanation: +/// heights: [1,2,3,4,5] +/// expected: [1,2,3,4,5] +/// All indices match. +/// ``` +/// +/// **Constraints:** +/// ``` +/// 1 <= heights.length <= 100 +/// 1 <= heights[i] <= 100 +/// ``` +final class HeightChecker_Solution { + + func heightChecker(_ heights: [Int]) -> Int { + heights.sorted() + .enumerated() + .reduce(into: 0, { if $1.element != heights[$1.offset] { $0 += 1 } }) + } + +} diff --git a/LeetCode100/main.swift b/LeetCode100/main.swift index d36d1b2..1d303ac 100644 --- a/LeetCode100/main.swift +++ b/LeetCode100/main.swift @@ -112,6 +112,13 @@ final class Solution { return solution.commonChars(words) } + // MARK: - 1051. Height Checker + + func heightChecker(_ heights: [Int]) -> Int { + let solution = HeightChecker_Solution() + return solution.heightChecker(heights) + } + // MARK: - 1480. Running Sum of 1d Array func runningSumOf1dArray(_ nums: [Int]) -> [Int] { diff --git a/LeetCode75/Medium/1004. Max Consecutive Ones III/MaxConsecutiveOnesIII.swift b/LeetCode75/Medium/1004. Max Consecutive Ones III/MaxConsecutiveOnesIII.swift new file mode 100644 index 0000000..420da25 --- /dev/null +++ b/LeetCode75/Medium/1004. Max Consecutive Ones III/MaxConsecutiveOnesIII.swift @@ -0,0 +1,59 @@ +// +// MaxConsecutiveOnesIII.swift +// LeetCode +// +// Created by Artem Mayer on 10.06.2024. +// + +import Foundation + +// MARK: - 1004. Max Consecutive Ones III + +/// Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's. +/// +/// +/// **Example 1:** +/// ``` +/// Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2 +/// Output: 6 +/// Explanation: [1,1,1,0,0,1,1,1,1,1,1] +/// Bolded numbers were flipped from 0 to 1. The longest subarray is underlined. +/// ``` +/// +/// **Example 2:** +/// ``` +/// Input: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3 +/// Output: 10 +/// Explanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1] +/// Bolded numbers were flipped from 0 to 1. The longest subarray is underlined. +/// ``` +/// +/// **Constraints:** +/// ``` +/// 1 <= nums.length <= 10⁵ +/// nums[i] is either 0 or 1. +/// 0 <= k <= nums.length +/// ``` +final class MaxConsecutiveOnesIII_Solution { + + func longestOnes(_ nums: [Int], _ k: Int) -> Int { + var k = k + var l = 0, r = 0 + + while r < nums.count { + if nums[r] == 0 { + k -= 1 + } + + if k < 0 { + k += 1 - nums[l] + l += 1 + } + + r += 1 + } + + return r - l + } + +} diff --git a/LeetCode75/Medium/1456. Maximum Number of Vowels in a Substring of Given Length/MaximumNumberOfVowelsInSubstringOfGivenLength.swift b/LeetCode75/Medium/1456. Maximum Number of Vowels in a Substring of Given Length/MaximumNumberOfVowelsInSubstringOfGivenLength.swift new file mode 100644 index 0000000..396ca37 --- /dev/null +++ b/LeetCode75/Medium/1456. Maximum Number of Vowels in a Substring of Given Length/MaximumNumberOfVowelsInSubstringOfGivenLength.swift @@ -0,0 +1,74 @@ +// +// MaximumNumberOfVowelsInSubstringOfGivenLength.swift +// LeetCode +// +// Created by Artem Mayer on 08.06.2024. +// + +import Foundation + +// MARK: - 1456. Maximum Number of Vowels in a Substring of Given Length + +/// Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length k. +/// +/// Vowel letters in English are 'a', 'e', 'i', 'o', and 'u'. +/// +/// +/// **Example 1:** +/// ``` +/// Input: s = "abciiidef", k = 3 +/// Output: 3 +/// Explanation: The substring "iii" contains 3 vowel letters. +/// ``` +/// +/// **Example 2:** +/// ``` +/// Input: s = "aeiou", k = 2 +/// Output: 2 +/// Explanation: Any substring of length 2 contains 2 vowels. +/// ``` +/// +/// **Example 3:** +/// ``` +/// Input: s = "leetcode", k = 3 +/// Output: 2 +/// Explanation: "lee", "eet" and "ode" contain 2 vowels. +/// ``` +/// +/// **Constraints:** +/// ``` +/// 1 <= s.length <= 10⁵ +/// s consists of lowercase English letters. +/// 1 <= k <= s.length +/// ``` +final class MaximumNumberOfVowelsInSubstringOfGivenLength_Soluton { + + func maxVowels(_ s: String, _ k: Int) -> Int { + var res = s[s.startIndex.. Int { + var k = 1 + var l = 0, r = 0 + + while r < nums.count { + if nums[r] == 0 { + k -= 1 + } + + if k < 0 { + k += 1 - nums[l] + l += 1 + } + + r += 1 + } + + return r - l - 1 + } + +} diff --git a/LeetCode75/main.swift b/LeetCode75/main.swift index de73e70..14d35f6 100644 --- a/LeetCode75/main.swift +++ b/LeetCode75/main.swift @@ -202,6 +202,27 @@ final class Solution { return solution.kidsWithCandies(candies, extraCandies) } + // MARK: - 1004. Max Consecutive Ones III + + func maxConsecutiveOnesIII(_ nums: [Int], _ k: Int) -> Int { + let solution = MaxConsecutiveOnesIII_Solution() + return solution.longestOnes(nums, k) + } + + // MARK: - 1456. Maximum Number of Vowels in a Substring of Given Length + + func maximumNumberOfVowelsInSubstringOfGivenLength(_ s: String, _ k: Int) -> Int { + let solution = MaximumNumberOfVowelsInSubstringOfGivenLength_Soluton() + return solution.maxVowels(s, k) + } + + // MARK: - 1493. Longest Subarray of 1's After Deleting One Element + + func longestSubarrayOf1sAfterDeletingOneElement(_ nums: [Int]) -> Int { + let solution = LongestSubarrayOf1sAfterDeletingOneElement_Solution() + return solution.longestSubarray(nums) + } + // MARK: - 1679. Max Number of K-Sum Pairs func maxNumberOfKSumPairs(_ nums: [Int], _ k: Int) -> Int { diff --git a/UnitTests/LeetCode100/LeetCode100.swift b/UnitTests/LeetCode100/LeetCode100.swift index dca4247..4324e6a 100644 --- a/UnitTests/LeetCode100/LeetCode100.swift +++ b/UnitTests/LeetCode100/LeetCode100.swift @@ -285,6 +285,22 @@ final class UnitTests: XCTestCase { XCTAssertEqual(solution.findCommonCharacters(case2).sorted(), case2Result) } + // MARK: - 1051. Height Checker + + func testHeightChecker() throws { + let case1 = [1, 1, 4, 2, 1, 3] + let case2 = [5, 1, 2, 3, 4] + let case3 = [1, 2, 3, 4, 5] + + let case1Result = 3 + let case2Result = 5 + let case3Result = 0 + + XCTAssertEqual(solution.heightChecker(case1), case1Result) + XCTAssertEqual(solution.heightChecker(case2), case2Result) + XCTAssertEqual(solution.heightChecker(case3), case3Result) + } + // MARK: - 1480. Running Sum of 1d Array func testRunningSumOf1dArray() throws { diff --git a/UnitTests/LeetCode75/LeetCode75.swift b/UnitTests/LeetCode75/LeetCode75.swift index d60a18f..3359059 100644 --- a/UnitTests/LeetCode75/LeetCode75.swift +++ b/UnitTests/LeetCode75/LeetCode75.swift @@ -579,6 +579,57 @@ final class UnitTests: XCTestCase { XCTAssertEqual(solution.kidsWithTheGreatestNumberOfCandies(case3.0, case3.1), case3Result) } + // MARK: - 1004. Max Consecutive Ones III + + func testMaxConsecutiveOnesIII() throws { + let case1 = ([1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0], 2) + let case2 = ([0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1], 3) + + let case1Result = 6 + let case2Result = 10 + + XCTAssertEqual(solution.maxConsecutiveOnesIII(case1.0, case1.1), case1Result) + XCTAssertEqual(solution.maxConsecutiveOnesIII(case2.0, case2.1), case2Result) + } + + // MARK: - 1456. Maximum Number of Vowels in a Substring of Given Length + + func testMaximumNumberOfVowelsInSubstringOfGivenLength() throws { + let case1 = ("abciiidef", 3) + let case2 = ("aeiou", 2) + let case3 = ("leetcode", 3) + let case4 = ("novowels", 1) + let case5 = ("rhythms", 4) + + let case1Result = 3 + let case2Result = 2 + let case3Result = 2 + let case4Result = 1 + let case5Result = 0 + + XCTAssertEqual(solution.maximumNumberOfVowelsInSubstringOfGivenLength(case1.0, case1.1), case1Result) + XCTAssertEqual(solution.maximumNumberOfVowelsInSubstringOfGivenLength(case2.0, case2.1), case2Result) + XCTAssertEqual(solution.maximumNumberOfVowelsInSubstringOfGivenLength(case3.0, case3.1), case3Result) + XCTAssertEqual(solution.maximumNumberOfVowelsInSubstringOfGivenLength(case4.0, case4.1), case4Result) + XCTAssertEqual(solution.maximumNumberOfVowelsInSubstringOfGivenLength(case5.0, case5.1), case5Result) + } + + // MARK: - 1493. Longest Subarray of 1's After Deleting One Element + + func testLongestSubarrayOf1sAfterDeletingOneElement() throws { + let case1 = [1, 1, 0, 1] + let case2 = [0, 1, 1, 1, 0, 1, 1, 0, 1] + let case3 = [1, 1, 1] + + let case1Result = 3 + let case2Result = 5 + let case3Result = 2 + + XCTAssertEqual(solution.longestSubarrayOf1sAfterDeletingOneElement(case1), case1Result) + XCTAssertEqual(solution.longestSubarrayOf1sAfterDeletingOneElement(case2), case2Result) + XCTAssertEqual(solution.longestSubarrayOf1sAfterDeletingOneElement(case3), case3Result) + } + // MARK: - 1679. Max Number of K-Sum Pairs func testMaxNumberOfKSumPairs() throws {