Uncommon Words from Two Sentences
Function Name: findUncommonWords
Description
Write a function named `findUncommonWords` that takes two strings `sentence1` and `sentence2`, which represent sentences composed of lowercase English letters and spaces (the spaces separate the words in the sentence).
The function should return a list of the words that are uncommon in both sentences. A word is uncommon if it appears exactly once in one of the sentences and does not appear in the other sentence.
The final list of uncommon words should not be in any particular order.
Requirements
- The function should take two parameters -- both are non-empty strings.
- The strings only contain lowercase English letters and spaces.
- The function should return a list of strings.
- There should be no punctuation in the sentences, only words separated by single spaces.
- Words are case-sensitive, meaning 'hello' and 'Hello' should be considered different words.
- The order of the words in the output list does not matter.
Examples
Given `sentence1 = 'the quick'` and `sentence2 = 'brown fox'`, the function should return `['the', 'quick', 'brown', 'fox']`.Given `sentence1 = 'the tortoise beat the hare'` and `sentence2 = 'the tortoise lost to the hare'`, the function should return `['beat', 'lost', 'to']`.Given `sentence1 = 'copper coffee pot'` and `sentence2 = 'hot coffee pot'`, the function should return `['copper', 'hot']`.
Links
Merge Intervals
Fri Dec 13 2024
Write a function 'mergeIntervals' that takes an array of intervals where each interval is represented as an array of two integers, and the intervals are sorted in ascending order based on the start of each interval. The function should merge all overlapping intervals and return an array of the resulting non-overlapping intervals sorted in ascending order.
Subarray Sum Equals K
Sun Dec 15 2024
Write a function named 'subarraySum' that takes in an array of integers and an integer 'k', and returns the number of continuous subarrays whose sum equals to 'k'.