-2

Given an N array of strings of N length, return the minimum number of character changes required to create a chessboard pattern (a change means replacing characters).

for instances

["ab", "ba"] --> 0
["aba", "bac", "aba"] --> 1 

i am really lost, any help appreciated

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
Antonia Calvi
  • 127
  • 1
  • 3

1 Answers1

0

You can split up your problem into several smaller problems.

For instance:

  1. If there is at least one line, the number of lines have to be equal to the length of your first line, otherwise the structure is a 0x0 checkboard
  2. If there are at least two lines, the number of lines have to be equal to the length of your second line, otherwise the structure is a 1x1 checkboard
  3. All your even "lines" have to be equal
  4. All your odd "lines" have to be equal

(At this point you don't have to consider anymore the lines beyond line 2)

  1. In your first and second line, all the characters at even positions have to be equal
  2. In your first and second line, all the characters at odd positions have to be equal

(At this point you don't have to consider the characters beyond character 2)

  1. The first and second character of the first line have to be equal to the second and first characters of the second line
  2. The first and second characters of the first line have to be different
Fabian Pijcke
  • 2,920
  • 25
  • 29