Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This is the solution that made me look into constant vs linear time complexity and consider that I should learn formulas. Very interesting and never something I would have checked out otherwise

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    a more simple question, can you give comments on how this solution works? Thanks~!

  • Custom User Avatar

    I'm not understanding how this works. How am I misunderstanding?

    using System.Linq;

    public class Kata
    {
    public static object FirstNonConsecutive(int[] arr)
    {
    //create a variable count and set it equal to the value of the first index in arr a.k.a arr[0]

        var count = arr.First();
    
        //loop through each item in the arr array
        
        foreach (var val in arr)
        {   
            //if the val in the arr doesn't equal the first val in arr, return the val
            //my understanding is that count is == arr[0]
            //so on the first iteration of the loop, the if statment condition isn't met
            //on the second iteration, they will likely not be equal.
            //but the fact that the two indicies aren't equal doesn't mean that they are also no consecutive. 
            
            /
            if (val != count)
            {
                return val;
            }
            count++;
        }
        return null;
    }
    

    }

    PS I know this answer is correct, I'm not challenging that. I just want help to understand how it works. Thanks if you see this!

  • Custom User Avatar

    I just started c# (and coding) recently and am trying to work on 8 kyu stuff. Glad I wasn't crazy here and thanks for the reply!

  • Custom User Avatar

    int[] numbers = {3,4,3,3,3};

    What if the second index holds the stray? Wouldn't this solution assume that if [0] & [1] are different, that [0] is the stray? With the above array for example. The first if statement compares index 0 and 1, they are different, so it assigns val to index [0].