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

String findParenthesis(String s) {
	if(s.charAt(0) == '(') {
		if(s.charAt(s.length()-1) == ')')
			return s;
		else return findParenthesis(s.substring(0, s.length()-1));
	} else {
		return findParenthesis(s.substring(1));
	}
}

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

Yes..the clue for not using a variable apparently hints at recursion. So right answer.

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

function findSinglePairOfParenthesis(string n) {
	if (n == null) return null;
	// Go to the end of the string
	while (*n != '\0') n++;
	if (n == '\0') return null;
	// Find closing bracket
	while (*n != ')') n--;
	// Terminate the string right in place
	n++;
	*n = '\0';
	// Find opening bracket
	while (*n != '(') n--;
	
	return n;
}

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

which langue do u use?

- boyhailong July 06, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Good Answer provided by Sunny. Very near solution in C#

IEnumerable<string> GetValue(string val)
        {
            while (val.Length != 0)
            {
                if(val.Substring(0,1) == "(")
                {
                    while(val.Substring(0,1) != ")")
                    {
                        yield return val.Substring(0, 1);
                        val = val.Substring(1);
                    }
                    yield return val.Substring(0, 1);
                }
                val = val.Substring(1);
            }
            yield return string.Empty;
        }

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

I am not into c# but I am guessing yield return---> is the recursive call back to GetValue?

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

Here's python version without explicit variables

def find_start(input_string):
	if input_string.startswith("("):
		return input_string
	return find_start(input_string[1:])

def find_end(input_string):
	if input_string.endswith(")"):
		return input_string
	return find_end(input_string[:-1])


def in_parenthesis(input_string):
	return find_end(find_start(input_string))

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

Pseudo Code

for(Each char in String S){
Compute the ASCII value of the char;
If the ASCII Value matches the one corresponding to '('
Return (The values from the current char to the position where it again matches the ASCII value for ')' )
}

Run Time - O(n)

- Abhishek Das July 04, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def printInsideParens(s):
    if s[0] == '(':
        print '(',
        printUntilOutside(s[1:])
    else:
        printInsideParens(s[1:])


def printUntilOutside(s):
    if s[0] != ')':
        print s[0],
        printUntilOutside(s[1:])
    else:
        print ')'

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

Execute like so:
printInsideParens("xyz(abc)123")

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

//IN JAVA 
//finding the string within the given parenthesis without using variables
public class Parenthesis {
	public static void main(String[] args) {
		System.out.println(parenthesis("k(us)hal"));
	}

	public static String parenthesis(String input) {

		if (!Character.toString(input.charAt(0)).equals("(")) {

			return parenthesis(input.substring(1));
		} else if (!Character.toString(input.charAt(input.length() - 1))
				.equals(")")) {

			return parenthesis(input.substring(0, input.length() - 1));
		} else {
			return input;
		}

	}
}

- KP July 07, 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 *s="xyz(abc)123";
while(s[0]!='(')
s++;
while(s[0]!=')')
{
printf("%c",s[0]);
s++;
}
printf(")");
}

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

python execution:

a = 'xyz(abc)123'
a.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