Informatica Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
1
of 1 vote

/* This answer is in Java. For C/C++, the lengths of the strings are easily calculated and are already character arrays. The algorithm should be more or less the same. */

String input = "anonymous";
String find = "mous";
String replace = "kggse";
		
int leni = input.length();
int lenf = find.length();
		
char[] inputC = input.toCharArray();
char[] findC = find.toCharArray();
String output="";
boolean isMatch = false;

for(int i = 0; i < leni; i++){
	if(inputC[i] == findC[0]){
		
		for(int j = i, k = 0; j < i+lenf; j++, k++){
			isMatch = inputC[j] == findC[k];
					
			if(!isMatch) break;
		}
	}
			
	if(isMatch){
		output = output + replace;
		i = i + lenf - 1;	
		isMatch = false;
	} 
	else 
		output = output + inputC[i];
			
}

- Jackmerius Tacktheritrix October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if((index=KMP(source,target))==-1)
  return -1; // i.e., if the target string is not found in the source string
//index contains the starting position of the target in the source
for(i=index;i<target.size();i++)
   source[i]=target[i];

- Anonymous October 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReplaceString {

	public static void main(String[] args) {
		replace("anonymous", "abcs");
	}

	private static String replace(String input1, String input2) {
		char[] arr1 = input1.toCharArray();
		char[] arr2 = input2.toCharArray();
		char[] temp = new char[input2.length()];
		int i = 0;
		for (int j = 0; j < arr2.length; j++) {
			if (i < arr1.length) {
				if (arr1[i] == arr2[j]) {
					temp[j]=arr2[j];
					i++;
					continue;
				} else {
					temp[j]=arr2[j];
					i++;
				}
			}else{
				temp[j]=arr2[j];
			}
		}
		return temp.toString();
	}
}

- Sunil Kumar Tamoli November 24, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

More efficend code

public class ReplaceString {

	public static void main(String[] args) {
		System.out.println(replace("anonymous", "anonykggse"));
	}

	private static String replace(String input1, String input2) {
		char[] arr1 = input1.toCharArray();
		char[] arr2 = input2.toCharArray();
		int i = 0;
		StringBuilder sb = new StringBuilder();
		for (int j = 0; j < arr2.length; j++) {
			if (i < arr1.length) {
				if (arr1[i] == arr2[j]) {
					sb.append(arr2[j]);
					i++;
					continue;
				} else {
					sb.append(arr2[j]);
					i++;
				}
			}else{
				sb.append(arr2[j]);
			}
		}
		return sb.toString();
	}
}

- Anonymous November 24, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Code with less control statements
import java.util.*;

public class Informatica{

public static String stringReplace(String original, String change){
char[] input = original.toCharArray();
char[] out = change.toCharArray();
String output = "";
int j=0;
for(int i=0; i<change.length(); i++){
if(j < input.length && input[j] == out[i]){
output = output+""+input[i];
j++;
}else{
output = output + "" + out[i];
}
}
return output;
}

public static void main(String[] args){
System.out.println(Informatica.stringReplace("anonymous","anonymity"));
}
}

- Stephy Nancy March 27, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Replace a Substring in string using Java code follows like this:

String a = "Anonymousr How are you!";
String r = a.replace("mous","kggse");

print.i(r);

it will print: "Anonuykggse How are you!"

replace

public String replace(char oldChar,
                      char newChar)

Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar.

Examples:

"mesquite in your cellar".replace('e', 'o')
         returns "mosquito in your collar"
 "the war of baronets".replace('r', 'y')
         returns "the way of bayonets"
 "sparring with a purple porpoise".replace('p', 't')
         returns "starring with a turtle tortoise"
 "JonL".replace('q', 'x') returns "JonL" (no change)

Parameters:
oldChar - the old character.
newChar - the new character.
Returns:
a string derived from this string by replacing every occurrence of oldChar with newChar.

- Sunil B N October 03, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More