function isAnagram(str1, str2) { const sortedStr1 = str1.split(”).sort().join(”); const sortedStr2 = str2.split(”).sort().join(”); return sortedStr1 === sortedStr2; } Sample Answer 8. Implement a function that finds the second smallest element in an array of ...
Given two strings s and t, write a function to determine if t is an anagram of s. For example, s = "anagram", t = "nagaram", return true. s = "rat", t = "car", return false. Note: You may assume the string contains only lowercase alphabets. Follow up: What if the inputs...
var firstWord = "Deepak"; var secondWord = "Aman"; isAnagram(wordOne, wordTwo); // true function isAnagram(one, two) { //Change both words to lowercase for case insensitivity.. var a = one.toLowerCase(); var b = two.toLowerCase(); // Sort the strings, then combine the array...
var isAnagram = function(s, t) { if (s.length !== t.length) return false; let map = new Map(); for (let item of s) { if (map.get(item)) { map.set(item, map.get(item) + 1); } else { map.set(item, 1); } } for (let item of t) { if (map.get(item)) { map...
function isAnagram(first, second) { // For case insensitivity, change both words to lowercase. var a = first.toLowerCase(); var b = second.toLowerCase(); // Sort the strings, and join the resulting array to a string. Compare the results a = a.split("").sort().join(""); b ...
Valid Anagram public class Solution { public bool IsAnagram(string s, string t) { if(...
JavaScript is a key component of the modern web. Elisabeth Robson's picks h... By Elisabeth Robson April 2019 On-demand Course Modern JavaScript from The Beginning [Second Edition] - Second Edition This course is a comprehensive introduction to JavaScript, covering everyth... By Brad Traversy...
❓: Given two strings s & t , write a function to determine if t is an anagram of s. 🐣: 1️⃣ Input: s = "anagram", t = "nagaram" Output: true 2️⃣ Input: s = "rat", t = "car" Output: false 🐢 Solution: 🔨 Brute Force ⏰: O(nlogn) 🪐: O(n) ...
var firstWord = "Mary";var secondWord = "Army"; isAnagram(firstWord, secondWord); // truefunction isAnagram(first, second) { // For case insensitivity, change both words to lowercase. var a = first.toLowerCase(); var b = second.toLowerCase(); // Sort the strings, and join the ...
Median of Two Sorted Arrays Largest Rectangle in Histogram Plus One Trapping Rain Water Merge Intervals Spiral Matrix Summary Ranges Find All Numbers Disappeared in an Array Game of Life Next Permutation Find Peak Element Wiggle Sort Wiggle Sort II Valid Triangle Number Find Anagram Mappings K Empty...