Trilogy Interview Question for Computer Scientists


Country: India
Interview Type: In-Person




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

Why is this one false, abc is repeated:

Abcabcabcx - false

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

Java Code

public void launch() {
		Scanner scanner = new Scanner(System.in);
		String str = null;
		boolean repetition = false;
		while(scanner.hasNext()) {
			str = scanner.nextLine().toLowerCase();
			int strLength = str.length();
			for(int i = 1; i < strLength; i++) {
				if(strLength % i == 0) {
					String head = str.substring(0,i);
					repetition = true;
					for( int x = i; x < strLength; x += i) {
						String current = str.substring( x, x + i);
						if(!head.equals(current)) {
							repetition = false;
							break;
						}
					}
					if(repetition == true) {
						break;
					}					
				}
			}
			System.out.println(repetition);
		}
		scanner.close();
	}

- KrishnaK5891 October 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include <iostream>
#include <string>
using namespace std;


bool StringRepetition(string input)
{
	int pointera, pointerb;
	bool Repetation=true;
	for (pointera= 2; pointera< input.length();  pointera++)
	{
		Repetation=true;
		for (pointerb= 0; pointerb< input.length()-pointera; pointerb++)
		{
			if (input[pointerb]!=input[pointerb+pointera])
			{
				Repetation=false;
				break;
			}
		}
		if (Repetation==true)
		{
			break;
		}
	}
	return Repetation;
}

int main() {
	while(1)
	{
		string input;
		cin>>input;
		cout<<StringRepetition(input)<<endl;
	}
	return 0;
}

- Anonymous September 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<stdio.h>
#include<conio.h>
int length(char str[]){
    int i;
    for(i = 0; str[i] != '\0'; i++);
    return i--;
}

int main(){
    char str[] = "abaaabaaabaa";
    int len;
    for(len = 1; len < length(str); len++){
    int startIndex = 0;
    int true = 1;
    int i,j;
    for(i = 0; str[i] != '\0';){
          printf("%d\n",i);
          for(j = 0; j < len; j++){
                if(str[i++] != str[startIndex++]){
                         true = 0;
                         break;
                }
          }
          if(!true)
                   break;
          startIndex = 0;
    }
    if(true){
             printf("True");
             getch();
             return;         
    }
}
 printf("Not true");
    getch();
}

- Kishore October 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<stdio.h>
#include<conio.h>
int length(char str[]){
    int i;
    for(i = 0; str[i] != '\0'; i++);
    return i--;
}

int main(){
    char str[] = "abaaabaaabaa";
    int len;
    for(len = 1; len < length(str); len++){
    int startIndex = 0;
    int true = 1;
    int i,j;
    for(i = 0; str[i] != '\0';){
          printf("%d\n",i);
          for(j = 0; j < len; j++){
                if(str[i++] != str[startIndex++]){
                         true = 0;
                         break;
                }
          }
          if(!true)
                   break;
          startIndex = 0;
    }
    if(true){
             printf("True");
             getch();
             return;         
    }
}
 printf("Not true");
    getch();
}

- Kishore October 01, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<stdio.h>
#include<conio.h>
int length(char str[]){
    int i;
    for(i = 0; str[i] != '\0'; i++);
    return i--;
}

int main(){
    char str[] = "abaaabaaabaa";
    int len;
    for(len = 1; len < length(str); len++){
    int startIndex = 0;
    int true = 1;
    int i,j;
    for(i = 0; str[i] != '\0';){
          printf("%d\n",i);
          for(j = 0; j < len; j++){
                if(str[i++] != str[startIndex++]){
                         true = 0;
                         break;
                }
          }
          if(!true)
                   break;
          startIndex = 0;
    }
    if(true){
             printf("True");
             getch();
             return;         
    }
}
 printf("Not true");
    getch();
}

- Kishore October 01, 2014 | 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