The groupAnagrams function will return an array with anagrams grouped together

Group Anagrams in an Array

Problem Statement We have to implement a groupAnagram function that takes an array of strings as input and returns a new array with anagrams grouped. The input string array is assumed to be composed entirely of lowercase English characters. Brute Force Solution If two strings are anagrams then their sorted order will be the same. Thus, anagrams could be grouped under their sorted order. The brute-force implementation of groupAnagram uses a hashmap for grouping....

October 22, 2023 · 7 min · Avnish
The twoSums function will return the indices of two elements in the input array that sum up to the target value

Finding Elements in an Array that Sum Up to a Target Value

Problem Statement We have to implement a twoSums() function that takes an integer array and a target value as inputs. It returns the indexes of two elements in the input array which could be summed up to the target value. It is assumed that the input array contains only one valid pair of elements that sum up to the target value. Brute Force Solution The brute-force solution will find the sum of all element pairs in the array using nested loops....

October 15, 2023 · 4 min · Avnish
The isAnagram function will return true if both input strings are anagram and false otherwise

Identify Anagrams

Problem Statement We have to implement an isAnagram() function that takes two strings as input and returns true if they both are anagrams and false otherwise. Multiple words could be anagrams of each other if they contain the same characters with the same frequency of occurrence. For word counter: trounce is an anagram. trouncee isn’t an anagram, because the character e appears twice in trouncee. tounce isn’t an anagram, because the character r is missing....

October 12, 2023 · 5 min · Avnish
The containsDuplicate function takes an array as input and returns true or false depending on the fact that array contains duplicate elements or not

Checking an Array for Duplicate Values

Problem Statement We have to implement a function containsDuplicate() that takes an integer array as input and returns true if an element occurs more than once and false otherwise. Brute Force Solution The simplest solution for this problem would be two nested loops, where the first loop will select an element and the second loop will select another element from the array and compare them. On the first occurrence of a duplicate element, the function will exit while returning true....

October 10, 2023 · 3 min · Avnish
Rabin-Karp Substring Search

Rabin-Karp Substring Search

Searching contents on a website for a specific keyword, code search in text editors & IDEs, and information retrieval systems used in libraries and archives are use cases for an algorithm that searches a string within another string. Unlike searching for a single character, searching for a complete string could be challenging. If we search string ION in DICTIONARY. For each character in DICTIONARY, we have to look for I, O, and N in the same order....

October 8, 2023 · 8 min · Avnish