Click here to Skip to main content
15,891,567 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: WPF? WTF... Pin
glennPattonWork37-Jan-17 8:49
professionalglennPattonWork37-Jan-17 8:49 
GeneralRe: WPF? WTF... Pin
Nelek7-Jan-17 12:18
protectorNelek7-Jan-17 12:18 
GeneralRe: WPF? WTF... Pin
glennPattonWork38-Jan-17 0:38
professionalglennPattonWork38-Jan-17 0:38 
GeneralRe: WPF? WTF... Pin
GuyThiebaut8-Jan-17 5:17
professionalGuyThiebaut8-Jan-17 5:17 
GeneralRe: WPF? WTF... Pin
glennPattonWork38-Jan-17 7:02
professionalglennPattonWork38-Jan-17 7:02 
GeneralHackerRank Pin
Marc Clifton7-Jan-17 5:57
mvaMarc Clifton7-Jan-17 5:57 
GeneralRe: HackerRank Pin
Richard Andrew x647-Jan-17 7:05
professionalRichard Andrew x647-Jan-17 7:05 
GeneralRe: HackerRank Pin
Marc Clifton7-Jan-17 8:00
mvaMarc Clifton7-Jan-17 8:00 
I don't know, about 10 minutes. And yes, I included the comments in my "solution:"
static int maxLength(int[] a, int k)
{
    // The example, subarrays of [1,2,3] is wrong!!!
    // It is missing subarray of 3!!!
    // As usual, these tests are wrong!!!

    // Anyways, this is a fairly inefficient algorithm as it gets all the subarrays first,
    // and the max length, if == a.Length, could stop the search early, and could test if sum > k
    // as the subarrays are parsed, and ignore subarrays whose length is less than the working max.
    List<int[]> subArrays = GetSubArrays(a);
    int max = 0;

    for (int n = 0; n < subArrays.Count; n++)
    {
        if (subArrays[n].Sum() <= k)
        {
            if (subArrays[n].Length > max)
            {
                max = subArrays[n].Length;
            }
        }
    }

    return max;
}

static List<int[]> GetSubArrays(int[] a)
{
    int l = 0;      // Start with length of 1 (0 based indexing!)
    List<int[]> subarrays = new List<int[]>();

    // Iterate, starting with a subarray of length 1.
    while (l < a.Length)
    {
        int idx = 0;

        // Get the subarray components for the given length l
        while (idx + l < a.Length)
        {
            int[] sub = new int[l+1];

            for (int i = 0; i <= l; i++)
            {
                sub[i] = a[idx + i];
            }

            ++idx;

            subarrays.Add(sub);
        }

        ++l;        // next we get subarrays of length 2, then length 3, etc.
    }

    return subarrays;
}

Marc
V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802

GeneralRe: HackerRank Pin
virang_217-Jan-17 13:33
virang_217-Jan-17 13:33 
JokeHuman Evolution Pin
Cornelius Henning7-Jan-17 2:57
professionalCornelius Henning7-Jan-17 2:57 
GeneralVilmos's New Toy Pin
Nagy Vilmos7-Jan-17 0:45
professionalNagy Vilmos7-Jan-17 0:45 
GeneralRe: Vilmos's New Toy Pin
OriginalGriff7-Jan-17 1:19
mveOriginalGriff7-Jan-17 1:19 
GeneralRe: Vilmos's New Toy Pin
glennPattonWork37-Jan-17 1:20
professionalglennPattonWork37-Jan-17 1:20 
GeneralRe: Vilmos's New Toy Pin
OriginalGriff7-Jan-17 1:40
mveOriginalGriff7-Jan-17 1:40 
GeneralRe: Vilmos's New Toy Pin
glennPattonWork37-Jan-17 1:58
professionalglennPattonWork37-Jan-17 1:58 
GeneralRe: Vilmos's New Toy Pin
OriginalGriff7-Jan-17 2:42
mveOriginalGriff7-Jan-17 2:42 
GeneralRe: Vilmos's New Toy Pin
glennPattonWork37-Jan-17 2:48
professionalglennPattonWork37-Jan-17 2:48 
GeneralRe: Vilmos's New Toy Pin
Nagy Vilmos7-Jan-17 10:02
professionalNagy Vilmos7-Jan-17 10:02 
GeneralHerself's new toy Pin
OriginalGriff6-Jan-17 22:15
mveOriginalGriff6-Jan-17 22:15 
GeneralRe: Herself's new toy Pin
Richard MacCutchan6-Jan-17 23:29
mveRichard MacCutchan6-Jan-17 23:29 
GeneralRe: Herself's new toy Pin
Nathan Minier7-Jan-17 0:17
professionalNathan Minier7-Jan-17 0:17 
GeneralRe: Herself's new toy Pin
Mike Hankey7-Jan-17 1:44
mveMike Hankey7-Jan-17 1:44 
GeneralRe: Herself's new toy Pin
Ravi Bhavnani7-Jan-17 2:17
professionalRavi Bhavnani7-Jan-17 2:17 
GeneralRe: Herself's new toy Pin
lopatir7-Jan-17 2:51
lopatir7-Jan-17 2:51 
GeneralRe: Herself's new toy Pin
charlieg7-Jan-17 4:44
charlieg7-Jan-17 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.