Reverse only the alphabets in a string

Given a string that has alphabets and special characters. Write code that reverse only the alphabets in the string and does not change the special characters. INPUT STRING: AB$C^%DEF* OUTPUT: FE$D^%CBA* We have discussed a simple code to reverse a string in this post. We use the same logic here, the only difference here is […]

Reverse a string

Write a simple code to reverse a string. INPUT: “HELLO WORLD” OUTPUT: “DLROW OLLEH”

String Matching Algorithms

Given a string of characters, search for a pattern (another smaller string) in the string. For example, if given string is Ritambhara Technologies for Coding Interviews and the pattern is Tech, then the pattern is present in the string. If the pattern that we are looking for is Moksha, then this pattern is not present […]

Remove all white spaces from a string

Given a string that may have white spaces, write code to remove all white spaces from than string. For example: Input String: “IT IS HOT OUTSIDE” Output String: “ITISHOTOUTSIDE” Input String: ” I T I S HOT ” Output String: “ITISHOT”

Check duplicate parenthesis in an expression

A valid mathematical expression can also have duplicate parenthesis as shown below: ((a+b)) (((a+(b)))+(c+d)) Write code to find if an expression has duplicate parenthesis. You may assume that expression does not have any white spaces.

Compare to strings given as linked list

In C language, string library has a function strcmp that takes two arguments and return -1, 0 or 1 depending on whether first string is less than equal-to or greater than the second string. int strcmp(const char *str1, const char *str2); Write similar function that compare strings given in the form of linked list, For […]

Print characters coming in one of the 2 strings (and not in both)

Given two strings, write a function which will print characters coming on only one of the two strings (and not both). The character may be repeated in that string. For example: String-1 String-2 Output ——— ———- ————- AFW BGF AWBG AFAAW BGFFB AWBG BGF AWBG AFW BGH AFWBGH AFW BGF AWBG

Print first non-repeating character in the string

Given a String where characters are repeating. Write code to print the first character that is repeating later in the string. e.g, Input String: ritambhara Output: i Input String: social ritambhara Output: s

Longest substring of unique characters

Given a String in which characters may be repeating. Find the length of longest substring of where all characters are unique (non-repeating). For Example: If the String is “RITAMBHARA” Length of Longest substring with unique characters = 7 (“RITAMBH”)