Sort by

recency

|

264 Discussions

|

  • + 1 comment

    int strangeGrid(int r, int c) { // Base value for the row group (each pair of rows increases base by 10) int base = (r - 1) / 2 * 10;

    // Check if the row is odd or even
    if (r % 2 == 1) {
        // Odd row: Start at base, increment by 2 for each column
        return base + (c - 1) * 2;
    } else {
        // Even row: Start at base + 1, increment by 2 for each column
        return base + 1 + (c - 1) * 2;
    }
    

    }

  • + 0 comments

    cpp code:

    long long strangeGrid(long long r,long long c) { long long result = 0;

    if (r % 2 != 0) {
        result = (r - 1) * 5 + (c - 1) * 2;  
    } 
    else {
        result = (r - 2) * 5 + (c - 1) * 2 + 1;
    }
    
    return result;
    

    }

  • + 1 comment

    A solution template for Java is wrong. You should change the return type from int to long,

  • + 0 comments

    return r % 2 == 0 ? (10*(r/2 - 1) + 1) + (2*c - 2) : 10*((r+1)/2 - 1) + 2*(c-1)

    or

    return r % 2 == 0 ? 5*r - 11 + 2*c : 5*r - 7 + 2*c

  • + 0 comments

    for c++ must convertt the parsing of int to long long variable and also change stoi() to stoll() i got accepted after this