Apple Interview Question


Team: QA
Country: United States
Interview Type: In-Person




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

using suffix array we can find the starting index of sub string.

- siva April 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This could be done by using KMP, but to be honest it won't be easy to write the code during interview if you are not well prepared.

- groomnestle December 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int getSubStringStartingPosition(char[] st1, char[] st2)
	{
		int pos=0;
		boolean flag=false;
		
		int k=0;
		for (int i=0; i<=st1.length-1; ++i)
		{
			if ((k <= st2.length-1) && (st1[i]==st2[k]))
			{
				
				if (!flag)
				{
					pos=i;
				}
					
				flag=true;
				k++;
			}
			else
			{
				System.out.println("not found.."+st1[i]);
				if (flag && k <=st2.length-1)
				{
					System.out.println("found an extra character in the middle..");
					pos=0;
				}
			}
		}
		return pos;
	}

- Implementation in Java: January 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int findSubString(const char *input, const char *substring)
{
	int start = 0;
	for (; *input != '\0'; input++ )
	{
		while (*input == *substring)
		{
			substring++;
			input++;
            
			if (*substring == '\0')
				return start;
			if (*input == '\0')
				break;
		}
		start++;
	}
	return -1;
}

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

bool FindSubString(char* mainstr, char* str)
{
char* start_ptr = mainstr;
char* itr_ptr = mainstr;
char* substr = str;
while(*start_ptr != '\0')
{
substr = str;
while(*substr != '\0' && (*itr_ptr++ == *substr++));

if(*substr == '\0')
return true;

start_ptr++;
itr_ptr = start_ptr;
}
return false;
}

- Anonymous October 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool FindSubString(char* mainstr, char* str)
{
	char* start_ptr = mainstr;
	char* itr_ptr = mainstr;
	char* substr = str;
	while(*start_ptr != '\0')
	{
		substr = str;
		while(*substr != '\0' && (*itr_ptr++ == *substr++));

		if(*substr == '\0')
			return true;
		
		start_ptr++;
		itr_ptr = start_ptr;
	}
	return false;
}

- Anonymous October 02, 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