Interview Question


Country: India




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

Here you go

string RemoveChar(string orig, char c)
	{
            StringBuffer sb = new StringBuffer();
	    for(int i=0; i<orig.Length; ++i)
		{
 			if(orig[i] == c)
                       {
                            if( (i >0 && orig[i-1] != c) &&
                                  (i<orig.Length-1 && orig[i+1] != c))
				{
                                   continue;
				}
                       }
                      sb.Append(orig[i]);
		}	
              return sb.ToString();
	}

- vikas May 28, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class RemoveNonSimultaneous {
	public static void main(String[] args) {
		String str = "aabcdabagtdraafgdta";
		removeNonSimultaneous(str, 'a');
	}

	private static void removeNonSimultaneous(String str, char ch) {
		// TODO Auto-generated method stub
		char charArray[] = str.toCharArray();
		int counter = 0;

		for (int i = 0; i < charArray.length;) {
			if (charArray[i] == ch) {
				i++;
				if (i == charArray.length) {
					break;
				}
				if (charArray[i] != ch) {
					charArray[i - 1] = '\0';
					i++;
				} else {
					while (charArray[i] == ch)
						i++;
				}
			} else
				i++;
		}

		int j = 0;
		System.out.println(charArray.length);
		for (int i = 0; i < charArray.length; i++) {
			while (i != charArray.length && charArray[i] != '\0') {
				charArray[j++] = charArray[i++];
			}
		}
		charArray[j]='\0';

		String str1 = new String(charArray);
		System.out.println(str);
		System.out.println(str1 + " :index - " + j);

	}
}

- dhirajb1989 May 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
char str[100] , ch;
int i=0,k,len;

printf("enter string ");
scanf("%s",&str);

while(str[i])
{
if(str[i]=='0')
{
i++;
if(str[i]!='0' )
{
k=i;
while(str[i])
{
str[i-1]=str[i];
i++;
}
str[i-1]='\0';
i=k-1;
}
else
i++;
}
i++;
}
printf("\n\n %s ",str);
}

- shweta May 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

May be you would want to enclose in triple quotes to mind the formatting

- dhirajb1989 May 31, 2014 | Flag


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