Ibibo Interview Question for Testing / Quality Assurances


Country: United States
Interview Type: Phone Interview




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

if regex is an option:

(.)\1{1}

this can be used.

- Prithvi May 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi,

could you please give code snippet with regex?...I am not too much in regex..

- Anirudh May 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sites.google.com/site/spaceofjameschen/home/regular-expression/find-strings-with-a-consecutive-repetition-of-a-specified-letter---ibibo

- Anonymous June 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

^^Thank you good sire!! But the solution you gave is in C++ I guess!! How do I match (.)\1{1} as regex in Java?

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

The same regex can be used in java.

public class Main {
	Pattern p = Pattern.compile("(.)\\1{1}");
	Pattern pattern = Pattern.compile("(\\w)\\1+");

	public static void main(String[] args) {
		Main appMain = new Main();
		Set<String> stringSet = new HashSet<String>();
		stringSet.add("Dauresselam");
		stringSet.add("slab");
		stringSet.add("fuss");
		stringSet.add("boolean");
		stringSet.add("clap");
		stringSet.add("clap");
		appMain.compare(stringSet);
	}

	private void compare(Set<String> stringSet) {
		for (String arg : stringSet) {
			Matcher match = p.matcher(arg);
			if (match.find())
				System.out.println( " Match found in word:"
						+ arg);

		}
	}
}

You can use any of the 2 regex. they both should work fine

- Prithvi October 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks a lot Prithvi...Cheers!!

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

for(int i=0;i<stringArray.length;i++){
		for(int j=0;j<(stringArray[i].length())-1;j++) {
			if(stringArray[i].charAt(j)==stringArray[i].charAt(j+1)) {
				System.out.println(stringArray[i]);
				break;
			}
		}
	}

- ArunV July 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

So you have to return a string array as well. I tried with the below solution i know it's not perfect or polished from a purist p.o.v kinda didn't help me get in LoL:

import java.util.Scanner;
public class doubleChars {
public static String[] getDoubles(String[]In)
{
	
	int inLen=In.length;
	String zoom[]=new String[inLen];
	int count=0;
	if(inLen==0)
	{
		return zoom;
	}
	for(int i=0;i<=inLen-1;i++)
	{
		String A=In[i];
		//System.out.println(A);
		int striLen=A.length();
		for(int j=0;j<striLen-1;j++)
		{
			
			if(A.substring(j, j+1).equals(A.substring(j+1, j+2)))
			{
				zoom[count]=A;
				count++;
				break;
			}
		}
		
	}
	  return zoom;
	}
 public static void main(String[] args)
 {
	 char more='y';
	 int ab=0;
	String[] res={};
    String[] fillMe={"durres", "murres", "", "abcdeee", "boolean", "nger", "lagger"};
    Scanner strobe=new Scanner(System.in);
    System.out.println("Please enter the arraye of the string");
    /*while(strobe.hasNext())
    {
    	fillMe[ab]=strobe.next();
    	
    	ab++;
    }
    */
    res=doubleChars.getDoubles(fillMe);
    for(int k=0;k<res.length;k++)
    {
    	if(res[k]==null)
    	{
    		break;
    	}
    System.out.println(res[k]);
    }
    

}
}

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

void findCons(String[] words){
	if (words==null);

	else{
		for(String s : words){

			for(int i=0; i<s.length()-1;i++){
				if(s.charAt(i)==s.charAt(i+1)){
					System.out.println(s);
					break;
				}
			}
		}
	}
}

- Ashish May 28, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

You should do only upto i<s.length -1
also it'll be better if you make it a function like Bool StringHasRepeatedChars(string input)

- vj May 28, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Java strings don't have subscript[] operator, so you need to use "s.charAt(i) == s.charAt(i+1)".

- oOZz May 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Using For each loop is a better option but oOZz is right...either use chartAt ot substring function to verify repetition.

- Anirudh May 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Corrected the errors, thanx :)

- Ashish May 30, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class SubString {
public static String[] s = { "Dauresselam","fuss", "boolean","clap" };
public static void main(String[] args) {
for (String ss : s) { if(!ss.equals(null))
for (int i = 0; i < ss.length()-1; i++) {
if(ss.charAt(i)==ss.charAt(i+1)){System.out.println(ss);}
} } } }

- sudharshan May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

We are not printing here....rather returning an array of strings with repetition..

- Anirudh May 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ruby Code

a=Array.new
b=Array.new
a=["Dauresselam", "slab", "fuss", "boolean", "clap"]
p=0
l=a.length
puts l

for i in 0...l
    flag=0
    temp=Array.new   
    la=a[i].length
    temp = a[i]
	
	n=temp[0]
    for j in 1...la
	   if n==temp[j]
	      flag=1
       else
         n=temp[j]	   
	   end
    end	
	if flag == 1
	b[p]=a[i]
	p=p+1
	end
end	

puts "Array is: #{b}"

- Nitin May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

b=Array.new


Dynamic array initialization in Ruby? the code looks nice.

- Anirudh May 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think below function should work fine..and its run time complexity is O(n)

public static List<String> getConsecutiveRepeatedStrings(String[] input){

int inputLen = input.length;
List<String> li = new ArrayList<String>();
int strPtr = 0, i = 0 , j = 1;
while(strPtr<inputLen){
if(input[strPtr].charAt(i) == input[strPtr].charAt(j)){
li.add(input[strPtr]);
strPtr++;
i = 0 ;
j = 1;
}
else if(j < input[strPtr].length()-1){
i++;
j++;
}
else{
strPtr++;
i = 0 ;
j = 1;
}

}
return li;
}

- Rahul Khanna May 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

the ques is for array not arraylist

- Stuti June 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public ArrayList<String> findRepeat(String[] input) {
		int i = 0;
		ArrayList<String> res = new ArrayList<String>();
		res.clear();
		for (String s : input) {
			if (s.length() > 1) {
				for (i = 1; i < s.length(); i++) {
					if (s.charAt(i) == s.charAt(i - 1)) {
						res.add(s);
						break;
					}
				}
			}
		}
		return res;
	}

- Gabriel May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

here we can convert array List to an array and return the array.
There by getting our array containing all string with consecutive duplicate chars.

- RASHMI BS March 22, 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[5][15]={"kaushal","naggesh","indiaan","institute","myystring"};
char *str,*finalarr[5];
int i,len,j,count=0;
for(i=0;i<5;i++)
{
str=&a[i][0];
len=strlen(str);
for(j=1;j<len;j++)
{
if(str[j]==str[j-1])
{
finalarr[count]=str;
count++;
break;
}
}
}
for(i=0;i<count;i++)
printf(" %s ",finalarr[i]);
return 0;
}

- kaushal yadav May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
struct list
{
char data[20];
struct list *next;
}*head=NULL;
struct list *insert(struct list *head,char n[20])
{
struct list *temp=head,*t;
if(!head)
{
head=(struct list *)malloc(sizeof(struct list));
strcpy(head->data,n);
head->next=NULL;
}
else
{
while(temp->next)temp=temp->next;
t=(struct list *)malloc(sizeof(struct list));
strcpy(t->data,n);
t->next=NULL;
temp->next=t;
}
return head;
}
int display(struct list *head)
{
struct list *temp=head;
while(temp)
{
printf("%s ",temp->data);
temp=temp->next;
}
return 0;
}
int search(struct list *head)
{
int i=1;
struct list *temp=head;
while(temp)
{
i=0;
while(temp->data[i++])if(temp->data[i]==temp->data[i-1]){printf("\n%s",temp->data);break;}
temp=temp->next;
}
return 0;
}
int del_list(struct list *head)
{
struct list *temp=head,*t;
while(temp)
{
t=temp->next;
free(temp);
temp=t;
}
return 0;
}
int main()
{
int n,i;
char m[20];
printf("enter the number of elements to be inserted into the list:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",&m);
head=insert(head,m);
}
printf("search results:\n");
search(head);
printf("\n\n");
display(head);
return 0;
}

- ram rs May 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//Using HashSet in C# this is really easy code.
public static HashSet<string> UniqueWords()
{
string[] myArray = new string[] { "dog", "cat", "lion", "cat", "tiger", "cat", "rat" };
HashSet<string> HS = new HashSet<string>();
int i = 0;
while (i < myArray.Length)
{
HS.Add(myArray[i]);
i++;
}
Console.ReadLine();
return HS;
}

- Bharat Kumar July 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

a=["bubble", "slab", "fuss", "boolean", "clap"]
l=a.length
a1=a;
k=0
a3=Array.new
for i in 0...l
a2=a1[i]
l1=a2.length
for j in 0...l1
if a2[j]==a2[j+1]
a3[k]=a2
k=k+1
break
end

end
end
puts "#{a3}"

- Sony August 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.LinkedList;

public class Repeats {

        public String[] findConsecutiveRepeats(String[] s) {
                LinkedList<String> l = new LinkedList();

                for(int i=0; i<s.length; i++) {
                        char temp = s[i].charAt(0);

                        for(int j=1; j<s[i].length(); j++) {
                                if (temp == s[i].charAt(j)) {
                                        l.add(s[i]);
                                        break;
                                }
                                else
                                        temp = s[i].charAt(j);
                        }
                }

                return l.toArray(new String[0]);
        }

        public static void main(String[] args) {
                Repeats r = new Repeats();
                String s[] = {"aa", "ab", "ac"};        
                String s1[] = r.findConsecutiveRepeats(s);

                for(int i=0; i<s1.length; i++)
                        System.out.println(s1[i]);

        }
}

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

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        String[] words = {"Dauresselam", "slab", "fuss", "boolean", "clap", "ddan", "endd"};
        List<String> results = new ArrayList<String>();

        for (String word:words) {
            if (word.length() <= 1) break;

            int prev = -1;
            for (char ch:word.toCharArray()) {
                if (prev >= 0 && ch - word.charAt(prev) == 0) {
                    results.add(word);
                }
                prev++;
            }
        }

        for (String word:results) System.out.println(word);
    }
}

Way more readable and thus maintainable...

- chauvd October 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice Answer!!

- Anirudh October 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

After "results.add(word)", "break;" should be added. When a word has two consecutively repeated letters, e.g. ddaneef, the code adds the word twice to the list.

- tkekfl October 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class charDup {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] array = { "india", "fuss", "hello", "glee" };
String[] output = new String[10];
int count = 0;
for (int i = 0; i < array.length; i++)
for (int j = 0; j < array[i].length() - 1; j++)
if (array[i].charAt(j) == array[i].charAt(j + 1)) {
System.out.println(array[i]);
output[count] = array[i];
count++;
}
}
}

- JainB November 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A simple Python implementation.

word_list = ["Dauresselam", "slab", "fuss", "boolean", "clap"]

def repeating(word):
	flag = False
	for i in xrange(len(word)):
		if i != len(word)-1 and word[i] == word[i+1]:
			flag = True
			break
	return flag

for word in word_list:
	if repeating(word):
		print word

- svyzz March 25, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package QATest;

public class QATest{
	
	public String[] arrayStrings;	
	
	public static void main(String[] args)
	{
		QATest test = new QATest();
		test.arrayStrings = new String[] {"a","aa","hello","what","zoom", "11223", "abbba", "-+??-"};
		splitComparePrint(test.arrayStrings);
	}
	
	public static void splitComparePrint(String[] Array){
		boolean repeated = false;
		for (int i=0; i<Array.length; i++)
		{
			repeated = findRepetition(Array[i]);
			if (repeated){
				System.out.print(Array[i] + '\n');
			}
		}
	}
	
	public static boolean findRepetition(String string){
		boolean repeated = false;
		for (int i=0;i<string.length()-1;i++)
		{
			if (string.charAt(i)==string.charAt(i+1))
			{
				repeated = true;
				return repeated;
			}
		}
		return repeated;
	}
}

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

public static List<string> FindRep(string[] arr)
{
List<string> list = new List<string>();
bool found = false;
int i = 0;
int j = 0;
// int k = 0;
foreach (string str in arr)
{
found = false;
for (i = 0; i < str.Length - 1; i++)
{
if (str[i] == str[i+1])
{
found = true;
break;
}


}
if (found == true)
{
list.Add(arr[j]);
j++;

}
else
{
j++;
}

}

return list;
}

- Dj November 18, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;


public class ArrayOfStrings {


public static void main(String[] args)
{
// TODO Auto-generated method stub
String arr[]={"Dauresselam", "slab", "fuss", "boolean", "clap"};

ArrayList newarr=new ArrayList();

for(int i=0;i<arr.length-1;i++)
{
for(int j=0;j<arr[i].length()-1;j++)
{
if(arr[i].charAt(j)==arr[i].charAt(j+1))
{
newarr.add(arr[i]);
}
}
}

System.out.println(newarr);
}

}

- Ruchi Patel November 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void consecutiveOccurence(){
String[] arr={"Dauresselam", "slab", "fuss", "boolean", "clap"};
int size=arr.length;
boolean consecutive=false;
for(int i=0;i<size;i++){
String now=arr[i];
consecutive=false;
for (int j=1;j<now.length();j++){
if (now.charAt(j)==now.charAt(j-1)){
consecutive=true;
break;
}

}
if (consecutive){
System.out.println(now);
}
}
}

- sudip January 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just did a try with python:

input = ['Dauresselam', 'fuss', 'boolean', 'clap', 'slab']
output =[]

for i in input:

if len(set(i))!= len(i):

output.append(i)

print output

- 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