Print all repeating characters in a string
We have already seen the problem to print first repeating character in a string. In this post we will be looking at printing all the repeating characters in the string. For example: Input String: “www.ritambhara.in” Output: w.ria Input String: “social.ritambhara.in” Output: ia.r Input String: “meenakshi” Output: e Note that we are printing the repeating character […]
Print the first repeating character in String
Give a string in which characters may be repeating. Print the first character (from the start) which is repeating in the string. For example: String: ABCBCD Output: B (A is not repeating, hence B is the first character which is repeating) String: ABCDE Output: NULL (No character repeating)
Recursive function to reverse a String
We have already seen the problem to reverse the words in a string, in the solution to that problem we have also written function to reverse the string. That was a non-recursive (iterative) function. Write a recursive function to reverse the String. For example: If the String is “ABCD” then the output should be “DCBA“. Before […]
Check if one string is rotation of another
Given two strings, write code to check if one string is rotation of another. For example: str2 below is a rotation of str1. str1 = “ROTATE” str2 = “TATERO” You may use the strstr function, but ONLY ONCE.
Check if two strings are anagrams
An anagram is a word play. If letters of a word can be arranged to form another word, the two words are called anagrams. e.g MARY & ARMY are anagrams because both of them are formed of characters A, M, R and Y.
Remove duplicates from a string
Given a string of characters. Write code which will remove duplicate characters from the string: Input: “social.ritambhara.in” Output: “social.rtmbhn”
Reversing words in a String
Given a String, reverse the string but do not reverse the words. For example, if Input : “MCN Professionals is now Ritambhara” Output: “Ritambhara now is Professionals MCN” Your function should not take more that O(n) time in the worst case.
Permutations of a String or Array
Print all possible permutations of an Array or a String. For Example: If the array is arr={1, 2, 3}. Then the possible permutations are: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Print all interleavings of two strings
Given two strings, write code to print all inter-leavings of these strings. For example: if the two strings are “AB” and “12”, then the output should be: AB12 A1B2 A12B 1AB2 1A2B 12AB Note that the order of characters in the individual strings are not changed in the output.