Interview Question


Country: India
Interview Type: In-Person




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

Reverse the whole sentence first. Then leave the first word and reverse the second word. If the question is really asking to have this pattern of reversed word and a non-reversed word, continue this processing of reversing alternate words till the end.

- Murali Mohan June 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

from this question not getting full data.can u explain with sum more data or tell me that Sting contain only two words or many words .if it contain more then two words then what is the sequence of output string .

- yugandharr147 June 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just consider only dt string i.e welcome bangalore after performing reverse operation i want this format output erolagnab welcome

- Anonymous June 30, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>
int main()
{
    char a[100], temp;
    int length = 0, i=0;
    scanf("%[^\n]", a);

    while(a[i++] != ' ');
    i = i-1;

    while(length < i){
    temp = a[length];
    a[length++] = a[i];
    a[i--] = temp;
    }
    printf("%s", a);
}

- george June 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private String reverseString(String input){
StringBuilder str = new StringBuilder();
int index = 0;
int temp_index=0;
boolean bfirstword = false;
// reverse last word
for (int i = input.length() - 1; i > 0; i--) {
str.append(input.charAt(i));
if (input.charAt(i) == ' ') {
index = i;
break;
}
}

// now reverse string other than last word
while (index > 0) {
temp_index = index;
index = index-1;
bfirstword = true;
for (int i = index; i > 0; i--) {
if (input.charAt(i) == ' ') {
index = i;
bfirstword = false;
break;
}
}

if (bfirstword) {
for (int j = 0; j < temp_index+1; j++) {
str.append(input.charAt(j));
}
break;
} else {
for (int j = index + 1; j < temp_index+1; j++) {
str.append(input.charAt(j));
}
}
}
return str.toString();
}

- satish June 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class CarrerCup1 {

	
	public static void main(String[] args) {
		StringBuilder s=new StringBuilder("Welcome Bangalore");
		String str="";
		for(int i=(s.length()-1);i>=0;i--)
		{
			
			if(s.charAt(i)==' '){
				str=str+s.charAt(i);
				for(int j=0;j<i;j++){
					str=str+s.charAt(j);
				}
				i=0;
			}
			
			else{
				str=str+s.charAt(i);
			}
		}
		System.out.println(str);
		
	}

}

- yugandharr147 June 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

str=str+s.ChatAt[j] --- which will print chatAt(j) which j=0 as W.
can u pls explain the code for that if and for loop

- kalpana July 02, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class TestProgram {

public static final String SPACE = " ";

public static void main(String[] args) {
Scanner input = null;
try {
input = new Scanner(System.in);
String inString = input.nextLine();
System.out.println(new StringBuilder(inString.split(SPACE)[1]).reverse() + SPACE + inString.split(SPACE)[0]);

} catch (Exception e) {
e.printStackTrace();
} finally {
if (input != null)
try {
input.close();
} catch (Exception e2) {
// ignore
}
}
}

}

- Mohit July 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class TestProgram {

	public static final String SPACE = " ";

	public static void main(String[] args) {
		Scanner input = null;
		try {
			input = new Scanner(System.in);
			String inString = input.nextLine();
			System.out.println(new StringBuilder(inString.split(SPACE)[1]).reverse() + SPACE + inString.split(SPACE)[0]);

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (input != null)
				try {
					input.close();
				} catch (Exception e2) {
					// ignore
				}
		}
	}

}

- Mohit Mehta July 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

data='welcome bangalore'
data_modified =data.split(' ')
cnt=1
new_data='';
for line in data_modified:
  if cnt%2==0:
     new_data=new_data + line[::-1] + ' '
  else:
     new_data=new_data + line + ' '
  cnt=cnt+1
print  new_data

- Anonymous July 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[50] , revstr[50];
int i=0,j=0;
printf("enter the string for reversing:");
scanf("%s", str);
for(i=strlen(str)-1;i>=0;i--)
{
revstr[j] = str[i];
j++;
}
revstr= "\0";
printf("input string %s :" ,str);
printf("reversed string %s:", revstr);

}
}

- kalpana July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[50] , revstr[50];
int i=0,j=0;
printf("enter the string for reversing:");
scanf("%s", str);
for(i=strlen(str)-1;i>=0;i--)
{
revstr[j] = str[i];
j++;
}
revstr= "\0";
printf("input string %s :" ,str);
printf("reversed string %s:", revstr);

}
}

- kalpana July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Scanner;

public class TestProgram {

	public static final String SPACE = " ";

	public static void main(String[] args) {
		Scanner input = null;
		try {
			input = new Scanner(System.in);
			String inString = input.nextLine();
			System.out.println(new StringBuilder(inString.split(SPACE)[1]).reverse() + SPACE + inString.split(SPACE)[0]);

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (input != null)
				try {
					input.close();
				} catch (Exception e2) {
					// ignore
				}
		}
	}

}

- Mohit Mehta July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Sreverse{

public static void main(string[] args)
{
string s="Welcome Banglore";
Char[] arr= s.toCharArray();

//reverse string
Srevers.reversefunction(arr,0,arr.lenght/2,arr.length);
System.out.println(new string(arr));
}


public static void reversefunction(char[] arr, i,m,l)
{
for(;i<m;i++)
{
char temp=arr[i];
arr[i]=arr[l];
arr[l]=temp;
l--;
}
}
}

- kalpana July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<string.h>
int main()
{
char inp[]="welcome bangalore",rev[20];
int i,j=0,len;
len=strlen(inp);
i=len-1;
while(inp[i]!=' ')
{
rev[j]=inp[i];
printf("%c",rev[j]);
i--;
j++;
}
i=0;
printf(" ");
while(inp[i]!=' ')
{
printf("%c",inp[i]);
i++;
}
return 0;
}

- Saraban July 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class stringTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		 String str1 = "welcome bangalore";
		 String strArr[] = str1.split(" ");
		 
		 StringBuffer lastword = new StringBuffer(strArr[1]) ;
		 System.out.println(lastword.reverse() + " "+ strArr[0] );
		 
	}

}

- amitceg July 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

///String se="Welcome Bangalore";

System.out.println(new StringBuilder(se.substring(se.indexOf(" ")+1)).reverse()+" "+se.substring(0,se.indexOf(" ")));\\\

- tej August 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ReverseWordsInStrings {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String str = "Welcome Bangalore Ssk";
		String []iStr = str.split(" ");

		for(int j = iStr.length - 1; j >=0; j--){
			String s = iStr[j];
			String rev = "";
			if((iStr.length - j) % 2 == 0)
				rev = s;
			else
				for(int i = s.length() - 1; i >= 0; i--){
					rev += s.charAt(i);
				}
			System.out.print(rev + " ");
		}
	}

}

- Sameer August 08, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Rev
{
public static void main(String[] args)
{
String str="Welcome Banglore";
String str1;
str1=str.substring(str.indexOf("Banglore"));
StringBuffer str2=new StringBuffer(str1);
System.out.println(str2.reverse()+" "+str.substring(str.indexOf("Welcome"),str.indexOf("Banglore")));
}
}

- vinay.duddilla August 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Test {
public static void main(String[] args) {
String st = "welcome bangalore";
String[] sp = st.split(" ");
String b = sp[1];
String s = "";
for(int i = b.length()-1;i>=0;i--)
{
s = s+b.charAt(i);
}
System.out.println(s+" "+sp[0]);
}
}

- chinnaraj October 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.lakshma;

public class StringReverseExample {
public static void main(String[] args) {
String str = "WELCOME BANGALORE";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
Character ch = str.charAt(i);
if (ch.toString().equals(" ")) {
System.out.print(sb.toString());
sb = new StringBuffer();
} else {
sb.append(ch);
}
}
System.out.print(" " + sb.reverse().toString());
}
}

- Lakshmareddy August 25, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.lakshma;

public class StringReverseExample {
public static void main(String[] args) {
String str = "WELCOME BANGALORE";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
Character ch = str.charAt(i);
if (ch.toString().equals(" ")) {
System.out.print(sb.toString());
sb = new StringBuffer();
} else {
sb.append(ch);
}
}
System.out.print(" " + sb.reverse().toString());
}
}

- Lakshmareddy August 25, 2015 | 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