Interview Question


Country: United States




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

#include<stdio.h>
#include<conio.h>
{
int a,b;
add(a+b);
getch();
}

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

HAHAHAHAHA.

You made me laugh. BUT. I am laughing at you, not with you.

- Anonymous April 01, 2014 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

bool all_found(int* arr, std::map<char, int>& charmap)
{
	for (std::map<char, int>::const_iterator it = charmap.begin(); it != charmap.end(); ++it)
	{
		char c = it->first;
		int v = it->second;
		if (arr[c - 'a'] < v)
			return false;
	}

	return true;
}

int min_length(std::string s, std::string pattern)
{
	std::map<char, int> charmap;

	for (int i = 0; i < pattern.length(); ++i)
	{
		char c = pattern[i];
		if (charmap.find(c) != charmap.end())
			charmap.insert(std::make_pair<char, int>(c, 1));
		else
			charmap[c]++;
	}

	int arr[26] = {0};
	int min_length = s.length() + 1;
	std::string min_string;

	int i = 0, p = 0;
	int l = s.length();
	while (p < l)
	{
		char c = s[p];
		if (charmap.find(c) != charmap.end())
		{
			arr[c - 'a']++;

			while (all_found(arr, charmap))
			{
				int length = p - i + 1;
				if (length < min_length)
				{
					min_length = length;
					min_string = s.substr(i, length);
				}
				arr[s[i] - 'a']--;
				++i;
			}
		}
		++p;
	}

	if (min_length < l)
	{
		std::cout << min_string << "\n";
	}
	return min_length;
}

int _tmain(int argc, _TCHAR* argv[])
{ 
	std::string s = "adobecodebanc";
	std::string p = "abc";
	std::cout << min_length(s, p);
	getchar();
}

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