FastPrepOrthogonal Neighbor Grid Total
Problems/Orthogonal Neighbor Grid Total

Orthogonal Neighbor Grid Total

IMC Trading logoIMC Trading● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad online assessment. The rule compares all neighbors at the same time, then asks for the updated total. It is about 90% the same as the reported question. The photographed report uses a fixed 3-by-3 grid. This version uses a rectangular grid of integers that you can reuse, with a limited input range.

You are given an integer grid. Each cell is updated simultaneously using only values from the original grid.

For every existing orthogonal neighbor, add 1 to the cell if that neighbor has a strictly greater value, or subtract 1 if that neighbor has a strictly smaller value. An equal-valued neighbor contributes no change. Only cells immediately above, below, left or right are neighbors.

Return the sum of all cell values after one simultaneous update.

For this exercise, assume the same rule applies to any nonempty rectangular integer grid; there is no wrapping at the edges and no contribution from outside the grid. Return the total as a signed 64-bit integer.

Complete updatedGridTotal(grid). The requested output is the total, so you do not need to return the updated grid.

Function

updatedGridTotal(grid: int[][]) → long

Examples

Example 1

grid = [[2,4,5],[1,7,8],[3,5,4]]return = 39
grid
012024511782354

This is the photographed initial grid. A simultaneous update gives [[2,5,5],[4,5,5],[3,4,6]]. Its total is 39; the total is independently derived from the printed rules.

Example 2

grid = [[5]]return = 5
grid
005

A single cell has no orthogonal neighbors, so its value and the total stay 5.

Example 3

grid = [[1,2,2]]return = 5
grid
0120122

The updated row is [2,1,2]. Equal neighboring values contribute no change, and the total remains 5.

Example 4

grid = [[-4,-4],[-1,2]]return = -7
grid
010-4-41-12

The updated grid is [[-3,-3],[-1,0]]. Negative numbers use the same strict comparisons; the total remains -7.

Constraints

  • For this exercise, assume 1 <= rows, columns <= 200.
  • For this exercise, assume -1,000,000 <= grid[r][c] <= 1,000,000.
  • The grid is rectangular and all entries are integers.
  • The absolute total is at most 40,000,000,000 and fits in a signed 64-bit integer.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Scaled Dot-Product AttentionMeshy · OA
  • Flip Rows and Columns, Count ZerosNutanix · OANutanix interview questions
  • Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Grouped-Query Attention with a KV CacheAmazon · ONSITE INTERVIEW
  • Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • Implement Circular PaddingApple · ONSITE INTERVIEWApple interview questions
  • Column and Row Parallel Linear LayersNVIDIA · PHONE SCREENNVIDIA interview questions
  • Robot Survival ProbabilityInMobi · ONSITE INTERVIEWInMobi interview questions
  • Survey Table: Group Given an AnswerSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public long updatedGridTotal(int[][] grid) {
        // Write your solution here.
    }
}
Checking account…