Category: Strings

Determine given a pattern and string are isomorphic

Problem : Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and...

Determine if given strings are isomorphic

Problem : Given two (dictionary) words as Strings, determine if they are isomorphic. Two words are called isomorphic if the letters in one word can be remapped to get the second word. Remapping a...

Rearrange characters in a string so that no character repeats consecutively.

Below are some of the test strings with their expected output. Input: aaabc Output: abaca Input: aa Output: No valid output Input: aaaabc Output: No valid output Logic : Create frequency map of the...

Determine character frequency in the given string

Problem description : Create a character frequency analysis table for the given string. Input : A string // “foo bar” Output : A JSON // {” “: 1, a: 1, b: 1, f: 1,...

String compression using the counts of repeated characters.

Input : A string // aaaabbc Output : A string // a4b2c1 Logic : Iterate over the string Compare the current and next characters. If both characters are not same, Then increment the count...

Reverse a given string, also using similar technique reverse a sentence without reversing words

Reverse a given string Input : A string // ‘Hello’ Output : A string // ‘olleH’ There are many ways of reversing a string. Approach 1 : Simplest way is to use inbuilt javascript...

Determine if given strings are anagram.

Input : Two strings // ‘dog’, ‘god’ ; ‘foo’,’bar’ Output : Boolean // True ; False Clarifications : Is the comparison of our string permutation case sensitive? Yes Is whitespace significant? Yes Approach 1...

Determine if a string has all unique characters

Input : A string Output : Boolean Clarifications : Is the input string ASCII or Unicode ? If ASCII then we need storage size of 128 bits Logic : Iterate over entire string If...