Ibibo Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

//No validation of wrong inputs
public class FindParnth {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
					
		System.out.println(args[0].substring(args[0].lastIndexOf('('), args[0].lastIndexOf(')')+1));
			
		
	}

}

- Venkateswara Rao July 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Good work Venkateswara Rao !! :)

- Junaid July 04, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just asking, the question says there is only one instance of parenthesis so it it necessary to use lastIndexOf, we can just use indexOf, right?

- Aditya Peshave July 08, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Given a string that contains exactly a single pair of parenthesis, 
//return parenthesis and their contents, so "xyz(abc)123" yields "(abc)". etc.

import java.io.*;
import java.util.*;

public class returnParanthesis {

	public static final String EMPTY_STRING = "Empty String";
	public static final String INVALID_INPUT = "Invalid String";
	
	public String extractParanthesis(String input){
		StringBuffer output=new StringBuffer();
		if(input.length() == 0){
			return EMPTY_STRING;
		}
		int i=0;
		while(input.charAt(i)!='('){
			if(i == input.length()-1){
				return INVALID_INPUT;
			}
			i++;
		}
		while(input.charAt(i)!=')'){
			if(i == input.length()-1){
				return INVALID_INPUT;
			}
			output.append(input.charAt(i));
			i++;
		}
		output.append(input.charAt(i++));
		return output.toString();
	}
	
	public static void main(String args[]){
		returnParanthesis r = new returnParanthesis();
		System.out.println(r.extractParanthesis("abc(xyx)123"));
		System.out.println(r.extractParanthesis("abc(xyx123"));
		System.out.println(r.extractParanthesis("(abcxyx12)3"));
		System.out.println(r.extractParanthesis(""));
		System.out.println(r.extractParanthesis("()"));
	}
}

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

Lol..you needed only one line to solve that.

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

public class SingleParanthesis{
	public static void main(String args[]){
		String inStr = "xyz(abc)123";
		int openParanthesisIndex = inStr.indexOf("(");
		int closeParanthesisIndex = inStr.indexOf(")");
		
		if(openParanthesisIndex<closeParanthesisIndex)
			System.out.println(inStr.substring(openParanthesisIndex, closeParanthesisIndex+1));
		else
			System.out.println("Input condition is not satisfied");
		
	}

}

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

public class Paranthesis {
public static void main(String args[]){
String str = "xyz(abc)123";
System.out.println(str.substring(str.indexOf("("), str.lastIndexOf(")")+1));
}

}

- Sunil koni July 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class ParenthesisSurrounded {

public static void main(String[] args) {
String str = "xyzr(ghf)12j6(jhtm)j876 fdfdfd (fdfdfd)jjjjj ";

new ParenthesisSurrounded().recursiveCall(str, null);

}
public String recursiveCall(String baseString,String outputString){

if(null != outputString && baseString.indexOf("(") >= 0)
outputString += (baseString.length() > 0)?baseString.substring(baseString.indexOf("("),baseString.indexOf(")")+1):"";

else if(baseString.indexOf("(") >= 0)
outputString = (baseString.length() > 0)?baseString.substring(baseString.indexOf("("),baseString.indexOf(")")+1):"";

if(baseString.indexOf(")") >= 0)
baseString = (baseString.length() > 0)?baseString.substring(baseString.indexOf(")")+1):"";

if( baseString.indexOf("(") == -1){
System.out.println("final printing outputString : "+outputString);
return outputString;
}
return recursiveCall(baseString,outputString);
}

}

- Alok Raghuvanshi August 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

String strval = "xyz(abc)123";

System.out.println(strval.substring(strval.indexOf("("),strval.lastIndexOf(")")+1));

- Diptendu December 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

python execution:

'xyz(abc)123'.split('(')[1].split(')')[0]

- vinesh.emag May 27, 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