easy String

Palindrome

Write a function isPalindrome that determines if a given string is a palindrome. A string is considered a palindrome if it reads the same forward and backward, ignoring cases, spaces, and punctuation.

Function Signature

function isPalindrome(str);

Example 1:

Input: s = "racecar"
Output: true
Explanation: The string "racecar" reads the same forward and backward.

Example 2:

Input: s = "hello"
Output: false
Explanation: The string "hello" does not read the same forward and backward.

Example 3:

Input: s = "kajak"
Output: true
Explanation: The string "kajak" reads the same forward and backward, proving it is a palindrome.

Solve this problem

Start your 7-day free trial to solve this problem in our code editor with instant feedback.

Start 7-Day Free Trial to Solve This Problem

Related Problems

Reverse String

easy

Write a function `reverseString` that takes a string and returns it reversed. ## Function Signature ```function reverseString(str);``` ### Example 1: > **Input:** `str = "hello"`\ > **Output:** `"olleh"`\ > **Explanation:** The string "hello" reversed is "olleh". ### Example 2: > **Input:** `str = "world"`\ > **Output:** `"dlrow"`\ > **Explanation:** The string "world" reversed is "dlrow". ### Example 3: > **Input:** `str = "a"`\ > **Output:** `"a"`\ > **Explanation:** The string "a" reversed is "a".

String

Count Vowels

easy

Write a function `countVowels` that takes a string and returns the number of vowels in it. ## Function Signature ```function countVowels(str);``` ### Example 1: > **Input:** `str = "hello"`\ > **Output:** `2`\ > **Explanation:** The string "hello" contains 2 vowels: "e" and "o". ### Example 2: > **Input:** `str = "world"`\ > **Output:** `1`\ > **Explanation:** The string "world" contains 1 vowel: "o". ### Example 3: > **Input:** `str = "bcdfgh"`\ > **Output:** `0`\ > **Explanation:** The string "bcdfgh" contains no vowels.

String

Top N Frequent Words

hard

Write a function `topNFrequentWords` that takes a large text document as input and returns the top N most frequent words. The function should be optimized for performance. ## Function Signature ```function topNFrequentWords(text, N);``` ### Example 1: > **Input:** `text = "the quick brown fox jumps over the lazy dog the the the quick quick"`, `N = 2` \ > **Output:** `["the", "quick"]` \ > **Explanation:** "the" and "quick" are the most frequent words appearing 4 and 3 times respectively. ### Example 2: > **Input:** `text = "a a a b b c"`, `N = 1` \ > **Output:** `["a"]` \ > **Explanation:** "a" is the most frequent word appearing 3 times. ### Example 3: > **Input:** `text = "apple banana apple banana orange apple banana banana"`, `N = 2` \ > **Output:** `["banana", "apple"]` \ > **Explanation:** "banana" and "apple" are the most frequent words appearing 4 and 3 times respectively.

String