Skip to content

Instantly share code, notes, and snippets.

@hueitan
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save hueitan/3763cc29defecc97f6ba to your computer and use it in GitHub Desktop.

Select an option

Save hueitan/3763cc29defecc97f6ba to your computer and use it in GitHub Desktop.

Revisions

  1. Huei Tan revised this gist May 8, 2015. 1 changed file with 45 additions and 0 deletions.
    45 changes: 45 additions & 0 deletions taller.md
    Original file line number Diff line number Diff line change
    @@ -93,6 +93,51 @@ for (;i<N;) {

    }

    return o
    }
    ```

    -> 153 char
    ```js
    function Taller (N,M) {

    o = []
    i = 0


    while(i<N){

    j = i - 1
    p = -1
    k = 0
    t = [p,p]

    while (j!=i) {

    if (j<0)
    j = N


    if (j>N)
    j = -1


    if (M[j]>M[i]) {
    t[k++] = j + 1
    j = i
    p = 1
    }

    j += p

    k > 1 ? j=i: ''

    }

    o[i++] = t

    }

    return o
    }
    ```
  2. Huei Tan revised this gist May 8, 2015. 1 changed file with 44 additions and 0 deletions.
    44 changes: 44 additions & 0 deletions taller.md
    Original file line number Diff line number Diff line change
    @@ -51,4 +51,48 @@ for (i=0;i<N;i++) {

    return output;
    }
    ```

    156 char
    ```js
    function Taller (N,M) {

    o = []
    i = 0


    for (;i<N;) {

    j = i - 1
    p = -1
    k = 0
    t = [p,p]

    for (;j!=i;) {

    if (j<0)
    j = N


    if (j>N)
    j = -1


    if (M[j]>M[i]) {
    t[k++] = j + 1
    j = i
    p = 1
    if (k==2) break
    }

    j += p

    }

    o[i++] = t

    }

    return o
    }
    ```
  3. Huei Tan created this gist May 8, 2015.
    54 changes: 54 additions & 0 deletions taller.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    Original answer

    ```js
    function Taller (N,M) {

    var output = [];
    // check every element
    for (i=0;i<N;i++) {

    var temp = [];

    // check left
    for (j=i-1;;j--) {
    //
    if (j==i) {
    temp.push(-1);
    break;
    }
    // -1
    if (j==-1) {
    j = N;
    }
    // [0,N-1]
    else if (M[j]>M[i]) {
    temp.push(j+1);
    break;
    }

    }

    // check right
    for (j=i+1;;j++) {
    //
    if (j==i) {
    temp.push(-1);
    break;
    }
    // -1
    if (j==N) {
    j = -1;
    }
    // [0,N-1]
    else if (M[j]>M[i]) {
    temp.push(j+1);
    break;
    }
    }

    output.push(temp);
    }

    return output;
    }
    ```