Answers for "hackerrank diagonal difference"

0

hackerrank diagonal difference

var right int32
	var left int32

	for i := 0; i < len(arr); i++ {
		for j := 0; j < len(arr); j++ {
			if i == j {
				right += int32(arr[i][j])
			}

			if i+j == len(arr)-1 {
				left += int32(arr[i][j])
			}
		}
	}

	sum := right - left

	if sum < 0 {
		sum -= sum
	}

	return sum
   }
   
# step one
0 == 0 = 11 // true
1 == 0 = 2
2 == 0 = 4
0 == 1 = 4
1 == 1 = 5 // true
2 == 1 = 6
0 == 2 = 10
1 == 2 = 8
2 == 2 = -12 // true

= 11 + 5 - 12 = 4

# step two
0 == 2 = 11
1 == 2 = 2
2 == 2 = 4 // true
1 == 2 = 4
2 == 2 = 5 // true
3 == 2 = 6
2 == 2 = 10 // t rue
3 == 2 = 8
4 == 2 = 12

= 4 + 5 + 10 = 19
Posted by: Guest on October-28-2021

Code answers related to "hackerrank diagonal difference"

Browse Popular Code Answers by Language