Tag: String

Lexicographic Order in Java

Lexicographic Order Problem Write java method to compare two strings lexicographically. The method should return 0 if the two strings are Lexicographically equal. It should return 1 if the first string comes before the second string in the dictionary. It should return -1 if the first string comes after the second string in the dictionary.

Java Replace String Function

Problem Write a Java method to replace a sub string in a given text with another string of the same size Solution Loop through the text character by character. Starting at the current character loop a number of times equal to the size of the sub string while comparing characters in the original text and the sub

Copy String C++

Problem Write a C++ function to copy an existing string. Do not use built in functions. Solution This is a straight forward question and to my surprise I was asked this question in a site interview. If you are not prepared you might stumble on the easy ones. The idea is to allocate memory for

Reverse String Word by Word

Problem Write a program to reverse an English sentence word by word not character by character. For example if the sentence is "I love Pizza so much" the program should print "much so Pizza love I" Solution One solution is to split the sentence into tokens using the space character as the separator then print