LeedCode
Problems
Two Pointers
18 remaining tasks
0125 - Valid Palindrome
Easy
0680 - Valid Palindrome II
Easy
1984 - Minimum Difference Between Highest And Lowest of K Scores
Easy
1768 - Merge Strings Alternately
Easy
0344 - Reverse String
Easy
0088 - Merge Sorted Array
Easy
0283 - Move Zeroes
Easy
0026 - Remove Duplicates From Sorted Array
Easy
0080 - Remove Duplicates From Sorted Array II
Easy
0167 - Two Sum II Input Array Is Sorted
Easy
0015 - 3Sum
Easy
0018 - 4Sum
Easy
0011 - Container With Most Water
Easy
1498 - Number of Subsequences That Satisfy The Given Sum Condition
Easy
0189 - Rotate Array
Easy
1968 - Array With Elements Not Equal to Average of Neighbors
Easy
0881 - Boats to Save People
Easy
0042 - Trapping Rain Water
Easy
1768 - Merge Strings Alternately
Easy
Javascript
Code
// Time complexity: O(n)
// Space complexity: O(n)

var mergeAlternately = function (word1, word2) {
    const buffer = [];

    for (let i = 0; i < word1.length || i < word2.length; i++) {
        if (i < word1.length) buffer.push(word1[i]);
        if (i < word2.length) buffer.push(word2[i]);
    }

    return buffer.join('');
};
Mark as complete
Close
Shortcut: Ctrl + .
Shortcut: Ctrl + /