avatar
Untitled

Guest 0.9K 17th Jul, 2020

int playList(std::vector<int> arr)
{
    int length = 1;
	int start = 0, end = 1;
	while (start < arr.size())
	{
		int set = 0;
		// Move to the nearest similar "end"
		while (true)
		{
			// Check "end" with everything between it and "start"
			bool success = true;
			for (int i = start; i < end; i++)
			{
				if (arr[end] == arr[i])
				{
					success = false;
					set = i;
					break;
				}
			}
			// When there's something similar to "end"
			if (!success)
			{
				int temp = end - start;
				if (temp > length) length = temp;
				break;
			}
			// Or "end" is different
			else
			{
				end++;
				if (end >= arr.size())
				{
					int temp = end - start;
					if (temp > length) length = temp;
					break;
				}
			}
		}
		// Check "start"
		if (set == 0) start++;
		else start = set + 1;
	}
	return length;
}
C++
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data