Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created November 9, 2015 05:48
Show Gist options
  • Save sholfen/f983060d32f3f1fb4fcc to your computer and use it in GitHub Desktop.
Save sholfen/f983060d32f3f1fb4fcc to your computer and use it in GitHub Desktop.
for Codility FrogRiverOne
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FrogRiverOne
{
class Program
{
static void Main(string[] args)
{
int[] input = { 1, 3, 1, 4, 2, 3, 5, 4 };
Solution sol = new Solution();
int result = sol.solution(5, input);
Console.WriteLine("result is:" + result.ToString());
}
}
class Solution
{
public int solution(int x, int[] input)
{
bool[] positionCheckArray = new bool[x + 1];
int count = 0;
int result = -1;
for (int i = 0; i < input.Length; i++)
{
if (!positionCheckArray[input[i]])
{
count += 1;
positionCheckArray[input[i]] = true;
}
if (count == x)
{
result = i;
break;
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment