Longest strictly increasing sequence in 2D array

I'm having issues correcting my code to check for the longest strictly increasing sequence in a 2D array.

This is the sample grid:
-1 3.14 42
0.2 2.7172
0.5 1.4142 -0.5 0 -0.5 0
0 0.577
10000 9999.99 -3 10
1 1 1 1 1

I have 4 functions that I pass into main and right now I'm trying to fix the first one since none of them worked correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int lookRight(double** grid, int num_rows, int* col_count, int i, int j) {
   int length_size = 0;
   int max_row_right = 0;
 
   for (int n = j; n < col_count[i]; n++){
    if (grid[i][n+1] > grid[i][n] && grid[i][n+1] != grid[i][n]){
      length_size++;
      cout << grid[i][n] << " " << grid[i][n+1] << endl;
      max_row_right = length_size;
      cout << "max_row_right: " << max_row_right << endl;
    }   
   }
   max_row_right = length_size;
   cout << "Out of the entire grid, the max count in rows is: " << max_row_right << endl;
   return max_row_right;
}


Right now it prints:

-1 3.14
max_row_right: 1
3.14 42
max_row_right: 2
Out of the entire grid, the max count in rows is: 2
3.14 42
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
Out of the entire grid, the max count in rows is: 0
0.2 2.7172
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
Out of the entire grid, the max count in rows is: 0
0.5 1.4142
max_row_right: 1
-0.5 0
max_row_right: 2
-0.5 0
max_row_right: 3
Out of the entire grid, the max count in rows is: 3
-0.5 0
max_row_right: 1
-0.5 0
max_row_right: 2
Out of the entire grid, the max count in rows is: 2
-0.5 0
max_row_right: 1
-0.5 0
max_row_right: 2
Out of the entire grid, the max count in rows is: 2
-0.5 0
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
-0.5 0
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
Out of the entire grid, the max count in rows is: 0
0 0.577
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
Out of the entire grid, the max count in rows is: 0
-3 10
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
-3 10
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
-3 10
max_row_right: 1
Out of the entire grid, the max count in rows is: 1
Out of the entire grid, the max count in rows is: 0
Out of the entire grid, the max count in rows is: 0
Out of the entire grid, the max count in rows is: 0
Out of the entire grid, the max count in rows is: 0
Out of the entire grid, the max count in rows is: 0
Out of the entire grid, the max count in rows is: 0
Last edited on
What would correct output be?
Well we were given a "grid" of floating point numbers (double), and were to look for the longest strictly increasing sequence along a row or column, forward or backward (but no diagonals). Noting that the grid need not be regular (it can be jagged).

The output should ultimately just be the length of the longest increasing sequence in the input data. So I was trying to work on each of my functions (lookLeft, lookRight, lookUp, lookDown) separately and printing out the outputs.But clearly I can't even get the max value of the entire grid row stored correctly to pass in main >_>.
Assuming that length_size is intended to keep track of the current sequence, it should begin at length 1. Assuming none of your jagged arrays have a size of 0, the smallest sequence length is always 1. When you encounter a non-increasing pair of numbers, the value of length_size should be reset. Whenever the value length_size is greater than the value of the keeping the largest sequence found so far, an update of that variable should occur.

Why do you need the parameters i and j?
Last edited on
Oh ok I'm gonna take a whack at it again and I took out the i and j because I realized it wasn't necessary.
I figured everything out! Including all of the other functions!

Thanks :)
Last edited on
Topic archived. No new replies allowed.